2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation; either version 2 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 FILE_LICENCE ( GPL2_OR_LATER );
28 #include <ipxe/isapnp.h>
30 #include <ipxe/eisa.h>
46 * Structure returned from eth_probe and passed to other driver
50 struct nic_operations *nic_op;
51 int flags; /* driver specific flags */
52 unsigned char *node_addr;
53 unsigned char *packet;
54 unsigned int packetlen;
59 void *priv_data; /* driver private data */
62 struct nic_operations {
63 int ( *connect ) ( struct nic * );
64 int ( *poll ) ( struct nic *, int retrieve );
65 void ( *transmit ) ( struct nic *, const char *,
66 unsigned int, unsigned int, const char * );
67 void ( *irq ) ( struct nic *, irq_action_t );
70 extern struct nic nic;
72 static inline int eth_poll ( int retrieve ) {
73 return nic.nic_op->poll ( &nic, retrieve );
76 static inline void eth_transmit ( const char *dest, unsigned int type,
77 unsigned int size, const void *packet ) {
78 nic.nic_op->transmit ( &nic, dest, type, size, packet );
85 extern int dummy_connect ( struct nic *nic );
86 extern void dummy_irq ( struct nic *nic, irq_action_t irq_action );
87 extern int legacy_probe ( void *hwdev,
88 void ( * set_drvdata ) ( void *hwdev, void *priv ),
90 int ( * probe ) ( struct nic *nic, void *hwdev ),
91 void ( * disable ) ( struct nic *nic, void *hwdev ));
92 void legacy_remove ( void *hwdev,
93 void * ( * get_drvdata ) ( void *hwdev ),
94 void ( * disable ) ( struct nic *nic, void *hwdev ) );
96 #define PCI_DRIVER(_name,_ids,_class) \
98 _name ## _pci_legacy_probe ( struct pci_device *pci ); \
100 _name ## _pci_legacy_remove ( struct pci_device *pci ); \
101 struct pci_driver _name __pci_driver = { \
103 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
104 .probe = _name ## _pci_legacy_probe, \
105 .remove = _name ## _pci_legacy_remove, \
107 REQUIRE_OBJECT ( pci );
109 static inline void legacy_pci_set_drvdata ( void *hwdev, void *priv ) {
110 pci_set_drvdata ( hwdev, priv );
112 static inline void * legacy_pci_get_drvdata ( void *hwdev ) {
113 return pci_get_drvdata ( hwdev );
116 #define ISAPNP_DRIVER(_name,_ids) \
118 _name ## _isapnp_legacy_probe ( struct isapnp_device *isapnp, \
119 const struct isapnp_device_id *id ); \
121 _name ## _isapnp_legacy_remove ( struct isapnp_device *isapnp ); \
122 struct isapnp_driver _name __isapnp_driver = { \
124 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
125 .probe = _name ## _isapnp_legacy_probe, \
126 .remove = _name ## _isapnp_legacy_remove, \
128 REQUIRE_OBJECT ( isapnp );
130 static inline void legacy_isapnp_set_drvdata ( void *hwdev, void *priv ) {
131 isapnp_set_drvdata ( hwdev, priv );
133 static inline void * legacy_isapnp_get_drvdata ( void *hwdev ) {
134 return isapnp_get_drvdata ( hwdev );
137 #define EISA_DRIVER(_name,_ids) \
139 _name ## _eisa_legacy_probe ( struct eisa_device *eisa, \
140 const struct eisa_device_id *id ); \
142 _name ## _eisa_legacy_remove ( struct eisa_device *eisa ); \
143 struct eisa_driver _name __eisa_driver = { \
145 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
146 .probe = _name ## _eisa_legacy_probe, \
147 .remove = _name ## _eisa_legacy_remove, \
149 REQUIRE_OBJECT ( eisa );
151 static inline void legacy_eisa_set_drvdata ( void *hwdev, void *priv ) {
152 eisa_set_drvdata ( hwdev, priv );
154 static inline void * legacy_eisa_get_drvdata ( void *hwdev ) {
155 return eisa_get_drvdata ( hwdev );
158 #define MCA_DRIVER(_name,_ids) \
160 _name ## _mca_legacy_probe ( struct mca_device *mca, \
161 const struct mca_device_id *id ); \
163 _name ## _mca_legacy_remove ( struct mca_device *mca ); \
164 struct mca_driver _name __mca_driver = { \
166 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
167 .probe = _name ## _mca_legacy_probe, \
168 .remove = _name ## _mca_legacy_remove, \
170 REQUIRE_OBJECT ( mca );
172 static inline void legacy_mca_set_drvdata ( void *hwdev, void *priv ) {
173 mca_set_drvdata ( hwdev, priv );
175 static inline void * legacy_mca_get_drvdata ( void *hwdev ) {
176 return mca_get_drvdata ( hwdev );
179 #define ISA_DRIVER(_name,_probe_addrs,_probe_addr,_vendor_id,_prod_id) \
181 _name ## _isa_legacy_probe ( struct isa_device *isa ); \
183 _name ## _isa_legacy_probe_at_addr ( struct isa_device *isa ) { \
184 if ( ! _probe_addr ( isa->ioaddr ) ) \
186 return _name ## _isa_legacy_probe ( isa ); \
189 _name ## _isa_legacy_remove ( struct isa_device *isa ); \
190 static const char _name ## _text[]; \
191 struct isa_driver _name __isa_driver = { \
192 .name = _name ## _text, \
193 .probe_addrs = _probe_addrs, \
194 .addr_count = ( sizeof ( _probe_addrs ) / \
195 sizeof ( _probe_addrs[0] ) ), \
196 .vendor_id = _vendor_id, \
197 .prod_id = _prod_id, \
198 .probe = _name ## _isa_legacy_probe_at_addr, \
199 .remove = _name ## _isa_legacy_remove, \
201 REQUIRE_OBJECT ( isa );
203 static inline void legacy_isa_set_drvdata ( void *hwdev, void *priv ) {
204 isa_set_drvdata ( hwdev, priv );
206 static inline void * legacy_isa_get_drvdata ( void *hwdev ) {
207 return isa_get_drvdata ( hwdev );
211 #define DRIVER(_name_text,_unused2,_unused3,_name,_probe,_disable) \
212 static const char _name ## _text[] = _name_text; \
214 _name ## _probe ( struct nic *nic, void *hwdev ) { \
215 return _probe ( nic, hwdev ); \
218 _name ## _disable ( struct nic *nic, void *hwdev ) { \
219 void ( * _unsafe_disable ) () = _disable; \
220 _unsafe_disable ( nic, hwdev ); \
223 _name ## _pci_legacy_probe ( struct pci_device *pci ) { \
224 return legacy_probe ( pci, legacy_pci_set_drvdata, \
225 &pci->dev, _name ## _probe, \
226 _name ## _disable ); \
229 _name ## _pci_legacy_remove ( struct pci_device *pci ) { \
230 return legacy_remove ( pci, legacy_pci_get_drvdata, \
231 _name ## _disable ); \
234 _name ## _isapnp_legacy_probe ( struct isapnp_device *isapnp, \
235 const struct isapnp_device_id *id __unused ) { \
236 return legacy_probe ( isapnp, legacy_isapnp_set_drvdata, \
237 &isapnp->dev, _name ## _probe, \
238 _name ## _disable ); \
241 _name ## _isapnp_legacy_remove ( struct isapnp_device *isapnp ) { \
242 return legacy_remove ( isapnp, legacy_isapnp_get_drvdata, \
243 _name ## _disable ); \
246 _name ## _eisa_legacy_probe ( struct eisa_device *eisa, \
247 const struct eisa_device_id *id __unused ) { \
248 return legacy_probe ( eisa, legacy_eisa_set_drvdata, \
249 &eisa->dev, _name ## _probe, \
250 _name ## _disable ); \
253 _name ## _eisa_legacy_remove ( struct eisa_device *eisa ) { \
254 return legacy_remove ( eisa, legacy_eisa_get_drvdata, \
255 _name ## _disable ); \
258 _name ## _mca_legacy_probe ( struct mca_device *mca, \
259 const struct mca_device_id *id __unused ) { \
260 return legacy_probe ( mca, legacy_mca_set_drvdata, \
261 &mca->dev, _name ## _probe, \
262 _name ## _disable ); \
265 _name ## _mca_legacy_remove ( struct mca_device *mca ) { \
266 return legacy_remove ( mca, legacy_mca_get_drvdata, \
267 _name ## _disable ); \
270 _name ## _isa_legacy_probe ( struct isa_device *isa ) { \
271 return legacy_probe ( isa, legacy_isa_set_drvdata, \
272 &isa->dev, _name ## _probe, \
273 _name ## _disable ); \
276 _name ## _isa_legacy_remove ( struct isa_device *isa ) { \
277 return legacy_remove ( isa, legacy_isa_get_drvdata, \
278 _name ## _disable ); \
280 PROVIDE_REQUIRING_SYMBOL()