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, or (at
5 * your option) any later version.
8 FILE_LICENCE ( GPL2_OR_LATER );
18 #include <ipxe/isapnp.h>
20 #include <ipxe/eisa.h>
36 * Structure returned from eth_probe and passed to other driver
40 struct nic_operations *nic_op;
41 int flags; /* driver specific flags */
42 unsigned char *node_addr;
43 unsigned char *packet;
44 unsigned int packetlen;
49 void *priv_data; /* driver private data */
52 struct nic_operations {
53 int ( *connect ) ( struct nic * );
54 int ( *poll ) ( struct nic *, int retrieve );
55 void ( *transmit ) ( struct nic *, const char *,
56 unsigned int, unsigned int, const char * );
57 void ( *irq ) ( struct nic *, irq_action_t );
60 extern struct nic nic;
62 static inline int eth_poll ( int retrieve ) {
63 return nic.nic_op->poll ( &nic, retrieve );
66 static inline void eth_transmit ( const char *dest, unsigned int type,
67 unsigned int size, const void *packet ) {
68 nic.nic_op->transmit ( &nic, dest, type, size, packet );
75 extern int dummy_connect ( struct nic *nic );
76 extern void dummy_irq ( struct nic *nic, irq_action_t irq_action );
77 extern int legacy_probe ( void *hwdev,
78 void ( * set_drvdata ) ( void *hwdev, void *priv ),
80 int ( * probe ) ( struct nic *nic, void *hwdev ),
81 void ( * disable ) ( struct nic *nic, void *hwdev ));
82 void legacy_remove ( void *hwdev,
83 void * ( * get_drvdata ) ( void *hwdev ),
84 void ( * disable ) ( struct nic *nic, void *hwdev ) );
86 #define PCI_DRIVER(_name,_ids,_class) \
88 _name ## _pci_legacy_probe ( struct pci_device *pci ); \
90 _name ## _pci_legacy_remove ( struct pci_device *pci ); \
91 struct pci_driver _name __pci_driver = { \
93 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
94 .probe = _name ## _pci_legacy_probe, \
95 .remove = _name ## _pci_legacy_remove, \
97 REQUIRE_OBJECT ( pci );
99 static inline void legacy_pci_set_drvdata ( void *hwdev, void *priv ) {
100 pci_set_drvdata ( hwdev, priv );
102 static inline void * legacy_pci_get_drvdata ( void *hwdev ) {
103 return pci_get_drvdata ( hwdev );
106 #define ISAPNP_DRIVER(_name,_ids) \
108 _name ## _isapnp_legacy_probe ( struct isapnp_device *isapnp, \
109 const struct isapnp_device_id *id ); \
111 _name ## _isapnp_legacy_remove ( struct isapnp_device *isapnp ); \
112 struct isapnp_driver _name __isapnp_driver = { \
114 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
115 .probe = _name ## _isapnp_legacy_probe, \
116 .remove = _name ## _isapnp_legacy_remove, \
118 REQUIRE_OBJECT ( isapnp );
120 static inline void legacy_isapnp_set_drvdata ( void *hwdev, void *priv ) {
121 isapnp_set_drvdata ( hwdev, priv );
123 static inline void * legacy_isapnp_get_drvdata ( void *hwdev ) {
124 return isapnp_get_drvdata ( hwdev );
127 #define EISA_DRIVER(_name,_ids) \
129 _name ## _eisa_legacy_probe ( struct eisa_device *eisa, \
130 const struct eisa_device_id *id ); \
132 _name ## _eisa_legacy_remove ( struct eisa_device *eisa ); \
133 struct eisa_driver _name __eisa_driver = { \
135 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
136 .probe = _name ## _eisa_legacy_probe, \
137 .remove = _name ## _eisa_legacy_remove, \
139 REQUIRE_OBJECT ( eisa );
141 static inline void legacy_eisa_set_drvdata ( void *hwdev, void *priv ) {
142 eisa_set_drvdata ( hwdev, priv );
144 static inline void * legacy_eisa_get_drvdata ( void *hwdev ) {
145 return eisa_get_drvdata ( hwdev );
148 #define MCA_DRIVER(_name,_ids) \
150 _name ## _mca_legacy_probe ( struct mca_device *mca, \
151 const struct mca_device_id *id ); \
153 _name ## _mca_legacy_remove ( struct mca_device *mca ); \
154 struct mca_driver _name __mca_driver = { \
156 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
157 .probe = _name ## _mca_legacy_probe, \
158 .remove = _name ## _mca_legacy_remove, \
160 REQUIRE_OBJECT ( mca );
162 static inline void legacy_mca_set_drvdata ( void *hwdev, void *priv ) {
163 mca_set_drvdata ( hwdev, priv );
165 static inline void * legacy_mca_get_drvdata ( void *hwdev ) {
166 return mca_get_drvdata ( hwdev );
169 #define ISA_DRIVER(_name,_probe_addrs,_probe_addr,_vendor_id,_prod_id) \
171 _name ## _isa_legacy_probe ( struct isa_device *isa ); \
173 _name ## _isa_legacy_probe_at_addr ( struct isa_device *isa ) { \
174 if ( ! _probe_addr ( isa->ioaddr ) ) \
176 return _name ## _isa_legacy_probe ( isa ); \
179 _name ## _isa_legacy_remove ( struct isa_device *isa ); \
180 static const char _name ## _text[]; \
181 struct isa_driver _name __isa_driver = { \
182 .name = _name ## _text, \
183 .probe_addrs = _probe_addrs, \
184 .addr_count = ( sizeof ( _probe_addrs ) / \
185 sizeof ( _probe_addrs[0] ) ), \
186 .vendor_id = _vendor_id, \
187 .prod_id = _prod_id, \
188 .probe = _name ## _isa_legacy_probe_at_addr, \
189 .remove = _name ## _isa_legacy_remove, \
191 REQUIRE_OBJECT ( isa );
193 static inline void legacy_isa_set_drvdata ( void *hwdev, void *priv ) {
194 isa_set_drvdata ( hwdev, priv );
196 static inline void * legacy_isa_get_drvdata ( void *hwdev ) {
197 return isa_get_drvdata ( hwdev );
201 #define DRIVER(_name_text,_unused2,_unused3,_name,_probe,_disable) \
202 static const char _name ## _text[] = _name_text; \
204 _name ## _probe ( struct nic *nic, void *hwdev ) { \
205 return _probe ( nic, hwdev ); \
208 _name ## _disable ( struct nic *nic, void *hwdev ) { \
209 void ( * _unsafe_disable ) () = _disable; \
210 _unsafe_disable ( nic, hwdev ); \
213 _name ## _pci_legacy_probe ( struct pci_device *pci ) { \
214 return legacy_probe ( pci, legacy_pci_set_drvdata, \
215 &pci->dev, _name ## _probe, \
216 _name ## _disable ); \
219 _name ## _pci_legacy_remove ( struct pci_device *pci ) { \
220 return legacy_remove ( pci, legacy_pci_get_drvdata, \
221 _name ## _disable ); \
224 _name ## _isapnp_legacy_probe ( struct isapnp_device *isapnp, \
225 const struct isapnp_device_id *id __unused ) { \
226 return legacy_probe ( isapnp, legacy_isapnp_set_drvdata, \
227 &isapnp->dev, _name ## _probe, \
228 _name ## _disable ); \
231 _name ## _isapnp_legacy_remove ( struct isapnp_device *isapnp ) { \
232 return legacy_remove ( isapnp, legacy_isapnp_get_drvdata, \
233 _name ## _disable ); \
236 _name ## _eisa_legacy_probe ( struct eisa_device *eisa, \
237 const struct eisa_device_id *id __unused ) { \
238 return legacy_probe ( eisa, legacy_eisa_set_drvdata, \
239 &eisa->dev, _name ## _probe, \
240 _name ## _disable ); \
243 _name ## _eisa_legacy_remove ( struct eisa_device *eisa ) { \
244 return legacy_remove ( eisa, legacy_eisa_get_drvdata, \
245 _name ## _disable ); \
248 _name ## _mca_legacy_probe ( struct mca_device *mca, \
249 const struct mca_device_id *id __unused ) { \
250 return legacy_probe ( mca, legacy_mca_set_drvdata, \
251 &mca->dev, _name ## _probe, \
252 _name ## _disable ); \
255 _name ## _mca_legacy_remove ( struct mca_device *mca ) { \
256 return legacy_remove ( mca, legacy_mca_get_drvdata, \
257 _name ## _disable ); \
260 _name ## _isa_legacy_probe ( struct isa_device *isa ) { \
261 return legacy_probe ( isa, legacy_isa_set_drvdata, \
262 &isa->dev, _name ## _probe, \
263 _name ## _disable ); \
266 _name ## _isa_legacy_remove ( struct isa_device *isa ) { \
267 return legacy_remove ( isa, legacy_isa_get_drvdata, \
268 _name ## _disable ); \