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
12FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
13FILE_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 */
37struct san_path {
38 /** Containing SAN device */
40 /** Path index */
41 unsigned int index;
42 /** SAN device URI */
43 struct uri *uri;
44 /** List of open/closed paths */
46
47 /** Underlying block device interface */
49 /** Process */
51 /** Path status */
53
54 /** ACPI descriptor (if applicable) */
56};
57
58/** A SAN device */
59struct san_device {
60 /** Reference count */
61 struct refcnt refcnt;
62 /** List of SAN devices */
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 */
88
89 /** Driver private data */
90 void *priv;
91
92 /** Number of paths */
93 unsigned int paths;
94 /** Current active path */
96 /** List of opened SAN paths */
98 /** List of closed SAN paths */
100 /** SAN paths */
101 struct san_path path[0];
102};
103
104/** SAN device flags */
106 /** Device should not be included in description tables */
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 */
168int 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 */
176void 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 */
185int 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 */
192int san_describe ( void );
193
194extern 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 */
204static 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 */
214static inline __attribute__ (( always_inline )) struct san_device *
215sandev_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 */
225static inline __attribute__ (( always_inline )) void
226sandev_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 */
236static 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 */
246static 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 */
256static inline int sandev_needs_reopen ( struct san_device *sandev ) {
257 return ( sandev->active == NULL );
258}
259
260extern struct san_device * sandev_find ( unsigned int drive );
261extern struct san_device * sandev_next ( unsigned int drive );
262extern int sandev_reopen ( struct san_device *sandev );
263extern int sandev_reset ( struct san_device *sandev );
264extern int sandev_read ( struct san_device *sandev, uint64_t lba,
265 unsigned int count, void *buffer );
266extern int sandev_write ( struct san_device *sandev, uint64_t lba,
267 unsigned int count, void *buffer );
268extern struct san_device * alloc_sandev ( struct uri **uris, unsigned int count,
269 size_t priv_size );
270extern int register_sandev ( struct san_device *sandev, unsigned int drive,
271 unsigned int flags );
272extern void unregister_sandev ( struct san_device *sandev );
273extern unsigned int san_default_drive ( void );
274
275#endif /* _IPXE_SANBOOT_H */
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
iPXE internal APIs
unsigned long long uint64_t
Definition stdint.h:13
x86-specific sanboot API implementations
Block devices.
sanboot API configuration
Dummy SAN device.
uint8_t flags
Flags.
Definition ena.h:7
uint8_t drive
Drive number.
Definition int13.h:5
static unsigned int count
Number of entries.
Definition dwmac.h:220
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition netvsc.h:5
uint64_t lba
Starting block number.
Definition int13.h:11
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define __attribute__(x)
Definition compiler.h:10
ACPI data structures.
san_device_flags
SAN device flags.
Definition sanboot.h:105
@ SAN_NO_DESCRIBE
Device should not be included in description tables.
Definition sanboot.h:107
static size_t sandev_blksize(struct san_device *sandev)
Calculate SAN device block size.
Definition sanboot.h:236
int sandev_read(struct san_device *sandev, uint64_t lba, unsigned int count, void *buffer)
Read from SAN device.
Definition sanboot.c:647
static uint64_t sandev_capacity(struct san_device *sandev)
Calculate SAN device capacity.
Definition sanboot.h:246
static int sandev_needs_reopen(struct san_device *sandev)
Check if SAN device needs to be reopened.
Definition sanboot.h:256
int sandev_reopen(struct san_device *sandev)
(Re)open SAN device
Definition sanboot.c:373
static int have_sandevs(void)
There exist some SAN devices.
Definition sanboot.h:204
unsigned int san_default_drive(void)
Get default SAN drive number.
Definition sanboot.c:973
static void sandev_put(struct san_device *sandev)
Drop reference to SAN device.
Definition sanboot.h:226
int register_sandev(struct san_device *sandev, unsigned int drive, unsigned int flags)
Register SAN device.
Definition sanboot.c:880
int sandev_write(struct san_device *sandev, uint64_t lba, unsigned int count, void *buffer)
Write to SAN device.
Definition sanboot.c:668
void san_unhook(unsigned int drive)
Unhook SAN device.
static struct san_device * sandev_get(struct san_device *sandev)
Get reference to SAN device.
Definition sanboot.h:215
struct san_device * sandev_next(unsigned int drive)
Find next SAN device by drive number.
Definition sanboot.c:108
int sandev_reset(struct san_device *sandev)
Reset SAN device.
Definition sanboot.c:576
void unregister_sandev(struct san_device *sandev)
Unregister SAN device.
Definition sanboot.c:942
struct san_device * alloc_sandev(struct uri **uris, unsigned int count, size_t priv_size)
Allocate SAN device.
Definition sanboot.c:837
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_device * sandev_find(unsigned int drive)
Find SAN device by drive number.
Definition sanboot.c:92
struct list_head san_devices
int san_boot(unsigned int drive, struct san_boot_config *config)
Attempt to boot from a SAN device.
Linked lists.
#define list_empty(list)
Test whether a list is empty.
Definition list.h:137
Standard do-nothing sanboot interface.
Processes.
Reference counting.
#define ref_get(refcnt)
Get additional reference to object.
Definition refcnt.h:93
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107
Retry timers.
An ACPI descriptor (used to construct ACPI tables)
Definition acpi.h:295
Block device capacity.
Definition blockdev.h:18
uint64_t blocks
Total number of blocks.
Definition blockdev.h:20
size_t blksize
Block size.
Definition blockdev.h:22
An object interface.
Definition interface.h:125
A doubly-linked list entry (or list head)
Definition list.h:19
A retry timer.
Definition retry.h:22
SAN boot configuration parameters.
Definition sanboot.h:111
const char * filename
Boot filename (or NULL to use default)
Definition sanboot.h:113
const char * label
Filesystem label (or NULL to ignore volume label)
Definition sanboot.h:117
union uuid * uuid
UUID (or NULL to ignore UUID)
Definition sanboot.h:119
const char * extra
Required extra filename (or NULL to ignore)
Definition sanboot.h:115
A SAN device.
Definition sanboot.h:59
void * priv
Driver private data.
Definition sanboot.h:90
struct san_path * active
Current active path.
Definition sanboot.h:95
struct retry_timer timer
Command timeout timer.
Definition sanboot.h:73
unsigned int drive
Drive number.
Definition sanboot.h:66
struct refcnt refcnt
Reference count.
Definition sanboot.h:61
unsigned int blksize_shift
Block size shift.
Definition sanboot.h:85
struct list_head opened
List of opened SAN paths.
Definition sanboot.h:97
struct interface command
Command interface.
Definition sanboot.h:71
unsigned int paths
Number of paths.
Definition sanboot.h:93
struct block_device_capacity capacity
Raw block device capacity.
Definition sanboot.h:78
unsigned int flags
Flags.
Definition sanboot.h:68
int command_rc
Command status.
Definition sanboot.h:75
int is_cdrom
Drive is a CD-ROM.
Definition sanboot.h:87
struct list_head list
List of SAN devices.
Definition sanboot.h:63
struct list_head closed
List of closed SAN paths.
Definition sanboot.h:99
struct san_path path[0]
SAN paths.
Definition sanboot.h:101
A SAN path.
Definition sanboot.h:37
struct list_head list
List of open/closed paths.
Definition sanboot.h:45
struct process process
Process.
Definition sanboot.h:50
struct acpi_descriptor * desc
ACPI descriptor (if applicable)
Definition sanboot.h:55
int path_rc
Path status.
Definition sanboot.h:52
unsigned int index
Path index.
Definition sanboot.h:41
struct interface block
Underlying block device interface.
Definition sanboot.h:48
struct uri * uri
SAN device URI.
Definition sanboot.h:43
struct san_device * sandev
Containing SAN device.
Definition sanboot.h:39
A Uniform Resource Identifier.
Definition uri.h:65
Uniform Resource Identifiers.
Universally unique IDs.