Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / isapnp.h
1 /**************************************************************************
2 *
3 *    isapnp.h -- Etherboot isapnp support for the 3Com 3c515
4 *    Written 2002-2003 by Timothy Legge <tlegge@rogers.com>
5 *
6 *    This program is free software; you can redistribute it and/or modify
7 *    it under the terms of the GNU General Public License as published by
8 *    the Free Software Foundation; either version 2 of the License, or
9 *    (at your option) any later version.
10 *
11 *    This program is distributed in the hope that it will be useful,
12 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *    GNU General Public License for more details.
15 *
16 *    You should have received a copy of the GNU General Public License
17 *    along with this program; if not, write to the Free Software
18 *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 *    02110-1301, USA.
20 *
21 *    Portions of this code:
22 *               Copyright (C) 2001  P.J.H.Fox (fox@roestock.demon.co.uk)
23 *
24 *
25 *
26 *    REVISION HISTORY:
27 *    ================
28 *        Version 0.1 April 26, 2002     TJL
29 *        Version 0.2 01/08/2003                 TJL Renamed from 3c515_isapnp.h
30 *
31 *
32 *    Generalised into an ISAPnP bus that can be used by more than just
33 *    the 3c515 by Michael Brown <mbrown@fensystems.co.uk>
34 *
35 ***************************************************************************/
36
37 FILE_LICENCE ( GPL2_OR_LATER );
38
39 #ifndef ISAPNP_H
40 #define ISAPNP_H
41
42 #include <stdint.h>
43 #include <ipxe/isa_ids.h>
44 #include <ipxe/device.h>
45 #include <ipxe/tables.h>
46
47 /*
48  * ISAPnP constants
49  *
50  */
51
52 /* Port addresses */
53 #define ISAPNP_ADDRESS          0x279
54 #define ISAPNP_WRITE_DATA       0xa79
55 #define ISAPNP_READ_PORT_MIN    0x203
56 #define ISAPNP_READ_PORT_START  0x213   /* ISAPnP spec says 0x203, but
57                                          * Linux ISAPnP starts at
58                                          * 0x213 with no explanatory
59                                          * comment.  0x203 probably
60                                          * clashes with something. */
61 #define ISAPNP_READ_PORT_MAX    0x3ff
62 #define ISAPNP_READ_PORT_STEP   0x10    /* Can be any multiple of 4
63                                          * according to the spec, but
64                                          * since ISA I/O addresses are
65                                          * allocated in blocks of 16,
66                                          * it makes no sense to use
67                                          * any value less than 16.
68                                          */
69
70 /* Card select numbers */
71 #define ISAPNP_CSN_MIN          0x01
72 #define ISAPNP_CSN_MAX          0x0f
73
74 /* Registers */
75 #define ISAPNP_READPORT                 0x00
76 #define ISAPNP_SERIALISOLATION          0x01
77 #define ISAPNP_CONFIGCONTROL            0x02
78 #define ISAPNP_WAKE                     0x03
79 #define ISAPNP_RESOURCEDATA             0x04
80 #define ISAPNP_STATUS                   0x05
81 #define ISAPNP_CARDSELECTNUMBER         0x06
82 #define ISAPNP_LOGICALDEVICENUMBER      0x07
83 #define ISAPNP_ACTIVATE                 0x30
84 #define ISAPNP_IORANGECHECK             0x31
85 #define ISAPNP_IOBASE(n)                ( 0x60 + ( (n) * 2 ) )
86 #define ISAPNP_IRQNO(n)                 ( 0x70 + ( (n) * 2 ) )
87 #define ISAPNP_IRQTYPE(n)               ( 0x71 + ( (n) * 2 ) )
88
89 /* Bits in the CONFIGCONTROL register */
90 #define ISAPNP_CONFIG_RESET             ( 1 << 0 )
91 #define ISAPNP_CONFIG_WAIT_FOR_KEY      ( 1 << 1 )
92 #define ISAPNP_CONFIG_RESET_CSN         ( 1 << 2 )
93 #define ISAPNP_CONFIG_RESET_DRV         ( ISAPNP_CONFIG_RESET |         \
94                                           ISAPNP_CONFIG_WAIT_FOR_KEY |  \
95                                           ISAPNP_CONFIG_RESET_CSN )
96
97 /* The LFSR used for the initiation key and for checksumming */
98 #define ISAPNP_LFSR_SEED                0x6a
99
100 /* Small tags */
101 #define ISAPNP_IS_SMALL_TAG(tag)        ( ! ( (tag) & 0x80 ) )
102 #define ISAPNP_SMALL_TAG_NAME(tag)      ( ( (tag) >> 3 ) & 0xf )
103 #define ISAPNP_SMALL_TAG_LEN(tag)       ( ( (tag) & 0x7 ) )
104 #define ISAPNP_TAG_PNPVERNO             0x01
105 #define ISAPNP_TAG_LOGDEVID             0x02
106 #define ISAPNP_TAG_COMPATDEVID          0x03
107 #define ISAPNP_TAG_IRQ                  0x04
108 #define ISAPNP_TAG_DMA                  0x05
109 #define ISAPNP_TAG_STARTDEP             0x06
110 #define ISAPNP_TAG_ENDDEP               0x07
111 #define ISAPNP_TAG_IOPORT               0x08
112 #define ISAPNP_TAG_FIXEDIO              0x09
113 #define ISAPNP_TAG_RSVDSHORTA           0x0A
114 #define ISAPNP_TAG_RSVDSHORTB           0x0B
115 #define ISAPNP_TAG_RSVDSHORTC           0x0C
116 #define ISAPNP_TAG_RSVDSHORTD           0x0D
117 #define ISAPNP_TAG_VENDORSHORT          0x0E
118 #define ISAPNP_TAG_END                  0x0F
119 /* Large tags */
120 #define ISAPNP_IS_LARGE_TAG(tag)        ( ( (tag) & 0x80 ) )
121 #define ISAPNP_LARGE_TAG_NAME(tag)      (tag)
122 #define ISAPNP_TAG_MEMRANGE             0x81
123 #define ISAPNP_TAG_ANSISTR              0x82
124 #define ISAPNP_TAG_UNICODESTR           0x83
125 #define ISAPNP_TAG_VENDORLONG           0x84
126 #define ISAPNP_TAG_MEM32RANGE           0x85
127 #define ISAPNP_TAG_FIXEDMEM32RANGE      0x86
128 #define ISAPNP_TAG_RSVDLONG0            0xF0
129 #define ISAPNP_TAG_RSVDLONG1            0xF1
130 #define ISAPNP_TAG_RSVDLONG2            0xF2
131 #define ISAPNP_TAG_RSVDLONG3            0xF3
132 #define ISAPNP_TAG_RSVDLONG4            0xF4
133 #define ISAPNP_TAG_RSVDLONG5            0xF5
134 #define ISAPNP_TAG_RSVDLONG6            0xF6
135 #define ISAPNP_TAG_RSVDLONG7            0xF7
136 #define ISAPNP_TAG_RSVDLONG8            0xF8
137 #define ISAPNP_TAG_RSVDLONG9            0xF9
138 #define ISAPNP_TAG_RSVDLONGA            0xFA
139 #define ISAPNP_TAG_RSVDLONGB            0xFB
140 #define ISAPNP_TAG_RSVDLONGC            0xFC
141 #define ISAPNP_TAG_RSVDLONGD            0xFD
142 #define ISAPNP_TAG_RSVDLONGE            0xFE
143 #define ISAPNP_TAG_RSVDLONGF            0xFF
144 #define ISAPNP_TAG_PSEUDO_NEWBOARD      0x100
145
146 /** An ISAPnP serial identifier */
147 struct isapnp_identifier {
148         /** Vendor ID */
149         uint16_t vendor_id;
150         /** Product ID */
151         uint16_t prod_id;
152         /** Serial number */
153         uint32_t serial;
154         /** Checksum */
155         uint8_t checksum;
156 } __attribute__ (( packed ));
157
158 /** An ISAPnP logical device ID structure */
159 struct isapnp_logdevid {
160         /** Vendor ID */
161         uint16_t vendor_id;
162         /** Product ID */
163         uint16_t prod_id;
164         /** Flags */
165         uint16_t flags;
166 } __attribute__ (( packed ));
167
168 /** An ISAPnP device ID list entry */
169 struct isapnp_device_id {
170         /** Name */
171         const char *name;
172         /** Vendor ID */
173         uint16_t vendor_id;
174         /** Product ID */
175         uint16_t prod_id;
176 };
177
178 /** An ISAPnP device */
179 struct isapnp_device {
180         /** Generic device */
181         struct device dev;
182         /** Vendor ID */
183         uint16_t vendor_id;
184         /** Product ID */
185         uint16_t prod_id;
186         /** I/O address */
187         uint16_t ioaddr;
188         /** Interrupt number */
189         uint8_t irqno;
190         /** Card Select Number */
191         uint8_t csn;
192         /** Logical Device ID */
193         uint8_t logdev;
194         /** Driver for this device */
195         struct isapnp_driver *driver;
196         /** Driver-private data
197          *
198          * Use isapnp_set_drvdata() and isapnp_get_drvdata() to access
199          * this field.
200          */
201         void *priv;
202 };
203
204 /** An ISAPnP driver */
205 struct isapnp_driver {
206         /** ISAPnP ID table */
207         struct isapnp_device_id *ids;
208         /** Number of entries in ISAPnP ID table */
209         unsigned int id_count;
210         /**
211          * Probe device
212          *
213          * @v isapnp    ISAPnP device
214          * @v id        Matching entry in ID table
215          * @ret rc      Return status code
216          */
217         int ( * probe ) ( struct isapnp_device *isapnp,
218                           const struct isapnp_device_id *id );
219         /**
220          * Remove device
221          *
222          * @v isapnp    ISAPnP device
223          */
224         void ( * remove ) ( struct isapnp_device *isapnp );
225 };
226
227 /** ISAPnP driver table */
228 #define ISAPNP_DRIVERS __table ( struct isapnp_driver, "isapnp_drivers" )
229
230 /** Declare an ISAPnP driver */
231 #define __isapnp_driver __table_entry ( ISAPNP_DRIVERS, 01 )
232
233 extern uint16_t isapnp_read_port;
234
235 extern void isapnp_device_activation ( struct isapnp_device *isapnp,
236                                        int activation );
237
238 /**
239  * Activate ISAPnP device
240  *
241  * @v isapnp            ISAPnP device
242  */
243 static inline void activate_isapnp_device ( struct isapnp_device *isapnp ) {
244         isapnp_device_activation ( isapnp, 1 );
245 }
246
247 /**
248  * Deactivate ISAPnP device
249  *
250  * @v isapnp            ISAPnP device
251  */
252 static inline void deactivate_isapnp_device ( struct isapnp_device *isapnp ) {
253         isapnp_device_activation ( isapnp, 0 );
254 }
255
256 /**
257  * Set ISAPnP driver-private data
258  *
259  * @v isapnp            ISAPnP device
260  * @v priv              Private data
261  */
262 static inline void isapnp_set_drvdata ( struct isapnp_device *isapnp,
263                                         void *priv ) {
264         isapnp->priv = priv;
265 }
266
267 /**
268  * Get ISAPnP driver-private data
269  *
270  * @v isapnp            ISAPnP device
271  * @ret priv            Private data
272  */
273 static inline void * isapnp_get_drvdata ( struct isapnp_device *isapnp ) {
274         return isapnp->priv;
275 }
276
277 #endif /* ISAPNP_H */