MentOS  0.8.0
The Mentoring Operating System
pci.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include "stdint.h"
14 
16 typedef enum {
53 
55 typedef enum {
100 
111 
115 #define PCI_VENDOR_ID 0x00
116 
118 #define PCI_DEVICE_ID 0x02
119 
124 #define PCI_COMMAND 0x04
125 
127 #define PCI_STATUS 0x06
128 
130 #define PCI_REVISION_ID 0x08
131 
134 #define PCI_PROG_IF 0x09
135 
138 #define PCI_SUBCLASS 0x0a
139 
142 #define PCI_CLASS 0x0b
143 
148 #define PCI_CACHE_LINE_SIZE 0x0c
149 
151 #define PCI_LATENCY_TIMER 0x0d
152 
158 #define PCI_HEADER_TYPE 0x0e
159 
161 #define PCI_BIST 0x0f
162 
165 #define PCI_CARDBUS_CIS 0x28
166 
168 #define PCI_SUBSYSTEM_VENDOR_ID 0x2c
169 
171 #define PCI_SUBSYSTEM_ID 0x2e
172 
174 #define PCI_ROM_ADDRESS 0x30
175 
179 #define PCI_CAPABILITY_LIST 0x34
180 
186 #define PCI_INTERRUPT_LINE 0x3c
187 
190 #define PCI_INTERRUPT_PIN 0x3d
191 
194 #define PCI_MIN_GNT 0x3e
195 
198 #define PCI_MAX_LAT 0x3f
199 
201 
208 
209 #define PCI_BASE_ADDRESS_0 0x10
210 #define PCI_BASE_ADDRESS_1 0x14
211 #define PCI_BASE_ADDRESS_2 0x18
212 #define PCI_BASE_ADDRESS_3 0x1c
213 #define PCI_BASE_ADDRESS_4 0x20
214 #define PCI_BASE_ADDRESS_5 0x24
215 
217 
218 #define PCI_PRIMARY_BUS 0x18
219 #define PCI_SECONDARY_BUS 0x19
220 
221 #define PCI_HEADER_TYPE_NORMAL 0
222 #define PCI_HEADER_TYPE_BRIDGE 1
223 #define PCI_HEADER_TYPE_CARDBUS 2
224 
225 #define PCI_TYPE_BRIDGE 0x060400
226 #define PCI_TYPE_SATA 0x010600
227 
228 #define PCI_ADDRESS_PORT 0xCF8
229 #define PCI_VALUE_PORT 0xCFC
230 #define PCI_NONE 0xFFFF
231 
233 typedef void (*pci_scan_func_t)(uint32_t device, uint16_t vendor_id, uint16_t device_id, void *extra);
234 
239 void pci_write_8(uint32_t device, uint32_t field, uint8_t value);
240 
245 void pci_write_16(uint32_t device, uint32_t field, uint16_t value);
246 
251 void pci_write_32(uint32_t device, uint32_t field, uint32_t value);
252 
257 uint8_t pci_read_8(uint32_t device, int field);
258 
263 uint16_t pci_read_16(uint32_t device, int field);
264 
269 uint32_t pci_read_32(uint32_t device, int field);
270 
275 void pci_scan(pci_scan_func_t f, int type, void *extra);
276 
278 void pci_remap(void);
279 
284 
289 void pci_dump_device_data(uint32_t device, uint16_t vendorid, uint16_t deviceid);
290 
292 void pci_debug_scan(void);
293 
void pci_write_32(uint32_t device, uint32_t field, uint32_t value)
Writes a 32bit field to the given PCI device.
void(* pci_scan_func_t)(uint32_t device, uint16_t vendor_id, uint16_t device_id, void *extra)
PIC scan function.
Definition: pci.h:233
uint8_t pci_read_8(uint32_t device, int field)
Reads a 8bit field from the given PCI device.
uint16_t pci_read_16(uint32_t device, int field)
Reads a 16bit field from the given PCI device.
pci_command_bit_t
Types of PCI commands.
Definition: pci.h:16
void pci_write_16(uint32_t device, uint32_t field, uint16_t value)
Writes a 16bit field to the given PCI device.
int pci_get_interrupt(uint32_t device)
Retrieves the interrupt number for the given device.
pci_status_bit_t
Types of PCI status.
Definition: pci.h:55
void pci_debug_scan(void)
Prints all the devices connected to the PCI interfance.
uint32_t pci_read_32(uint32_t device, int field)
Reads a 32bit field from the given PCI device.
void pci_scan(pci_scan_func_t f, int type, void *extra)
Scans for the given type of device.
void pci_remap(void)
PCI-to-ISA remapping.
void pci_write_8(uint32_t device, uint32_t field, uint8_t value)
Writes a 8bit field to the given PCI device.
void pci_dump_device_data(uint32_t device, uint16_t vendorid, uint16_t deviceid)
Dumps on DEBUG, the information about the given device.
@ pci_command_memory_space
If set to 1 the device can respond to Memory Space accesses; otherwise, the device's response is disa...
Definition: pci.h:22
@ pci_command_special_cycles
If set to 1 the device can monitor Special Cycle operations; otherwise, the device will ignore them.
Definition: pci.h:28
@ pci_command_mw_ie
If set to 1 the device can generate the Memory Write and Invalidate command; otherwise,...
Definition: pci.h:31
@ pci_command_fast_bb_enable
If set to 1 indicates a device is allowed to generate fast back-to-back transactions; otherwise,...
Definition: pci.h:48
@ pci_command_parity_error_response
If set to 1 the device will take its normal action when a parity error is detected; otherwise,...
Definition: pci.h:41
@ pci_command_vga_palette_snoop
If set to 1 the device does not respond to palette register writes and will snoop the data; otherwise...
Definition: pci.h:35
@ pci_command_serr_enable
If set to 1 the SERR# driver is enabled; otherwise, the driver is disabled.
Definition: pci.h:44
@ pci_command_io_space
If set to 1 the device can respond to I/O Space accesses; otherwise, the device's response is disable...
Definition: pci.h:19
@ pci_command_bus_master
If set to 1 the device can behave as a bus master; otherwise, the device can not generate PCI accesse...
Definition: pci.h:25
@ pci_command_interrupt_disable
If set to 1 the assertion of the devices INTx# signal is disabled; otherwise, assertion of the signal...
Definition: pci.h:51
@ pci_status_master_data_parity_error
This bit is only set when the following conditions are met. The bus agent asserted PERR# on a read or...
Definition: pci.h:76
@ pci_status_fast_bb_capable
If set to 1 the device can accept fast back-to-back transactions that are not from the same agent; ot...
Definition: pci.h:70
@ pci_status_66_MHz_capable
If set to 1 the device is capable of running at 66 MHz; otherwise, the device runs at 33 MHz.
Definition: pci.h:66
@ pci_status_signalled_system_error
This bit will be set to 1 whenever the device asserts SERR#.
Definition: pci.h:95
@ pci_status_devsel_timing_high
The second bit required to set the devsel.
Definition: pci.h:83
@ pci_status_received_target_abort
This bit will be set to 1, by a master device, whenever its transaction is terminated with Target-Abo...
Definition: pci.h:89
@ pci_status_devsel_timing_low
Read only bits that represent the slowest time that a device will assert DEVSEL# for any bus command ...
Definition: pci.h:81
@ pci_status_received_master_abort
This bit will be set to 1, by a master device, whenever its transaction (except for Special Cycle tra...
Definition: pci.h:93
@ pci_status_detected_parity_error
This bit will be set to 1 whenever the device detects a parity error, even if parity error handling i...
Definition: pci.h:98
@ pci_status_interrupt_status
Represents the state of the device's INTx# signal. If set to 1 and bit 10 of the Command register (In...
Definition: pci.h:59
@ pci_status_capabilities_list
If set to 1 the device implements the pointer for a New Capabilities Linked list at offset 0x34; othe...
Definition: pci.h:63
@ pci_status_signalled_target_abort
This bit will be set to 1 whenever a target device terminates a transaction with Target-Abort.
Definition: pci.h:86
Standard integer data-types.
unsigned short uint16_t
Define the unsigned 16-bit integer.
Definition: stdint.h:24
unsigned int uint32_t
Define the unsigned 32-bit integer.
Definition: stdint.h:18
unsigned char uint8_t
Define the unsigned 8-bit integer.
Definition: stdint.h:30