iPXE
dummy_sanboot.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26/** @file
27 *
28 * Dummy SAN device
29 *
30 */
31
32#include <string.h>
33#include <errno.h>
34#include <ipxe/sanboot.h>
35
36/**
37 * Hook dummy SAN device
38 *
39 * @v drive Drive number
40 * @v uris List of URIs
41 * @v count Number of URIs
42 * @v flags Flags
43 * @ret drive Drive number, or negative error
44 */
45static int dummy_san_hook ( unsigned int drive, struct uri **uris,
46 unsigned int count, unsigned int flags ) {
47 struct san_device *sandev;
48 int rc;
49
50 /* Allocate SAN device */
51 sandev = alloc_sandev ( uris, count, 0 );
52 if ( ! sandev ) {
53 rc = -ENOMEM;
54 goto err_alloc;
55 }
56
57 /* Register SAN device */
58 if ( ( rc = register_sandev ( sandev, drive, flags ) ) != 0 ) {
59 DBGC ( sandev->drive, "SAN %#02x could not register: %s\n",
60 sandev->drive, strerror ( rc ) );
61 goto err_register;
62 }
63
64 return drive;
65
66 unregister_sandev ( sandev );
67 err_register:
68 sandev_put ( sandev );
69 err_alloc:
70 return rc;
71}
72
73/**
74 * Unhook dummy SAN device
75 *
76 * @v drive Drive number
77 */
78static void dummy_san_unhook ( unsigned int drive ) {
79 struct san_device *sandev;
80
81 /* Find drive */
82 sandev = sandev_find ( drive );
83 if ( ! sandev ) {
84 DBGC ( drive, "SAN %#02x does not exist\n", drive );
85 return;
86 }
87
88 /* Unregister SAN device */
89 unregister_sandev ( sandev );
90
91 /* Drop reference to drive */
92 sandev_put ( sandev );
93}
94
95/**
96 * Boot from dummy SAN device
97 *
98 * @v drive Drive number
99 * @v config Boot configuration parameters
100 * @ret rc Return status code
101 */
102static int dummy_san_boot ( unsigned int drive __unused,
103 struct san_boot_config *config __unused ) {
104
105 return -EOPNOTSUPP;
106}
107
108/**
109 * Install ACPI table
110 *
111 * @v acpi ACPI description header
112 * @ret rc Return status code
113 */
114static int dummy_install ( struct acpi_header *acpi ) {
115
116 DBGC ( acpi, "ACPI table %s:\n", acpi_name ( acpi->signature ) );
117 DBGC_HDA ( acpi, 0, acpi, le32_to_cpu ( acpi->length ) );
118 return 0;
119}
120
121/**
122 * Describe dummy SAN device
123 *
124 * @ret rc Return status code
125 */
126static int dummy_san_describe ( void ) {
127
128 return acpi_install ( dummy_install );
129}
130
int acpi_install(int(*install)(struct acpi_header *acpi))
Install ACPI tables.
Definition acpi.c:344
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static int dummy_san_describe(void)
Describe dummy SAN device.
static int dummy_install(struct acpi_header *acpi)
Install ACPI table.
static int dummy_san_hook(unsigned int drive, struct uri **uris, unsigned int count, unsigned int flags)
Hook dummy SAN device.
static int dummy_san_boot(unsigned int drive __unused, struct san_boot_config *config __unused)
Boot from dummy SAN device.
static void dummy_san_unhook(unsigned int drive)
Unhook dummy SAN device.
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition efi_block.c:67
uint8_t flags
Flags.
Definition ena.h:7
Error codes.
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#define DBGC(...)
Definition compiler.h:505
#define DBGC_HDA(...)
Definition compiler.h:506
uint8_t drive
Drive number.
Definition int13.h:5
static unsigned int count
Number of entries.
Definition dwmac.h:220
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define EOPNOTSUPP
Operation not supported on socket.
Definition errno.h:605
#define ENOMEM
Not enough space.
Definition errno.h:535
#define le32_to_cpu(value)
Definition byteswap.h:114
static const char * acpi_name(uint32_t signature)
Transcribe ACPI table signature (for debugging)
Definition acpi.h:207
iPXE sanboot API
static void sandev_put(struct san_device *sandev)
Drop reference to SAN device.
Definition sanboot.h:226
void san_unhook(unsigned int drive)
Unhook SAN device.
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.
int san_boot(unsigned int drive, struct san_boot_config *config)
Attempt to boot from a SAN device.
#define PROVIDE_SANBOOT(_subsys, _api_func, _func)
Provide a sanboot API implementation.
Definition sanboot.h:139
String functions.
int register_sandev(struct san_device *sandev, unsigned int drive, unsigned int flags)
Register SAN device.
Definition sanboot.c:880
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
struct san_device * sandev_find(unsigned int drive)
Find SAN device by drive number.
Definition sanboot.c:92
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
An ACPI description header.
Definition acpi.h:180
SAN boot configuration parameters.
Definition sanboot.h:111
A SAN device.
Definition sanboot.h:59
unsigned int drive
Drive number.
Definition sanboot.h:66
A Uniform Resource Identifier.
Definition uri.h:65