Add native memset() function on x86
[coreboot.git] / src / arch / x86 / lib / pci_ops_mmconf.c
1 #include <console/console.h>
2 #include <arch/io.h>
3 #include <arch/pciconf.h>
4 #include <device/pci.h>
5 #include <device/pci_ids.h>
6 #include <device/pci_ops.h>
7
8 /*
9  * Functions for accessing PCI configuration space with mmconf accesses
10  */
11
12 #define PCI_MMIO_ADDR(SEGBUS, DEVFN, WHERE)     \
13                                 (CONFIG_MMCONF_BASE_ADDRESS |\
14                                 (((SEGBUS) & 0xFFF) << 20) |\
15                                 (((DEVFN) & 0xFF) << 12) |\
16                                 ((WHERE) & 0xFFF))
17
18 #include <arch/mmio_conf.h>
19
20 static uint8_t pci_mmconf_read_config8(struct bus *pbus, int bus, int devfn,
21                                        int where)
22 {
23         return (read8x(PCI_MMIO_ADDR(bus, devfn, where)));
24 }
25
26 static uint16_t pci_mmconf_read_config16(struct bus *pbus, int bus, int devfn,
27                                          int where)
28 {
29         return (read16x(PCI_MMIO_ADDR(bus, devfn, where) & ~1));
30 }
31
32 static uint32_t pci_mmconf_read_config32(struct bus *pbus, int bus, int devfn,
33                                          int where)
34 {
35         return (read32x(PCI_MMIO_ADDR(bus, devfn, where) & ~3));
36 }
37
38 static void pci_mmconf_write_config8(struct bus *pbus, int bus, int devfn,
39                                      int where, uint8_t value)
40 {
41         write8x(PCI_MMIO_ADDR(bus, devfn, where), value);
42 }
43
44 static void pci_mmconf_write_config16(struct bus *pbus, int bus, int devfn,
45                                       int where, uint16_t value)
46 {
47         write16x(PCI_MMIO_ADDR(bus, devfn, where) & ~1, value);
48 }
49
50 static void pci_mmconf_write_config32(struct bus *pbus, int bus, int devfn,
51                                       int where, uint32_t value)
52 {
53         write32x(PCI_MMIO_ADDR(bus, devfn, where) & ~3, value);
54 }
55
56 const struct pci_bus_operations pci_ops_mmconf = {
57         .read8 = pci_mmconf_read_config8,
58         .read16 = pci_mmconf_read_config16,
59         .read32 = pci_mmconf_read_config32,
60         .write8 = pci_mmconf_write_config8,
61         .write16 = pci_mmconf_write_config16,
62         .write32 = pci_mmconf_write_config32,
63 };