1 // PCI BIOS (int 1a/b1) calls
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
11 #include "bregs.h" // struct bregs
12 #include "biosvar.h" // GET_EBDA
14 #define RET_FUNC_NOT_SUPPORTED 0x81
15 #define RET_BAD_VENDOR_ID 0x83
16 #define RET_DEVICE_NOT_FOUND 0x86
17 #define RET_BUFFER_TOO_SMALL 0x89
21 handle_1ab101(struct bregs *regs)
23 regs->al = 0x01; // Flags - "Config Mechanism #1" supported.
24 regs->bx = 0x0210; // PCI version 2.10
25 regs->cl = pci_bdf_to_bus(GET_VAR(CS, MaxBDF) - 1);
26 regs->edx = 0x20494350; // "PCI "
27 // XXX - bochs bios code sets edi to point to 32bit code - but no
28 // reference to this in spec.
29 set_code_success(regs);
34 handle_1ab102(struct bregs *regs)
39 bdf = pci_find_device(regs->dx, regs->cx, bdf+1);
41 set_code_fail(regs, RET_DEVICE_NOT_FOUND);
47 set_code_success(regs);
52 handle_1ab103(struct bregs *regs)
57 bdf = pci_find_classprog(regs->ecx, bdf+1);
59 set_code_fail(regs, RET_DEVICE_NOT_FOUND);
65 set_code_success(regs);
68 // read configuration byte
70 handle_1ab108(struct bregs *regs)
72 regs->cl = pci_config_readb(regs->bx, regs->di);
73 set_code_success(regs);
76 // read configuration word
78 handle_1ab109(struct bregs *regs)
80 regs->cx = pci_config_readw(regs->bx, regs->di);
81 set_code_success(regs);
84 // read configuration dword
86 handle_1ab10a(struct bregs *regs)
88 regs->ecx = pci_config_readl(regs->bx, regs->di);
89 set_code_success(regs);
92 // write configuration byte
94 handle_1ab10b(struct bregs *regs)
96 pci_config_writeb(regs->bx, regs->di, regs->cl);
97 set_code_success(regs);
100 // write configuration word
102 handle_1ab10c(struct bregs *regs)
104 pci_config_writew(regs->bx, regs->di, regs->cx);
105 set_code_success(regs);
108 // write configuration dword
110 handle_1ab10d(struct bregs *regs)
112 pci_config_writel(regs->bx, regs->di, regs->ecx);
113 set_code_success(regs);
116 // get irq routing options
118 handle_1ab10e(struct bregs *regs)
120 struct pir_header *pirtable_far = GET_EBDA(pir_loc);
121 if (! pirtable_far) {
122 set_code_fail(regs, RET_FUNC_NOT_SUPPORTED);
126 // Validate and update size.
127 u16 size = GET_FARVAR(regs->es, *(u16*)(regs->di+0));
128 u16 pirsize = (GET_FARPTR(pirtable_far->size)
129 - sizeof(struct pir_header));
130 SET_FARVAR(regs->es, *(u16*)(regs->di+0), pirsize);
131 if (size < pirsize) {
132 set_code_fail(regs, RET_BUFFER_TOO_SMALL);
137 u16 d = (GET_FARVAR(regs->es, *(u16*)(regs->di+2)) + 0);
138 u16 destseg = GET_FARVAR(regs->es, *(u16*)(regs->di+4));
140 // Memcpy pir table slots to dest buffer.
141 memcpy_far(MAKE_FARPTR(destseg, d), pirtable_far, pirsize);
143 // XXX - bochs bios sets bx to (1 << 9) | (1 << 11)
144 regs->bx = GET_FARPTR(pirtable_far->exclusive_irqs);
145 set_code_success(regs);
149 handle_1ab1XX(struct bregs *regs)
151 set_code_fail(regs, RET_FUNC_NOT_SUPPORTED);
155 handle_1ab1(struct bregs *regs)
159 if (! CONFIG_PCIBIOS) {
165 case 0x01: handle_1ab101(regs); break;
166 case 0x02: handle_1ab102(regs); break;
167 case 0x03: handle_1ab103(regs); break;
168 case 0x08: handle_1ab108(regs); break;
169 case 0x09: handle_1ab109(regs); break;
170 case 0x0a: handle_1ab10a(regs); break;
171 case 0x0b: handle_1ab10b(regs); break;
172 case 0x0c: handle_1ab10c(regs); break;
173 case 0x0d: handle_1ab10d(regs); break;
174 case 0x0e: handle_1ab10e(regs); break;
175 default: handle_1ab1XX(regs); break;