AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
ecam.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
17static uintptr_t offset(struct pci_dev *dev, uint16_t reg)
18{
19 return (uintptr_t) dev->bus << 20 | (uintptr_t) dev->dev << 15 |
20 (uintptr_t) dev->func << 12 | (reg & 0xFFC);
21}
22
33{
34 uintptr_t off = offset(dev, reg);
35
36 if (off >= host->size)
37 return 0xFFFFFFFF;
38
39 return io_in32(&host->config, off);
40}
41
51void pci_ecam_write(struct pci_host *host, struct pci_dev *dev, uint16_t reg, uint32_t val)
52{
53 uintptr_t off = offset(dev, reg);
54
55 if (off < host->size)
56 io_out32(&host->config, off, val);
57}
static uint32_t io_in32(struct ioaddr *io, uintptr_t off)
Definition io.h:38
static void io_out32(struct ioaddr *io, uintptr_t off, uint32_t val)
Definition io.h:54
void pci_ecam_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 ecam.c:51
uint32_t pci_ecam_read(struct pci_host *host, struct pci_dev *dev, uint16_t reg)
Reads a 32-bit register of a function's configuration space.
Definition ecam.c:32
static uintptr_t offset(struct pci_dev *dev, uint16_t reg)
Returns where register reg of dev is, from the start of the configuration space (the register rounded...
Definition ecam.c:17
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
unsigned int uint32_t
Definition stddef.h:22
unsigned short int uint16_t
Definition stddef.h:21
A device driver: its operations, any of which may be NULL.
Definition dev.h:28
A PCI function: its bus, device (slot) and function numbers.
Definition pci.h:18
The host bridge, which the platform describes (platform_init() sets it): how its configuration space ...
Definition pci.h:32
struct ioaddr config
Definition pci.h:38
size_t size
Definition pci.h:39