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 <errno.h>
33 #include <ipxe/sanboot.h>
34 
35 /**
36  * Hook dummy SAN device
37  *
38  * @v drive Drive number
39  * @v uris List of URIs
40  * @v count Number of URIs
41  * @v flags Flags
42  * @ret drive Drive number, or negative error
43  */
44 static int dummy_san_hook ( unsigned int drive, struct uri **uris,
45  unsigned int count, unsigned int flags ) {
46  struct san_device *sandev;
47  int rc;
48 
49  /* Allocate SAN device */
50  sandev = alloc_sandev ( uris, count, 0 );
51  if ( ! sandev ) {
52  rc = -ENOMEM;
53  goto err_alloc;
54  }
55 
56  /* Register SAN device */
57  if ( ( rc = register_sandev ( sandev, drive, flags ) ) != 0 ) {
58  DBGC ( sandev, "SAN %#02x could not register: %s\n",
59  sandev->drive, strerror ( rc ) );
60  goto err_register;
61  }
62 
63  return drive;
64 
65  unregister_sandev ( sandev );
66  err_register:
67  sandev_put ( sandev );
68  err_alloc:
69  return rc;
70 }
71 
72 /**
73  * Unhook dummy SAN device
74  *
75  * @v drive Drive number
76  */
77 static void dummy_san_unhook ( unsigned int drive ) {
78  struct san_device *sandev;
79 
80  /* Find drive */
81  sandev = sandev_find ( drive );
82  if ( ! sandev ) {
83  DBG ( "SAN %#02x does not exist\n", drive );
84  return;
85  }
86 
87  /* Unregister SAN device */
88  unregister_sandev ( sandev );
89 
90  /* Drop reference to drive */
91  sandev_put ( sandev );
92 }
93 
94 /**
95  * Boot from dummy SAN device
96  *
97  * @v drive Drive number
98  * @v filename Filename (or NULL to use default)
99  * @ret rc Return status code
100  */
101 static int dummy_san_boot ( unsigned int drive __unused,
102  const char *filename __unused ) {
103 
104  return -EOPNOTSUPP;
105 }
106 
107 /**
108  * Install ACPI table
109  *
110  * @v acpi ACPI description header
111  * @ret rc Return status code
112  */
113 static int dummy_install ( struct acpi_header *acpi ) {
114 
115  DBGC ( acpi, "ACPI table %s:\n", acpi_name ( acpi->signature ) );
116  DBGC_HDA ( acpi, 0, acpi, le32_to_cpu ( acpi->length ) );
117  return 0;
118 }
119 
120 /**
121  * Describe dummy SAN device
122  *
123  * @ret rc Return status code
124  */
125 static int dummy_san_describe ( void ) {
126 
127  return acpi_install ( dummy_install );
128 }
129 
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
int san_boot(unsigned int drive, const char *filename)
Attempt to boot from a SAN device.
Error codes.
void unregister_sandev(struct san_device *sandev)
Unregister SAN device.
Definition: sanboot.c:925
#define DBGC(...)
Definition: compiler.h:505
static void sandev_put(struct san_device *sandev)
Drop reference to SAN device.
Definition: sanboot.h:202
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
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:61
unsigned int drive
Drive number.
Definition: sanboot.h:54
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:44
int register_sandev(struct san_device *sandev, unsigned int drive, unsigned int flags)
Register SAN device.
Definition: sanboot.c:868
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:357
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:47
An ACPI description header.
Definition: acpi.h:28
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
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:100
uint16_t count
Number of entries.
Definition: ena.h:22
static const char * acpi_name(uint32_t signature)
Transcribe ACPI table signature (for debugging)
Definition: acpi.h:55
static int dummy_san_describe(void)
Describe dummy SAN device.
A Uniform Resource Identifier.
Definition: uri.h:50
static int dummy_install(struct acpi_header *acpi)
Install ACPI table.
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
iPXE sanboot API
static int dummy_san_boot(unsigned int drive __unused, const char *filename __unused)
Boot from dummy SAN device.
static void dummy_san_unhook(unsigned int drive)
Unhook dummy SAN device.
Definition: dummy_sanboot.c:77
struct san_device * alloc_sandev(struct uri **uris, unsigned int count, size_t priv_size)
Allocate SAN device.
Definition: sanboot.c:825
uint8_t flags
Flags.
Definition: ena.h:18