2 * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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
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.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
30 #include <ipxe/device.h>
31 #include <ipxe/init.h>
35 #include <undipreload.h>
41 * This is the UNDI driver without explicit support for PCI or any
42 * other bus type. It is capable only of using the preloaded UNDI
43 * device. It must not be combined in an image with any other
46 * If you want a PXE-loadable image that contains only the UNDI
47 * driver, build "bin/undionly.kpxe".
49 * If you want any other image format, or any other drivers in
50 * addition to the UNDI driver, build e.g. "bin/undi.dsk".
56 * @v rootdev UNDI bus root device
58 * Scans the UNDI bus for devices and registers all devices it can
61 static int undibus_probe ( struct root_device *rootdev ) {
62 struct undi_device *undi = &preloaded_undi;
65 /* Check for a valie preloaded UNDI device */
66 if ( ! undi->entry.segment ) {
67 DBG ( "No preloaded UNDI device found!\n" );
71 /* Add to device hierarchy */
72 undi->dev.driver_name = "undionly";
73 if ( undi->pci_busdevfn != UNDI_NO_PCI_BUSDEVFN ) {
74 undi->dev.desc.bus_type = BUS_TYPE_PCI;
75 undi->dev.desc.location = undi->pci_busdevfn;
76 undi->dev.desc.vendor = undi->pci_vendor;
77 undi->dev.desc.device = undi->pci_device;
78 snprintf ( undi->dev.name, sizeof ( undi->dev.name ),
79 "UNDI-PCI%02x:%02x.%x",
80 PCI_BUS ( undi->pci_busdevfn ),
81 PCI_SLOT ( undi->pci_busdevfn ),
82 PCI_FUNC ( undi->pci_busdevfn ) );
83 } else if ( undi->isapnp_csn != UNDI_NO_ISAPNP_CSN ) {
84 undi->dev.desc.bus_type = BUS_TYPE_ISAPNP;
85 snprintf ( undi->dev.name, sizeof ( undi->dev.name ),
88 undi->dev.parent = &rootdev->dev;
89 list_add ( &undi->dev.siblings, &rootdev->dev.children);
90 INIT_LIST_HEAD ( &undi->dev.children );
92 /* Create network device */
93 if ( ( rc = undinet_probe ( undi ) ) != 0 )
99 list_del ( &undi->dev.siblings );
104 * Remove UNDI root bus
106 * @v rootdev UNDI bus root device
108 static void undibus_remove ( struct root_device *rootdev __unused ) {
109 struct undi_device *undi = &preloaded_undi;
111 undinet_remove ( undi );
112 list_del ( &undi->dev.siblings );
115 /** UNDI bus root device driver */
116 static struct root_driver undi_root_driver = {
117 .probe = undibus_probe,
118 .remove = undibus_remove,
121 /** UNDI bus root device */
122 struct root_device undi_root_device __root_device = {
123 .dev = { .name = "UNDI" },
124 .driver = &undi_root_driver,
130 * @v booting System is shutting down for OS boot
132 static void undionly_shutdown ( int booting ) {
133 /* If we are shutting down to boot an OS, clear the "keep PXE
137 preloaded_undi.flags &= ~UNDI_FL_KEEP_ALL;
140 struct startup_fn startup_undionly __startup_fn ( STARTUP_LATE ) = {
141 .shutdown = undionly_shutdown,