Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / arch / i386 / drivers / net / undionly.c
1 /*
2  * Copyright (C) 2007 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
20 FILE_LICENCE ( GPL2_OR_LATER );
21
22 #include <stdint.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <ipxe/device.h>
27 #include <ipxe/init.h>
28 #include <ipxe/pci.h>
29 #include <undi.h>
30 #include <undinet.h>
31 #include <undipreload.h>
32
33 /** @file
34  *
35  * "Pure" UNDI driver
36  *
37  * This is the UNDI driver without explicit support for PCI or any
38  * other bus type.  It is capable only of using the preloaded UNDI
39  * device.  It must not be combined in an image with any other
40  * drivers.
41  *
42  * If you want a PXE-loadable image that contains only the UNDI
43  * driver, build "bin/undionly.kpxe".
44  *
45  * If you want any other image format, or any other drivers in
46  * addition to the UNDI driver, build e.g. "bin/undi.dsk".
47  */
48
49 /**
50  * Probe UNDI root bus
51  *
52  * @v rootdev           UNDI bus root device
53  *
54  * Scans the UNDI bus for devices and registers all devices it can
55  * find.
56  */
57 static int undibus_probe ( struct root_device *rootdev ) {
58         struct undi_device *undi = &preloaded_undi;
59         int rc;
60
61         /* Check for a valie preloaded UNDI device */
62         if ( ! undi->entry.segment ) {
63                 DBG ( "No preloaded UNDI device found!\n" );
64                 return -ENODEV;
65         }
66
67         /* Add to device hierarchy */
68         undi->dev.driver_name = "undionly";
69         if ( undi->pci_busdevfn != UNDI_NO_PCI_BUSDEVFN ) {
70                 undi->dev.desc.bus_type = BUS_TYPE_PCI;
71                 undi->dev.desc.location = undi->pci_busdevfn;
72                 undi->dev.desc.vendor = undi->pci_vendor;
73                 undi->dev.desc.device = undi->pci_device;
74                 snprintf ( undi->dev.name, sizeof ( undi->dev.name ),
75                            "UNDI-PCI%02x:%02x.%x",
76                            PCI_BUS ( undi->pci_busdevfn ),
77                            PCI_SLOT ( undi->pci_busdevfn ),
78                            PCI_FUNC ( undi->pci_busdevfn ) );
79         } else if ( undi->isapnp_csn != UNDI_NO_ISAPNP_CSN ) {
80                 undi->dev.desc.bus_type = BUS_TYPE_ISAPNP;
81                 snprintf ( undi->dev.name, sizeof ( undi->dev.name ),
82                            "UNDI-ISAPNP" );
83         }
84         undi->dev.parent = &rootdev->dev;
85         list_add ( &undi->dev.siblings, &rootdev->dev.children);
86         INIT_LIST_HEAD ( &undi->dev.children );
87
88         /* Create network device */
89         if ( ( rc = undinet_probe ( undi ) ) != 0 )
90                 goto err;
91
92         return 0;
93
94  err:
95         list_del ( &undi->dev.siblings );
96         return rc;
97 }
98
99 /**
100  * Remove UNDI root bus
101  *
102  * @v rootdev           UNDI bus root device
103  */
104 static void undibus_remove ( struct root_device *rootdev __unused ) {
105         struct undi_device *undi = &preloaded_undi;
106
107         undinet_remove ( undi );
108         list_del ( &undi->dev.siblings );
109 }
110
111 /** UNDI bus root device driver */
112 static struct root_driver undi_root_driver = {
113         .probe = undibus_probe,
114         .remove = undibus_remove,
115 };
116
117 /** UNDI bus root device */
118 struct root_device undi_root_device __root_device = {
119         .dev = { .name = "UNDI" },
120         .driver = &undi_root_driver,
121 };
122
123 /**
124  * Prepare for exit
125  *
126  * @v booting           System is shutting down for OS boot
127  */
128 static void undionly_shutdown ( int booting ) {
129         /* If we are shutting down to boot an OS, clear the "keep PXE
130          * stack" flag.
131          */
132         if ( booting )
133                 preloaded_undi.flags &= ~UNDI_FL_KEEP_ALL;
134 }
135
136 struct startup_fn startup_undionly __startup_fn ( STARTUP_LATE ) = {
137         .shutdown = undionly_shutdown,
138 };