iPXE
dummy_sanboot.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2017 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 /** @file
00027  *
00028  * Dummy SAN device
00029  *
00030  */
00031 
00032 #include <errno.h>
00033 #include <ipxe/sanboot.h>
00034 
00035 /**
00036  * Hook dummy SAN device
00037  *
00038  * @v drive             Drive number
00039  * @v uris              List of URIs
00040  * @v count             Number of URIs
00041  * @v flags             Flags
00042  * @ret drive           Drive number, or negative error
00043  */
00044 static int dummy_san_hook ( unsigned int drive, struct uri **uris,
00045                             unsigned int count, unsigned int flags ) {
00046         struct san_device *sandev;
00047         int rc;
00048 
00049         /* Allocate SAN device */
00050         sandev = alloc_sandev ( uris, count, 0 );
00051         if ( ! sandev ) {
00052                 rc = -ENOMEM;
00053                 goto err_alloc;
00054         }
00055 
00056         /* Register SAN device */
00057         if ( ( rc = register_sandev ( sandev, drive, flags ) ) != 0 ) {
00058                 DBGC ( sandev, "SAN %#02x could not register: %s\n",
00059                        sandev->drive, strerror ( rc ) );
00060                 goto err_register;
00061         }
00062 
00063         return drive;
00064 
00065         unregister_sandev ( sandev );
00066  err_register:
00067         sandev_put ( sandev );
00068  err_alloc:
00069         return rc;
00070 }
00071 
00072 /**
00073  * Unhook dummy SAN device
00074  *
00075  * @v drive             Drive number
00076  */
00077 static void dummy_san_unhook ( unsigned int drive ) {
00078         struct san_device *sandev;
00079 
00080         /* Find drive */
00081         sandev = sandev_find ( drive );
00082         if ( ! sandev ) {
00083                 DBG ( "SAN %#02x does not exist\n", drive );
00084                 return;
00085         }
00086 
00087         /* Unregister SAN device */
00088         unregister_sandev ( sandev );
00089 
00090         /* Drop reference to drive */
00091         sandev_put ( sandev );
00092 }
00093 
00094 /**
00095  * Boot from dummy SAN device
00096  *
00097  * @v drive             Drive number
00098  * @v filename          Filename (or NULL to use default)
00099  * @ret rc              Return status code
00100  */
00101 static int dummy_san_boot ( unsigned int drive __unused,
00102                             const char *filename __unused ) {
00103 
00104         return -EOPNOTSUPP;
00105 }
00106 
00107 /**
00108  * Install ACPI table
00109  *
00110  * @v acpi              ACPI description header
00111  * @ret rc              Return status code
00112  */
00113 static int dummy_install ( struct acpi_header *acpi ) {
00114 
00115         DBGC ( acpi, "ACPI table %s:\n", acpi_name ( acpi->signature ) );
00116         DBGC_HDA ( acpi, 0, acpi, le32_to_cpu ( acpi->length ) );
00117         return 0;
00118 }
00119 
00120 /**
00121  * Describe dummy SAN device
00122  *
00123  * @ret rc              Return status code
00124  */
00125 static int dummy_san_describe ( void ) {
00126 
00127         return acpi_install ( dummy_install );
00128 }
00129 
00130 PROVIDE_SANBOOT ( dummy, san_hook, dummy_san_hook );
00131 PROVIDE_SANBOOT ( dummy, san_unhook, dummy_san_unhook );
00132 PROVIDE_SANBOOT ( dummy, san_boot, dummy_san_boot );
00133 PROVIDE_SANBOOT ( dummy, san_describe, dummy_san_describe );