AquilaOS documentation
How it works, and its code
Toggle main menu visibility
Loading...
Searching...
No Matches
conf1.c
Go to the documentation of this file.
1
10
11
#include <
core/system.h
>
12
#include <
dev/pci.h
>
13
#include <
cpu/io.h
>
14
15
#define PCI_CONFIG_ADDRESS 0x00
16
#define PCI_CONFIG_DATA 0x04
17
19
union
pci_address
{
20
struct
{
21
uint8_t
reg
: 8;
22
uint8_t
function
: 3;
23
uint8_t
device
: 5;
24
uint8_t
bus
: 8;
25
uint8_t
reserved
: 7;
26
uint8_t
enable
: 1;
27
}
structure
;
28
uint32_t
raw
;
29
}
__packed
;
30
33
static
void
conf1_select
(
struct
pci_host
*host,
struct
pci_dev
*
dev
,
uint16_t
reg)
34
{
35
union
pci_address
addr;
36
addr.
raw
= 0;
37
38
addr.
structure
.enable = 1;
39
addr.
structure
.bus =
dev
->bus;
40
addr.
structure
.device =
dev
->dev;
41
addr.
structure
.function =
dev
->func;
42
addr.
structure
.reg = reg & 0xfc;
43
44
io_out32
(&host->
config
,
PCI_CONFIG_ADDRESS
, addr.
raw
);
45
}
46
55
uint32_t
pci_conf1_read
(
struct
pci_host
*host,
struct
pci_dev
*
dev
,
uint16_t
reg)
56
{
57
if
(reg > 0xFF)
58
return
0xFFFFFFFF;
59
60
conf1_select
(host,
dev
, reg);
61
return
io_in32
(&host->
config
,
PCI_CONFIG_DATA
);
62
}
63
73
void
pci_conf1_write
(
struct
pci_host
*host,
struct
pci_dev
*
dev
,
uint16_t
reg,
uint32_t
val)
74
{
75
if
(reg > 0xFF)
76
return
;
77
78
conf1_select
(host,
dev
, reg);
79
io_out32
(&host->
config
,
PCI_CONFIG_DATA
, val);
80
}
io_in32
static uint32_t io_in32(struct ioaddr *io, uintptr_t off)
Definition
io.h:38
io_out32
static void io_out32(struct ioaddr *io, uintptr_t off, uint32_t val)
Definition
io.h:54
conf1_select
static void conf1_select(struct pci_host *host, struct pci_dev *dev, uint16_t reg)
Selects register reg of dev (rounded down to 4 bytes), for the next access to CONFIG_DATA.
Definition
conf1.c:33
pci_conf1_write
void pci_conf1_write(struct pci_host *host, struct pci_dev *dev, uint16_t reg, uint32_t val)
Writes a 32-bit register of a function's configuration space.
Definition
conf1.c:73
pci_conf1_read
uint32_t pci_conf1_read(struct pci_host *host, struct pci_dev *dev, uint16_t reg)
Reads a 32-bit register of a function's configuration space.
Definition
conf1.c:55
PCI_CONFIG_ADDRESS
#define PCI_CONFIG_ADDRESS
Definition
conf1.c:15
PCI_CONFIG_DATA
#define PCI_CONFIG_DATA
Definition
conf1.c:16
system.h
__packed
#define __packed
Definition
system.h:30
io.h
pci.h
uint32_t
unsigned int uint32_t
Definition
stddef.h:22
uint8_t
unsigned char uint8_t
Definition
stddef.h:20
uint16_t
unsigned short int uint16_t
Definition
stddef.h:21
dev
A device driver: its operations, any of which may be NULL.
Definition
dev.h:28
pci_address::[struct].structure::enable
uint8_t enable
pci_address::[struct].structure::reserved
uint8_t reserved
pci_address::[struct].structure::reg
uint8_t reg
pci_address::[struct].structure::bus
uint8_t bus
pci_address::[struct].structure::function
uint8_t function
pci_address::[struct].structure::device
uint8_t device
pci_dev
A PCI function: its bus, device (slot) and function numbers.
Definition
pci.h:18
pci_host
The host bridge, which the platform describes (platform_init() sets it): how its configuration space ...
Definition
pci.h:32
pci_host::config
struct ioaddr config
Definition
pci.h:38
pci_address
What is written to CONFIG_ADDRESS: the register to reach.
Definition
conf1.c:19
pci_address::raw
uint32_t raw
Definition
conf1.c:28
pci_address::structure
struct pci_address::@101077010334364201370103200271212236154121237126 structure
kernel
dev
pci
conf1.c
Generated by
1.18.0