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 
24 FILE_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  */
45 static 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  */
78 static 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  */
102 static 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  */
114 static 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  */
126 static int dummy_san_describe ( void ) {
127 
128  return acpi_install ( dummy_install );
129 }
130 
static int dummy_san_boot(unsigned int drive __unused, struct san_boot_config *config __unused)
Boot from dummy SAN device.
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
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.
#define le32_to_cpu(value)
Definition: byteswap.h:113
Error codes.
void unregister_sandev(struct san_device *sandev)
Unregister SAN device.
Definition: sanboot.c:941
int san_boot(unsigned int drive, struct san_boot_config *config)
Attempt to boot from a SAN device.
#define DBGC(...)
Definition: compiler.h:505
static void sandev_put(struct san_device *sandev)
Drop reference to SAN device.
Definition: sanboot.h:225
uint8_t drive
Drive number.
Definition: int13.h:16
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define DBGC_HDA(...)
Definition: compiler.h:506
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:66
unsigned int drive
Drive number.
Definition: sanboot.h:65
SAN boot configuration parameters.
Definition: sanboot.h:110
static int dummy_san_hook(unsigned int drive, struct uri **uris, unsigned int count, unsigned int flags)
Hook dummy SAN device.
Definition: dummy_sanboot.c:45
int register_sandev(struct san_device *sandev, unsigned int drive, unsigned int flags)
Register SAN device.
Definition: sanboot.c:879
static unsigned int count
Number of entries.
Definition: dwmac.h:225
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
PROVIDE_SANBOOT(dummy, san_hook, dummy_san_hook)
int acpi_install(int(*install)(struct acpi_header *acpi))
Install ACPI tables.
Definition: acpi.c:343
uint8_t flags
Flags.
Definition: ena.h:18
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define EOPNOTSUPP
Operation not supported on socket.
Definition: errno.h:604
A SAN device.
Definition: sanboot.h:58
An ACPI description header.
Definition: acpi.h:179
void san_unhook(unsigned int drive)
Unhook SAN device.
struct san_device * sandev_find(unsigned int drive)
Find SAN device by drive number.
Definition: sanboot.c:91
static const char * acpi_name(uint32_t signature)
Transcribe ACPI table signature (for debugging)
Definition: acpi.h:206
static int dummy_san_describe(void)
Describe dummy SAN device.
A Uniform Resource Identifier.
Definition: uri.h:64
static int dummy_install(struct acpi_header *acpi)
Install ACPI table.
iPXE sanboot API
String functions.
static void dummy_san_unhook(unsigned int drive)
Unhook dummy SAN device.
Definition: dummy_sanboot.c:78
struct san_device * alloc_sandev(struct uri **uris, unsigned int count, size_t priv_size)
Allocate SAN device.
Definition: sanboot.c:836