1 #ifndef _IPXE_SANBOOT_H
2 #define _IPXE_SANBOOT_H
8 * The sanboot API provides methods for hooking, unhooking,
9 * describing, and booting from SAN devices.
12 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL
);
15 #include <ipxe/refcnt.h>
16 #include <ipxe/list.h>
18 #include <ipxe/retry.h>
19 #include <ipxe/process.h>
20 #include <ipxe/blockdev.h>
21 #include <ipxe/acpi.h>
22 #include <config/sanboot.h>
26 /** Containing SAN device */
27 struct san_device
*sandev
;
32 /** List of open/closed paths */
33 struct list_head list
;
35 /** Underlying block device interface */
36 struct interface block
;
38 struct process process
;
42 /** ACPI descriptor (if applicable) */
43 struct acpi_descriptor
*desc
;
48 /** Reference count */
50 /** List of SAN devices */
51 struct list_head list
;
58 /** Command interface */
59 struct interface command
;
60 /** Command timeout timer */
61 struct retry_timer timer
;
65 /** Raw block device capacity */
66 struct block_device_capacity capacity
;
69 * To allow for emulation of CD-ROM access, this represents
70 * the left-shift required to translate from exposed logical
71 * I/O blocks to underlying blocks.
73 unsigned int blksize_shift
;
74 /** Drive is a CD-ROM */
77 /** Driver private data */
80 /** Number of paths */
82 /** Current active path */
83 struct san_path
*active
;
84 /** List of opened SAN paths */
85 struct list_head opened
;
86 /** List of closed SAN paths */
87 struct list_head closed
;
89 struct san_path path
[0];
94 uint8_t boot_catalog_sector
[2048];
97 /** SAN device flags */
98 enum san_device_flags
{
99 /** Device should not be included in description tables */
100 SAN_NO_DESCRIBE
= 0x0001,
104 * Calculate static inline sanboot API function name
106 * @v _prefix Subsystem prefix
107 * @v _api_func API function
108 * @ret _subsys_func Subsystem API function
110 #define SANBOOT_INLINE( _subsys, _api_func ) \
111 SINGLE_API_INLINE ( SANBOOT_PREFIX_ ## _subsys, _api_func )
114 * Provide a sanboot API implementation
116 * @v _prefix Subsystem prefix
117 * @v _api_func API function
118 * @v _func Implementing function
120 #define PROVIDE_SANBOOT( _subsys, _api_func, _func ) \
121 PROVIDE_SINGLE_API ( SANBOOT_PREFIX_ ## _subsys, _api_func, _func )
124 * Provide a static inline sanboot API implementation
126 * @v _prefix Subsystem prefix
127 * @v _api_func API function
129 #define PROVIDE_SANBOOT_INLINE( _subsys, _api_func ) \
130 PROVIDE_SINGLE_API_INLINE ( SANBOOT_PREFIX_ ## _subsys, _api_func )
132 /* Include all architecture-independent sanboot API headers */
133 #include <ipxe/null_sanboot.h>
134 #include <ipxe/dummy_sanboot.h>
135 #include <ipxe/efi/efi_block.h>
137 /* Include all architecture-dependent sanboot API headers */
138 #include <bits/sanboot.h>
143 * @v drive Drive number
144 * @v uris List of URIs
145 * @v count Number of URIs
147 * @ret drive Drive number, or negative error
149 int san_hook ( unsigned int drive
, struct uri
**uris
, unsigned int count
,
150 unsigned int flags
);
155 * @v drive Drive number
157 void san_unhook ( unsigned int drive
);
160 * Attempt to boot from a SAN device
162 * @v drive Drive number
163 * @v filename Filename (or NULL to use default)
164 * @ret rc Return status code
166 int san_boot ( unsigned int drive
, const char *filename
);
169 * Describe SAN devices for SAN-booted operating system
171 * @ret rc Return status code
173 int san_describe ( void );
175 extern struct list_head san_devices
;
177 /** Iterate over all SAN devices */
178 #define for_each_sandev( sandev ) \
179 list_for_each_entry ( (sandev), &san_devices, list )
181 /** There exist some SAN devices
183 * @ret existence Existence of SAN devices
185 static inline int have_sandevs ( void ) {
186 return ( ! list_empty ( &san_devices
) );
190 * Get reference to SAN device
192 * @v sandev SAN device
193 * @ret sandev SAN device
195 static inline __attribute__ (( always_inline
)) struct san_device
*
196 sandev_get ( struct san_device
*sandev
) {
197 ref_get ( &sandev
->refcnt
);
202 * Drop reference to SAN device
204 * @v sandev SAN device
206 static inline __attribute__ (( always_inline
)) void
207 sandev_put ( struct san_device
*sandev
) {
208 ref_put ( &sandev
->refcnt
);
212 * Calculate SAN device block size
214 * @v sandev SAN device
215 * @ret blksize Sector size
217 static inline size_t sandev_blksize ( struct san_device
*sandev
) {
218 return ( sandev
->capacity
.blksize
<< sandev
->blksize_shift
);
222 * Calculate SAN device capacity
224 * @v sandev SAN device
225 * @ret blocks Number of blocks
227 static inline uint64_t sandev_capacity ( struct san_device
*sandev
) {
228 return ( sandev
->capacity
.blocks
>> sandev
->blksize_shift
);
232 * Check if SAN device needs to be reopened
234 * @v sandev SAN device
235 * @ret needs_reopen SAN device needs to be reopened
237 static inline int sandev_needs_reopen ( struct san_device
*sandev
) {
238 return ( sandev
->active
== NULL
);
241 extern struct san_device
* sandev_find ( unsigned int drive
);
242 extern int sandev_reopen ( struct san_device
*sandev
);
243 extern int sandev_reset ( struct san_device
*sandev
);
244 extern int sandev_read ( struct san_device
*sandev
, uint64_t lba
,
245 unsigned int count
, userptr_t buffer
);
246 extern int sandev_write ( struct san_device
*sandev
, uint64_t lba
,
247 unsigned int count
, userptr_t buffer
);
248 extern struct san_device
* alloc_sandev ( struct uri
**uris
, unsigned int count
,
250 extern int register_sandev ( struct san_device
*sandev
, unsigned int drive
,
251 unsigned int flags
);
252 extern void unregister_sandev ( struct san_device
*sandev
);
253 extern unsigned int san_default_drive ( void );
255 #endif /* _IPXE_SANBOOT_H */