1 // Low level ATA disk access
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2002 MandrakeSoft S.A.
6 // This file may be distributed under the terms of the GNU GPLv3 license.
8 #include "types.h" // u32
9 #include "util.h" // handle_1ab1
10 #include "pci.h" // pci_config_readl
13 /****************************************************************
15 ****************************************************************/
38 struct link_info links[4];
45 struct pir_slot slots[6];
46 } PACKED PIR_TABLE VISIBLE16 __attribute__((aligned(16))) = {
49 .signature = 0x52495024, // "$PIR"
51 .size = sizeof(struct pir_table),
52 .router_devfunc = 0x08,
53 .compatible_devid = 0x122e8086,
54 .checksum = 0x37, // XXX - should auto calculate
58 // first slot entry PCI-to-ISA (embedded)
61 {.link = 0x60, .bitmap = 0xdef8}, // INTA#
62 {.link = 0x61, .bitmap = 0xdef8}, // INTB#
63 {.link = 0x62, .bitmap = 0xdef8}, // INTC#
64 {.link = 0x63, .bitmap = 0xdef8}, // INTD#
66 .slot_nr = 0, // embedded
68 // second slot entry: 1st PCI slot
71 {.link = 0x61, .bitmap = 0xdef8}, // INTA#
72 {.link = 0x62, .bitmap = 0xdef8}, // INTB#
73 {.link = 0x63, .bitmap = 0xdef8}, // INTC#
74 {.link = 0x60, .bitmap = 0xdef8}, // INTD#
78 // third slot entry: 2nd PCI slot
81 {.link = 0x62, .bitmap = 0xdef8}, // INTA#
82 {.link = 0x63, .bitmap = 0xdef8}, // INTB#
83 {.link = 0x60, .bitmap = 0xdef8}, // INTC#
84 {.link = 0x61, .bitmap = 0xdef8}, // INTD#
88 // 4th slot entry: 3rd PCI slot
91 {.link = 0x63, .bitmap = 0xdef8}, // INTA#
92 {.link = 0x60, .bitmap = 0xdef8}, // INTB#
93 {.link = 0x61, .bitmap = 0xdef8}, // INTC#
94 {.link = 0x62, .bitmap = 0xdef8}, // INTD#
98 // 5th slot entry: 4rd PCI slot
101 {.link = 0x60, .bitmap = 0xdef8}, // INTA#
102 {.link = 0x61, .bitmap = 0xdef8}, // INTB#
103 {.link = 0x62, .bitmap = 0xdef8}, // INTC#
104 {.link = 0x63, .bitmap = 0xdef8}, // INTD#
108 // 6th slot entry: 5rd PCI slot
111 {.link = 0x61, .bitmap = 0xdef8}, // INTA#
112 {.link = 0x62, .bitmap = 0xdef8}, // INTB#
113 {.link = 0x63, .bitmap = 0xdef8}, // INTC#
114 {.link = 0x60, .bitmap = 0xdef8}, // INTD#
119 #endif // CONFIG_PIRTABLE
123 /****************************************************************
125 ****************************************************************/
127 #define RET_FUNC_NOT_SUPPORTED 0x81
128 #define RET_BAD_VENDOR_ID 0x83
129 #define RET_DEVICE_NOT_FOUND 0x86
130 #define RET_BUFFER_TOO_SMALL 0x89
132 // installation check
134 handle_1ab101(struct bregs *regs)
139 regs->edx = 0x20494350; // "PCI "
140 // XXX - bochs bios code sets edi to point to 32bit code - but no
141 // reference to this in spec.
147 handle_1ab102(struct bregs *regs)
150 int ret = pci_find_device(regs->cx, regs->dx, regs->si, &d);
152 set_code_fail(regs, RET_DEVICE_NOT_FOUND);
157 set_code_success(regs);
162 handle_1ab103(struct bregs *regs)
165 int ret = pci_find_class(regs->ecx, regs->si, &d);
167 set_code_fail(regs, RET_DEVICE_NOT_FOUND);
172 set_code_success(regs);
175 // read configuration byte
177 handle_1ab108(struct bregs *regs)
179 regs->cl = pci_config_readb(pci_bd(regs->bh, regs->bl), regs->di);
180 set_code_success(regs);
183 // read configuration word
185 handle_1ab109(struct bregs *regs)
187 regs->cx = pci_config_readw(pci_bd(regs->bh, regs->bl), regs->di);
188 set_code_success(regs);
191 // read configuration dword
193 handle_1ab10a(struct bregs *regs)
195 regs->ecx = pci_config_readl(pci_bd(regs->bh, regs->bl), regs->di);
196 set_code_success(regs);
199 // write configuration byte
201 handle_1ab10b(struct bregs *regs)
203 pci_config_writeb(pci_bd(regs->bh, regs->bl), regs->di, regs->cl);
204 set_code_success(regs);
207 // write configuration word
209 handle_1ab10c(struct bregs *regs)
211 pci_config_writew(pci_bd(regs->bh, regs->bl), regs->di, regs->cx);
212 set_code_success(regs);
215 // write configuration dword
217 handle_1ab10d(struct bregs *regs)
219 pci_config_writel(pci_bd(regs->bh, regs->bl), regs->di, regs->ecx);
220 set_code_success(regs);
223 // get irq routing options
225 handle_1ab10e(struct bregs *regs)
227 if (! CONFIG_PIRTABLE) {
228 set_code_fail(regs, RET_FUNC_NOT_SUPPORTED);
232 // Validate and update size.
233 u16 size = GET_FARVAR(regs->es, *(u16*)(regs->di+0));
234 u32 pirsize = sizeof(PIR_TABLE.slots);
235 SET_FARVAR(regs->es, *(u16*)(regs->di+0), pirsize);
236 if (size < pirsize) {
237 set_code_fail(regs, RET_BUFFER_TOO_SMALL);
242 u8 *d = (u8*)(GET_FARVAR(regs->es, *(u16*)(regs->di+2)) + 0);
243 u16 destseg = GET_FARVAR(regs->es, *(u16*)(regs->di+4));
245 // Memcpy pir table slots to dest buffer.
246 u8 *p = (u8*)PIR_TABLE.slots;
247 u8 *end = p + pirsize;
248 for (; p<end; p++, d++) {
249 u8 c = GET_VAR(CS, *p);
250 SET_FARVAR(destseg, *d, c);
253 // XXX - bochs bios sets bx to (1 << 9) | (1 << 11)
254 regs->bx = GET_VAR(CS, PIR_TABLE.pir.exclusive_irqs);
255 set_code_success(regs);
259 handle_1ab1XX(struct bregs *regs)
261 set_code_fail(regs, RET_FUNC_NOT_SUPPORTED);
265 handle_1ab1(struct bregs *regs)
269 if (! CONFIG_PCIBIOS) {
275 case 0x01: handle_1ab101(regs); break;
276 case 0x02: handle_1ab102(regs); break;
277 case 0x03: handle_1ab103(regs); break;
278 case 0x08: handle_1ab108(regs); break;
279 case 0x09: handle_1ab109(regs); break;
280 case 0x0a: handle_1ab10a(regs); break;
281 case 0x0b: handle_1ab10b(regs); break;
282 case 0x0c: handle_1ab10c(regs); break;
283 case 0x0d: handle_1ab10d(regs); break;
284 case 0x0e: handle_1ab10e(regs); break;
285 default: handle_1ab1XX(regs); break;