1 | /** @file
|
---|
2 | * Utility routines for calling the PCI BIOS.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2011-2015 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #include <stdint.h>
|
---|
18 | #include <string.h>
|
---|
19 | #include "biosint.h"
|
---|
20 | #include "inlines.h"
|
---|
21 |
|
---|
22 | /** PCI BIOS functions. */
|
---|
23 | #define PCIBIOS_ID 0xb1
|
---|
24 | #define PCIBIOS_PCI_BIOS_PRESENT 0x01
|
---|
25 | #define PCIBIOS_FIND_PCI_DEVICE 0x02
|
---|
26 | #define PCIBIOS_FIND_CLASS_CODE 0x03
|
---|
27 | #define PCIBIOS_GENERATE_SPECIAL_CYCLE 0x06
|
---|
28 | #define PCIBIOS_READ_CONFIG_BYTE 0x08
|
---|
29 | #define PCIBIOS_READ_CONFIG_WORD 0x09
|
---|
30 | #define PCIBIOS_READ_CONFIG_DWORD 0x0a
|
---|
31 | #define PCIBIOS_WRITE_CONFIG_BYTE 0x0b
|
---|
32 | #define PCIBIOS_WRITE_CONFIG_WORD 0x0c
|
---|
33 | #define PCIBIOS_WRITE_CONFIG_DWORD 0x0d
|
---|
34 | #define PCIBIOS_GET_IRQ_ROUTING_OPTIONS 0x0e
|
---|
35 | #define PCIBIOS_SET_PCI_IRQ 0x0f
|
---|
36 |
|
---|
37 | /** Status codes. */
|
---|
38 | #define SUCCESSFUL 0x00
|
---|
39 | #define FUNC_NOT_SUPPORTED 0x81
|
---|
40 | #define BAD_VENDOR_ID 0x83
|
---|
41 | #define DEVICE_NOT_FOUND 0x86
|
---|
42 | #define BAD_REGISTER_NUMBER 0x87
|
---|
43 | #define SET_FAILED 0x88
|
---|
44 | #define BUFFER_TOO_SMALL 0x89
|
---|
45 |
|
---|
46 |
|
---|
47 | /* Warning: Destroys high bits of ECX. */
|
---|
48 | uint16_t pci_find_class(uint16_t op, uint32_t dev_class, uint16_t start_bdf);
|
---|
49 | #pragma aux pci_find_class = \
|
---|
50 | ".386" \
|
---|
51 | "shl ecx, 16" \
|
---|
52 | "mov cx, dx" \
|
---|
53 | "int 0x1a" \
|
---|
54 | "cmp ah, 0" \
|
---|
55 | "je found" \
|
---|
56 | "mov bx, 0xffff" \
|
---|
57 | "found:" \
|
---|
58 | parm [ax] [cx dx] [si] value [bx];
|
---|
59 |
|
---|
60 | uint16_t pci_find_dev(uint16_t op, uint16_t dev_id, uint16_t ven_id, uint16_t start_bdf);
|
---|
61 | #pragma aux pci_find_dev = \
|
---|
62 | "int 0x1a" \
|
---|
63 | "cmp ah, 0" \
|
---|
64 | "je found" \
|
---|
65 | "mov bx, 0xffff" \
|
---|
66 | "found:" \
|
---|
67 | parm [ax] [cx] [dx] [si] value [bx];
|
---|
68 |
|
---|
69 | uint8_t pci_read_cfgb(uint16_t op, uint16_t bus_dev_fn, uint16_t reg);
|
---|
70 | #pragma aux pci_read_cfgb = \
|
---|
71 | "int 0x1a" \
|
---|
72 | parm [ax] [bx] [di] value [cl];
|
---|
73 |
|
---|
74 | uint16_t pci_read_cfgw(uint16_t op, uint16_t bus_dev_fn, uint16_t reg);
|
---|
75 | #pragma aux pci_read_cfgw = \
|
---|
76 | "int 0x1a" \
|
---|
77 | parm [ax] [bx] [di] value [cx];
|
---|
78 |
|
---|
79 | /* Warning: Destroys high bits of ECX. */
|
---|
80 | uint32_t pci_read_cfgd(uint16_t op, uint16_t bus_dev_fn, uint16_t reg);
|
---|
81 | #pragma aux pci_read_cfgd = \
|
---|
82 | ".386" \
|
---|
83 | "int 0x1a" \
|
---|
84 | "mov ax, cx" \
|
---|
85 | "shr ecx, 16" \
|
---|
86 | parm [ax] [bx] [di] value [cx ax];
|
---|
87 |
|
---|
88 | uint8_t pci_write_cfgb(uint16_t op, uint16_t bus_dev_fn, uint16_t reg, uint8_t val);
|
---|
89 | #pragma aux pci_write_cfgb = \
|
---|
90 | "int 0x1a" \
|
---|
91 | parm [ax] [bx] [di] [cl];
|
---|
92 |
|
---|
93 | uint8_t pci_write_cfgw(uint16_t op, uint16_t bus_dev_fn, uint16_t reg, uint16_t val);
|
---|
94 | #pragma aux pci_write_cfgw = \
|
---|
95 | "int 0x1a" \
|
---|
96 | parm [ax] [bx] [di] [cx];
|
---|
97 |
|
---|
98 | /* Warning: Destroys high bits of ECX. */
|
---|
99 | uint8_t pci_write_cfgd(uint16_t op, uint16_t bus_dev_fn, uint16_t reg, uint32_t val);
|
---|
100 | #pragma aux pci_write_cfgd = \
|
---|
101 | ".386" \
|
---|
102 | "xchg cx, dx" \
|
---|
103 | "shl ecx, 16" \
|
---|
104 | "mov cx, dx" \
|
---|
105 | "int 0x1a" \
|
---|
106 | parm [ax] [bx] [di] [dx cx];
|
---|
107 |
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Returns the bus/device/function of a PCI device with
|
---|
111 | * the given class code.
|
---|
112 | *
|
---|
113 | * @returns bus/device/fn in a 16-bit integer where
|
---|
114 | * where the upper byte contains the bus number
|
---|
115 | * and lower one the device and function number.
|
---|
116 | * VBOX_AHCI_NO_DEVICE if no device was found.
|
---|
117 | * @param dev_class The PCI class code to search for.
|
---|
118 | */
|
---|
119 | uint16_t pci_find_classcode(uint32_t dev_class)
|
---|
120 | {
|
---|
121 | return pci_find_class((PCIBIOS_ID << 8) | PCIBIOS_FIND_CLASS_CODE, dev_class, 0);
|
---|
122 | }
|
---|
123 |
|
---|
124 | uint32_t pci_read_config_byte(uint8_t bus, uint8_t dev_fn, uint8_t reg)
|
---|
125 | {
|
---|
126 | return pci_read_cfgb((PCIBIOS_ID << 8) | PCIBIOS_READ_CONFIG_BYTE, (bus << 8) | dev_fn, reg);
|
---|
127 | }
|
---|
128 |
|
---|
129 | uint32_t pci_read_config_word(uint8_t bus, uint8_t dev_fn, uint8_t reg)
|
---|
130 | {
|
---|
131 | return pci_read_cfgw((PCIBIOS_ID << 8) | PCIBIOS_READ_CONFIG_WORD, (bus << 8) | dev_fn, reg);
|
---|
132 | }
|
---|
133 |
|
---|
134 | uint32_t pci_read_config_dword(uint8_t bus, uint8_t dev_fn, uint8_t reg)
|
---|
135 | {
|
---|
136 | return pci_read_cfgd((PCIBIOS_ID << 8) | PCIBIOS_READ_CONFIG_DWORD, (bus << 8) | dev_fn, reg);
|
---|
137 | }
|
---|
138 |
|
---|
139 | #if 0 /* Disabled to save space because they are not needed. Might become useful in the future. */
|
---|
140 | /**
|
---|
141 | * Returns the bus/device/function of a PCI device with
|
---|
142 | * the given vendor and device id.
|
---|
143 | *
|
---|
144 | * @returns bus/device/fn in one 16bit integer where
|
---|
145 | * where the upper byte contains the bus number
|
---|
146 | * and lower one the device and function number.
|
---|
147 | * VBOX_AHCI_NO_DEVICE if no device was found.
|
---|
148 | * @param u16Vendor The vendor ID.
|
---|
149 | * @param u16Device The device ID.
|
---|
150 | */
|
---|
151 | uint16_t pci_find_device(uint16_t v_id, uint16_t d_id)
|
---|
152 | {
|
---|
153 | return pci_find_dev((PCIBIOS_ID << 8) | PCIBIOS_FIND_PCI_DEVICE, v_id, d_id, 0);
|
---|
154 | }
|
---|
155 |
|
---|
156 | void pci_write_config_byte(uint8_t bus, uint8_t dev_fn, uint8_t reg, uint8_t val)
|
---|
157 | {
|
---|
158 | pci_write_cfgb((PCIBIOS_ID << 8) | PCIBIOS_WRITE_CONFIG_BYTE, (bus << 8) | dev_fn, reg, val);
|
---|
159 | }
|
---|
160 |
|
---|
161 | void pci_write_config_word(uint8_t bus, uint8_t dev_fn, uint8_t reg, uint16_t val)
|
---|
162 | {
|
---|
163 | pci_write_cfgw((PCIBIOS_ID << 8) | PCIBIOS_WRITE_CONFIG_WORD, (bus << 8) | dev_fn, reg, val);
|
---|
164 | }
|
---|
165 |
|
---|
166 | void pci_write_config_dword(uint8_t bus, uint8_t dev_fn, uint8_t reg, uint32_t val)
|
---|
167 | {
|
---|
168 | pci_write_cfgd((PCIBIOS_ID << 8) | PCIBIOS_WRITE_CONFIG_DWORD, (bus << 8) | dev_fn, reg, val);
|
---|
169 | }
|
---|
170 | #endif /* 0 */
|
---|