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
;
92 uint8_t boot_catalog_sector
[2048];
95 struct san_path path
[0];
98 /** SAN device flags */
99 enum san_device_flags
{
100 /** Device should not be included in description tables */
101 SAN_NO_DESCRIBE
= 0x0001,
105 * Calculate static inline sanboot API function name
107 * @v _prefix Subsystem prefix
108 * @v _api_func API function
109 * @ret _subsys_func Subsystem API function
111 #define SANBOOT_INLINE( _subsys, _api_func ) \
112 SINGLE_API_INLINE ( SANBOOT_PREFIX_ ## _subsys, _api_func )
115 * Provide a sanboot API implementation
117 * @v _prefix Subsystem prefix
118 * @v _api_func API function
119 * @v _func Implementing function
121 #define PROVIDE_SANBOOT( _subsys, _api_func, _func ) \
122 PROVIDE_SINGLE_API ( SANBOOT_PREFIX_ ## _subsys, _api_func, _func )
125 * Provide a static inline sanboot API implementation
127 * @v _prefix Subsystem prefix
128 * @v _api_func API function
130 #define PROVIDE_SANBOOT_INLINE( _subsys, _api_func ) \
131 PROVIDE_SINGLE_API_INLINE ( SANBOOT_PREFIX_ ## _subsys, _api_func )
133 /* Include all architecture-independent sanboot API headers */
134 #include <ipxe/null_sanboot.h>
135 #include <ipxe/dummy_sanboot.h>
136 #include <ipxe/efi/efi_block.h>
138 /* Include all architecture-dependent sanboot API headers */
139 #include <bits/sanboot.h>
144 * @v drive Drive number
145 * @v uris List of URIs
146 * @v count Number of URIs
148 * @ret drive Drive number, or negative error
150 int san_hook ( unsigned int drive
, struct uri
**uris
, unsigned int count
,
151 unsigned int flags
);
156 * @v drive Drive number
158 void san_unhook ( unsigned int drive
);
161 * Attempt to boot from a SAN device
163 * @v drive Drive number
164 * @v filename Filename (or NULL to use default)
165 * @ret rc Return status code
167 int san_boot ( unsigned int drive
, const char *filename
);
170 * Describe SAN devices for SAN-booted operating system
172 * @ret rc Return status code
174 int san_describe ( void );
176 extern struct list_head san_devices
;
178 /** Iterate over all SAN devices */
179 #define for_each_sandev( sandev ) \
180 list_for_each_entry ( (sandev), &san_devices, list )
182 /** There exist some SAN devices
184 * @ret existence Existence of SAN devices
186 static inline int have_sandevs ( void ) {
187 return ( ! list_empty ( &san_devices
) );
191 * Get reference to SAN device
193 * @v sandev SAN device
194 * @ret sandev SAN device
196 static inline __attribute__ (( always_inline
)) struct san_device
*
197 sandev_get ( struct san_device
*sandev
) {
198 ref_get ( &sandev
->refcnt
);
203 * Drop reference to SAN device
205 * @v sandev SAN device
207 static inline __attribute__ (( always_inline
)) void
208 sandev_put ( struct san_device
*sandev
) {
209 ref_put ( &sandev
->refcnt
);
213 * Calculate SAN device block size
215 * @v sandev SAN device
216 * @ret blksize Sector size
218 static inline size_t sandev_blksize ( struct san_device
*sandev
) {
219 return ( sandev
->capacity
.blksize
<< sandev
->blksize_shift
);
223 * Calculate SAN device capacity
225 * @v sandev SAN device
226 * @ret blocks Number of blocks
228 static inline uint64_t sandev_capacity ( struct san_device
*sandev
) {
229 return ( sandev
->capacity
.blocks
>> sandev
->blksize_shift
);
233 * Check if SAN device needs to be reopened
235 * @v sandev SAN device
236 * @ret needs_reopen SAN device needs to be reopened
238 static inline int sandev_needs_reopen ( struct san_device
*sandev
) {
239 return ( sandev
->active
== NULL
);
242 extern struct san_device
* sandev_find ( unsigned int drive
);
243 extern int sandev_reopen ( struct san_device
*sandev
);
244 extern int sandev_reset ( struct san_device
*sandev
);
245 extern int sandev_read ( struct san_device
*sandev
, uint64_t lba
,
246 unsigned int count
, userptr_t buffer
);
247 extern int sandev_write ( struct san_device
*sandev
, uint64_t lba
,
248 unsigned int count
, userptr_t buffer
);
249 extern struct san_device
* alloc_sandev ( struct uri
**uris
, unsigned int count
,
251 extern int register_sandev ( struct san_device
*sandev
, unsigned int drive
,
252 unsigned int flags
);
253 extern void unregister_sandev ( struct san_device
*sandev
);
254 extern unsigned int san_default_drive ( void );
256 #endif /* _IPXE_SANBOOT_H */