iPXE
sanboot.h
Go to the documentation of this file.
1 #ifndef _IPXE_SANBOOT_H
2 #define _IPXE_SANBOOT_H
3 
4 /** @file
5  *
6  * iPXE sanboot API
7  *
8  * The sanboot API provides methods for hooking, unhooking,
9  * describing, and booting from SAN devices.
10  */
11 
12 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
13 FILE_SECBOOT ( PERMITTED );
14 
15 #include <ipxe/api.h>
16 #include <ipxe/refcnt.h>
17 #include <ipxe/list.h>
18 #include <ipxe/uri.h>
19 #include <ipxe/retry.h>
20 #include <ipxe/process.h>
21 #include <ipxe/blockdev.h>
22 #include <ipxe/acpi.h>
23 #include <ipxe/uuid.h>
24 #include <config/sanboot.h>
25 
26 /**
27  * Default SAN drive number
28  *
29  * The drive number is an externally defined concept only in a BIOS
30  * environment, where it represents the INT13 drive number (0x80 for
31  * the first hard disk). We retain it in other environments to allow
32  * for a simple way for iPXE commands to refer to SAN drives.
33  */
34 #define SAN_DEFAULT_DRIVE 0x80
35 
36 /** A SAN path */
37 struct san_path {
38  /** Containing SAN device */
39  struct san_device *sandev;
40  /** Path index */
41  unsigned int index;
42  /** SAN device URI */
43  struct uri *uri;
44  /** List of open/closed paths */
45  struct list_head list;
46 
47  /** Underlying block device interface */
48  struct interface block;
49  /** Process */
50  struct process process;
51  /** Path status */
52  int path_rc;
53 
54  /** ACPI descriptor (if applicable) */
56 };
57 
58 /** A SAN device */
59 struct san_device {
60  /** Reference count */
61  struct refcnt refcnt;
62  /** List of SAN devices */
63  struct list_head list;
64 
65  /** Drive number */
66  unsigned int drive;
67  /** Flags */
68  unsigned int flags;
69 
70  /** Command interface */
72  /** Command timeout timer */
74  /** Command status */
76 
77  /** Raw block device capacity */
79  /** Block size shift
80  *
81  * To allow for emulation of CD-ROM access, this represents
82  * the left-shift required to translate from exposed logical
83  * I/O blocks to underlying blocks.
84  */
85  unsigned int blksize_shift;
86  /** Drive is a CD-ROM */
87  int is_cdrom;
88 
89  /** Driver private data */
90  void *priv;
91 
92  /** Number of paths */
93  unsigned int paths;
94  /** Current active path */
95  struct san_path *active;
96  /** List of opened SAN paths */
97  struct list_head opened;
98  /** List of closed SAN paths */
99  struct list_head closed;
100  /** SAN paths */
101  struct san_path path[0];
102 };
103 
104 /** SAN device flags */
106  /** Device should not be included in description tables */
107  SAN_NO_DESCRIBE = 0x0001,
108 };
109 
110 /** SAN boot configuration parameters */
112  /** Boot filename (or NULL to use default) */
113  const char *filename;
114  /** Required extra filename (or NULL to ignore) */
115  const char *extra;
116  /** Filesystem label (or NULL to ignore volume label) */
117  const char *label;
118  /** UUID (or NULL to ignore UUID) */
119  union uuid *uuid;
120 };
121 
122 /**
123  * Calculate static inline sanboot API function name
124  *
125  * @v _prefix Subsystem prefix
126  * @v _api_func API function
127  * @ret _subsys_func Subsystem API function
128  */
129 #define SANBOOT_INLINE( _subsys, _api_func ) \
130  SINGLE_API_INLINE ( SANBOOT_PREFIX_ ## _subsys, _api_func )
131 
132 /**
133  * Provide a sanboot API implementation
134  *
135  * @v _prefix Subsystem prefix
136  * @v _api_func API function
137  * @v _func Implementing function
138  */
139 #define PROVIDE_SANBOOT( _subsys, _api_func, _func ) \
140  PROVIDE_SINGLE_API ( SANBOOT_PREFIX_ ## _subsys, _api_func, _func )
141 
142 /**
143  * Provide a static inline sanboot API implementation
144  *
145  * @v _prefix Subsystem prefix
146  * @v _api_func API function
147  */
148 #define PROVIDE_SANBOOT_INLINE( _subsys, _api_func ) \
149  PROVIDE_SINGLE_API_INLINE ( SANBOOT_PREFIX_ ## _subsys, _api_func )
150 
151 /* Include all architecture-independent sanboot API headers */
152 #include <ipxe/null_sanboot.h>
153 #include <ipxe/dummy_sanboot.h>
154 #include <ipxe/efi/efi_block.h>
155 
156 /* Include all architecture-dependent sanboot API headers */
157 #include <bits/sanboot.h>
158 
159 /**
160  * Hook SAN device
161  *
162  * @v drive Drive number
163  * @v uris List of URIs
164  * @v count Number of URIs
165  * @v flags Flags
166  * @ret drive Drive number, or negative error
167  */
168 int san_hook ( unsigned int drive, struct uri **uris, unsigned int count,
169  unsigned int flags );
170 
171 /**
172  * Unhook SAN device
173  *
174  * @v drive Drive number
175  */
176 void san_unhook ( unsigned int drive );
177 
178 /**
179  * Attempt to boot from a SAN device
180  *
181  * @v drive Drive number
182  * @v config Boot configuration parameters
183  * @ret rc Return status code
184  */
185 int san_boot ( unsigned int drive, struct san_boot_config *config );
186 
187 /**
188  * Describe SAN devices for SAN-booted operating system
189  *
190  * @ret rc Return status code
191  */
192 int san_describe ( void );
193 
194 extern struct list_head san_devices;
195 
196 /** Iterate over all SAN devices */
197 #define for_each_sandev( sandev ) \
198  list_for_each_entry ( (sandev), &san_devices, list )
199 
200 /** There exist some SAN devices
201  *
202  * @ret existence Existence of SAN devices
203  */
204 static inline int have_sandevs ( void ) {
205  return ( ! list_empty ( &san_devices ) );
206 }
207 
208 /**
209  * Get reference to SAN device
210  *
211  * @v sandev SAN device
212  * @ret sandev SAN device
213  */
214 static inline __attribute__ (( always_inline )) struct san_device *
215 sandev_get ( struct san_device *sandev ) {
216  ref_get ( &sandev->refcnt );
217  return sandev;
218 }
219 
220 /**
221  * Drop reference to SAN device
222  *
223  * @v sandev SAN device
224  */
225 static inline __attribute__ (( always_inline )) void
226 sandev_put ( struct san_device *sandev ) {
227  ref_put ( &sandev->refcnt );
228 }
229 
230 /**
231  * Calculate SAN device block size
232  *
233  * @v sandev SAN device
234  * @ret blksize Sector size
235  */
236 static inline size_t sandev_blksize ( struct san_device *sandev ) {
237  return ( sandev->capacity.blksize << sandev->blksize_shift );
238 }
239 
240 /**
241  * Calculate SAN device capacity
242  *
243  * @v sandev SAN device
244  * @ret blocks Number of blocks
245  */
246 static inline uint64_t sandev_capacity ( struct san_device *sandev ) {
247  return ( sandev->capacity.blocks >> sandev->blksize_shift );
248 }
249 
250 /**
251  * Check if SAN device needs to be reopened
252  *
253  * @v sandev SAN device
254  * @ret needs_reopen SAN device needs to be reopened
255  */
256 static inline int sandev_needs_reopen ( struct san_device *sandev ) {
257  return ( sandev->active == NULL );
258 }
259 
260 extern struct san_device * sandev_find ( unsigned int drive );
261 extern struct san_device * sandev_next ( unsigned int drive );
262 extern int sandev_reopen ( struct san_device *sandev );
263 extern int sandev_reset ( struct san_device *sandev );
264 extern int sandev_read ( struct san_device *sandev, uint64_t lba,
265  unsigned int count, void *buffer );
266 extern int sandev_write ( struct san_device *sandev, uint64_t lba,
267  unsigned int count, void *buffer );
268 extern struct san_device * alloc_sandev ( struct uri **uris, unsigned int count,
269  size_t priv_size );
270 extern int register_sandev ( struct san_device *sandev, unsigned int drive,
271  unsigned int flags );
272 extern void unregister_sandev ( struct san_device *sandev );
273 extern unsigned int san_default_drive ( void );
274 
275 #endif /* _IPXE_SANBOOT_H */
A process.
Definition: process.h:18
static struct san_device * sandev_get(struct san_device *sandev)
Get reference to SAN device.
Definition: sanboot.h:215
#define __attribute__(x)
Definition: compiler.h:10
iPXE internal APIs
int san_describe(void)
Describe SAN devices for SAN-booted operating system.
int san_hook(unsigned int drive, struct uri **uris, unsigned int count, unsigned int flags)
Hook SAN device.
struct san_path path[0]
SAN paths.
Definition: sanboot.h:101
struct list_head list
List of open/closed paths.
Definition: sanboot.h:45
A universally unique ID.
Definition: uuid.h:16
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
A command-line command.
Definition: command.h:10
int command_rc
Command status.
Definition: sanboot.h:75
int sandev_read(struct san_device *sandev, uint64_t lba, unsigned int count, void *buffer)
Read from SAN device.
Definition: sanboot.c:647
Retry timers.
int san_boot(unsigned int drive, struct san_boot_config *config)
Attempt to boot from a SAN device.
struct interface block
Underlying block device interface.
Definition: sanboot.h:48
A retry timer.
Definition: retry.h:22
unsigned long long uint64_t
Definition: stdint.h:13
Universally unique IDs.
struct list_head san_devices
static void sandev_put(struct san_device *sandev)
Drop reference to SAN device.
Definition: sanboot.h:226
static int sandev_needs_reopen(struct san_device *sandev)
Check if SAN device needs to be reopened.
Definition: sanboot.h:256
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
int register_sandev(struct san_device *sandev, unsigned int drive, unsigned int flags)
Register SAN device.
Definition: sanboot.c:880
Standard do-nothing sanboot interface.
uint8_t drive
Drive number.
Definition: int13.h:16
struct list_head opened
List of opened SAN paths.
Definition: sanboot.h:97
Uniform Resource Identifiers.
void unregister_sandev(struct san_device *sandev)
Unregister SAN device.
Definition: sanboot.c:942
unsigned int san_default_drive(void)
Get default SAN drive number.
Definition: sanboot.c:973
unsigned int index
Path index.
Definition: sanboot.h:41
A doubly-linked list entry (or list head)
Definition: list.h:19
A reference counter.
Definition: refcnt.h:27
A timer.
Definition: timer.h:29
Dummy SAN device.
static int have_sandevs(void)
There exist some SAN devices.
Definition: sanboot.h:204
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
An object interface.
Definition: interface.h:125
A SAN path.
Definition: sanboot.h:37
unsigned int drive
Drive number.
Definition: sanboot.h:66
SAN boot configuration parameters.
Definition: sanboot.h:111
union uuid * uuid
UUID (or NULL to ignore UUID)
Definition: sanboot.h:119
static uint64_t sandev_capacity(struct san_device *sandev)
Calculate SAN device capacity.
Definition: sanboot.h:246
static unsigned int count
Number of entries.
Definition: dwmac.h:225
const char * filename
Boot filename (or NULL to use default)
Definition: sanboot.h:113
unsigned int blksize_shift
Block size shift.
Definition: sanboot.h:85
uint64_t blocks
Total number of blocks.
Definition: blockdev.h:20
sanboot API configuration
Linked lists.
uint8_t flags
Flags.
Definition: ena.h:18
Block devices.
struct list_head closed
List of closed SAN paths.
Definition: sanboot.h:99
ACPI data structures.
int is_cdrom
Drive is a CD-ROM.
Definition: sanboot.h:87
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:93
struct list_head list
List of SAN devices.
Definition: sanboot.h:63
int path_rc
Path status.
Definition: sanboot.h:52
A SAN device.
Definition: sanboot.h:59
const char * label
Filesystem label (or NULL to ignore volume label)
Definition: sanboot.h:117
uint64_t lba
Starting block number.
Definition: int13.h:22
Processes.
Device should not be included in description tables.
Definition: sanboot.h:107
unsigned int paths
Number of paths.
Definition: sanboot.h:93
struct uri * uri
SAN device URI.
Definition: sanboot.h:43
struct block_device_capacity capacity
Raw block device capacity.
Definition: sanboot.h:78
void san_unhook(unsigned int drive)
Unhook SAN device.
An ACPI descriptor (used to construct ACPI tables)
Definition: acpi.h:295
struct san_device * sandev_next(unsigned int drive)
Find next SAN device by drive number.
Definition: sanboot.c:108
Block device capacity.
Definition: blockdev.h:18
struct refcnt refcnt
Reference count.
Definition: sanboot.h:61
int sandev_reset(struct san_device *sandev)
Reset SAN device.
Definition: sanboot.c:576
const char * extra
Required extra filename (or NULL to ignore)
Definition: sanboot.h:115
void * priv
Driver private data.
Definition: sanboot.h:90
Reference counting.
static size_t sandev_blksize(struct san_device *sandev)
Calculate SAN device block size.
Definition: sanboot.h:236
int sandev_reopen(struct san_device *sandev)
(Re)open SAN device
Definition: sanboot.c:373
A Uniform Resource Identifier.
Definition: uri.h:65
struct san_path * active
Current active path.
Definition: sanboot.h:95
unsigned int flags
Flags.
Definition: sanboot.h:68
int sandev_write(struct san_device *sandev, uint64_t lba, unsigned int count, void *buffer)
Write to SAN device.
Definition: sanboot.c:668
struct acpi_descriptor * desc
ACPI descriptor (if applicable)
Definition: sanboot.h:55
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
struct san_device * sandev
Containing SAN device.
Definition: sanboot.h:39
FILE_SECBOOT(PERMITTED)
struct san_device * sandev_find(unsigned int drive)
Find SAN device by drive number.
Definition: sanboot.c:92
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:107
size_t blksize
Block size.
Definition: blockdev.h:22
san_device_flags
SAN device flags.
Definition: sanboot.h:105
struct san_device * alloc_sandev(struct uri **uris, unsigned int count, size_t priv_size)
Allocate SAN device.
Definition: sanboot.c:837