Import a good chunk of the PNP code from FreeBSD-5.x
[dragonfly.git] / sys / i386 / include / pc / bios.h
1 /*-
2  * Copyright (c) 1997 Michael Smith
3  * Copyright (c) 1998 Jonathan Lemon
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD: src/sys/i386/include/pc/bios.h,v 1.7.2.3 2001/10/21 03:16:56 yokota Exp $
28  * $DragonFly: src/sys/i386/include/pc/Attic/bios.h,v 1.3 2003/11/08 02:55:19 dillon Exp $
29  */
30
31 /* 
32  * Signature structure for the BIOS32 Service Directory header 
33  */
34 struct bios32_SDheader 
35 {
36     u_int8_t    sig[4];
37     u_int32_t   entry;
38     u_int8_t    revision;
39     u_int8_t    len;
40     u_int8_t    cksum;
41     u_int8_t    pad[5];
42 };
43
44 /* 
45  * BIOS32 Service Directory entry.  Caller supplies name, bios32_SDlookup
46  * fills in the rest of the details.
47  */
48 struct bios32_SDentry 
49 {
50     union 
51     {
52         u_int8_t        name[4];        /* service identifier */
53         u_int32_t       id;             /* as a 32-bit value */
54     } ident;
55     u_int32_t   base;                   /* base of service */
56     u_int32_t   len;                    /* service length */
57     u_int32_t   entry;                  /* entrypoint offset from base */
58     vm_offset_t ventry;                 /* entrypoint in kernel virtual segment */
59 };
60
61 extern int              bios32_SDlookup(struct bios32_SDentry *ent);
62 extern u_int32_t        bios_sigsearch(u_int32_t start, u_char *sig, int siglen, 
63                                          int paralen, int sigofs);
64
65 #define BIOS_PADDRTOVADDR(x)    (((x) - ISA_HOLE_START) + atdevbase)
66 #define BIOS_VADDRTOPADDR(x)    (((x) - atdevbase) + ISA_HOLE_START)
67
68
69 /* 
70  * PnP BIOS presence structure
71  */
72 struct PnPBIOS_table 
73 {
74     u_int8_t    sig[4];                 /* "$PnP */
75     u_int8_t    version;                /* should be 0x10 */
76     u_int8_t    len;                    /* total structure length */
77     u_int16_t   control;                /* BIOS feature flags */
78     u_int8_t    cksum;                  /* checksum */
79     u_int32_t   evflagaddr;             /* address of event notificaton flag */
80     u_int16_t   rmentryoffset;          /* real-mode entry offset */
81     u_int16_t   rmentryseg;             /*                 segment */
82     u_int16_t   pmentryoffset;          /* protected-mode entry offset */
83     u_int32_t   pmentrybase;            /*                segment base */
84     u_int32_t   oemdevid;               /* motherboard EISA ID */
85     u_int16_t   rmbiosseg;              /* real-mode BIOS segment */
86     u_int32_t   pmdataseg;              /* protected-mode data segment */
87 } __attribute__ ((packed));
88
89
90 /* 
91  * Exported lookup results 
92  */
93 extern struct bios32_SDentry    PCIbios;
94 extern struct PnPBIOS_table     *PnPBIOStable;
95
96 struct segment_info {
97         u_int   base;
98         u_int   limit;
99 };
100
101 #define BIOSCODE_FLAG   0x01
102 #define BIOSDATA_FLAG   0x02
103 #define BIOSUTIL_FLAG   0x04
104 #define BIOSARGS_FLAG   0x08
105
106 struct bios_segments {
107         struct  segment_info code32;            /* 32-bit code (mandatory) */
108         struct  segment_info code16;            /* 16-bit code */
109         struct  segment_info data;              /* 16-bit data */
110         struct  segment_info util;              /* 16-bit utility */
111         struct  segment_info args;              /* 16-bit args */
112 };
113
114 struct bios_regs {
115         u_int   eax;
116         u_int   ebx;
117         u_int   ecx;
118         u_int   edx;
119         u_int   esi;
120         u_int   edi;
121 };
122
123 struct bios_args {
124         u_int   entry;                          /* entry point of routine */
125         struct  bios_regs r;
126         struct  bios_segments seg;
127 };
128
129 /*
130  * PnP BIOS return codes
131  */
132 #define PNP_SUCCESS                             0x00
133 #define PNP_NOT_SET_STATICALLY                  0x7f
134 #define PNP_UNKNOWN_FUNCTION                    0x81
135 #define PNP_FUNTION_NOT_SUPPORTED               0x82
136 #define PNP_INVALID_HANDLE                      0x83
137 #define PNP_BAD_PARAMETER                       0x84
138 #define PNP_SET_FAILED                          0x85
139 #define PNP_EVENTS_NOT_PENDING                  0x86
140 #define PNP_SYSTEM_NOT_DOCKED                   0x87
141 #define PNP_NO_ISA_PNP_CARDS                    0x88
142 #define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89
143 #define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY     0x8a
144 #define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b
145 #define PNP_BUFFER_TOO_SMALL                    0x8c
146 #define PNP_USE_ESCD_SUPPORT                    0x8d
147 #define PNP_MESSAGE_NOT_SUPPORTED               0x8e
148 #define PNP_HARDWARE_ERROR                      0x8f
149
150 /*
151  * DMI return codes
152  */
153 #define DMI_SUCCESS                             0x00
154 #define DMI_UNKNOWN_FUNCTION                    0x81
155 #define DMI_FUNCTION_NOT_SUPPORTED              0x82
156 #define DMI_INVALID_HANDLE                      0x83
157 #define DMI_BAD_PARAMETER                       0x84
158 #define DMI_INVALID_SUBFUNCTION                 0x85
159 #define DMI_NO_CHANGE                           0x86
160 #define DMI_ADD_STRUCTURE_FAILED                0x87
161 #define DMI_READ_ONLY                           0x8d
162 #define DMI_LOCK_NOT_SUPPORTED                  0x90
163 #define DMI_CURRENTLY_LOCKED                    0x91
164 #define DMI_INVALID_LOCK                        0x92
165
166 /*
167  * format specifiers and defines for bios16()
168  *     s        = short (16 bits)
169  *     i        = int (32 bits)
170  *     p        = pointer (converted to seg:offset)
171  *     C,D,U    = selector (corresponding to code/data/utility segment)
172  *
173  * GetDevNodes(0x01, nodenumptr, nodebuf, control, biossel)
174  *
175  *      Required.  if *nodenumptr is 0 the system bios will return the
176  *      first node.  On return *nodenumptr will contain the next node
177  *      number or 0xFFh if no more nodes exist.
178  *
179  *      Control flag: bit 1: do not get info for how the device will be
180  *                           configured for the next boot.
181  *                    bit 0: do not get info on how the device is configured
182  *                           right now.
183  *                    bit 0 or bit 1 must be set. 0 is illegal, both are
184  *                           illegal.
185  *
186  *      Returns %ax 0 if success, !0 if an error (bit 7 set) or warning
187  *      occured.
188  */
189 #define PNP_COUNT_DEVNODES      "sppD",         0x00
190 #define PNP_GET_DEVNODE         "sppsD",        0x01
191 #define PNP_SET_DEVNODE         "sspsD",        0x02
192 #define PNP_GET_EVENT           "spD",          0x03
193 #define PNP_SEND_MSG            "ssD",          0x04
194 #define PNP_GET_DOCK_INFO       "spD",          0x05
195
196 #define PNP_SEL_PRIBOOT         "ssiiisspD",    0x07
197 #define PNP_GET_PRIBOOT         "sspppppD",     0x08
198 #define PNP_SET_RESINFO         "spD",          0x09
199 #define PNP_GET_RESINFO         "spD",          0x0A
200 #define PNP_GET_APM_ID          "sppD",         0x0B
201
202 #define PNP_GET_ISA_INFO        "spD",          0x40
203 #define PNP_GET_ECSD_INFO       "spppD",        0x41
204 #define PNP_READ_ESCD           "spUD",         0x42
205 #define PNP_WRITE_ESCD          "spUD",         0x43
206
207 #define PNP_GET_DMI_INFO        "spppppD",      0x50
208 #define PNP_GET_DMI_STRUCTURE   "sppUD",        0x51
209 #define PNP_SET_DMI_STRUCTURE   "sppsUD"        0x52
210 #define PNP_GET_DMI_CHANGE      "spUD"          0x53
211 #define PNP_DMI_CONTROL         "sspsUD"        0x54
212 #define PNP_GET_GPNV_INFO       "sppppD"        0x55
213 #define PNP_READ_GPNV_DATA      "ssppUD"        0x56
214 #define PNP_WRITE_GPNV_DATA     "sspsUD"        0x57
215
216 #define PNP_BOOT_CHECK          "sp",           0x60
217 #define PNP_COUNT_IPL           "sppp",         0x61
218 #define PNP_GET_BOOTPRI         "spp",          0x62
219 #define PNP_SET_BOOTPRI         "sp",           0x63
220 #define PNP_GET_LASTBOOT        "sp",           0x64
221 #define PNP_GET_BOOTFIRST       "sp",           0x65
222 #define PNP_SET_BOOTFIRST       "sp",           0x66
223
224 /*
225  * PCI BIOS functions
226  */
227 #define PCIBIOS_BIOS_PRESENT            0xb101
228 #define PCIBIOS_READ_CONFIG_BYTE        0xb108
229 #define PCIBIOS_READ_CONFIG_WORD        0xb109
230 #define PCIBIOS_READ_CONFIG_DWORD       0xb10a
231 #define PCIBIOS_WRITE_CONFIG_BYTE       0xb10b
232 #define PCIBIOS_WRITE_CONFIG_WORD       0xb10c
233 #define PCIBIOS_WRITE_CONFIG_DWORD      0xb10d
234 #define PCIBIOS_GET_IRQ_ROUTING         0xb10e
235 #define PCIBIOS_ROUTE_INTERRUPT         0xb10f
236
237 extern int bios16(struct bios_args *, char *, ...);
238 extern int bios16_call(struct bios_regs *, char *);
239 extern int bios32(struct bios_regs *, u_int, u_short);
240 extern void set_bios_selectors(struct bios_segments *, int);
241
242 /*
243  * PCI interrupt routing table.
244  *
245  * $PIR in the BIOS segment contains a PIR_table
246  * int 1a:b106 returns PIR_table in buffer at es:(e)di 
247  * int 1a:b18e returns PIR_table in buffer at es:(e)di 
248  * int 1a:b406 returns es:di pointing to the BIOS PIR_table
249  */
250 struct PIR_header 
251 {
252     int8_t      ph_signature[4];
253     u_int16_t   ph_version;
254     u_int16_t   ph_length;
255     u_int8_t    ph_router_bus;
256     u_int8_t    ph_router_dev_fn;
257     u_int16_t   ph_pci_irqs;
258     u_int16_t   ph_router_vendor;
259     u_int16_t   ph_router_device;
260     u_int32_t   ph_miniport;
261     u_int8_t    ph_res[11];
262     u_int8_t    ph_checksum;
263 } __attribute__ ((packed));
264
265 struct PIR_intpin 
266 {
267     u_int8_t    link;
268     u_int16_t   irqs;
269 } __attribute__ ((packed));
270
271 struct PIR_entry
272 {
273     u_int8_t            pe_bus;
274     u_int8_t            pe_res1:3;
275     u_int8_t            pe_device:5;
276     struct PIR_intpin   pe_intpin[4];
277     u_int8_t    pe_slot;
278     u_int8_t    pe_res3;
279 } __attribute__ ((packed));
280
281 struct PIR_table 
282 {
283     struct PIR_header   pt_header;
284     struct PIR_entry    pt_entry[0];
285 } __attribute__ ((packed));
286
287 /*
288  * Int 15:E820 'SMAP' structure
289  *
290  * XXX add constants for type
291  */
292 #define SMAP_SIG        0x534D4150                      /* 'SMAP' */
293 struct bios_smap {
294     u_int64_t   base;
295     u_int64_t   length;
296     u_int32_t   type;
297 } __attribute__ ((packed));