1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2014 Google, Inc
8 * IO space access commands.
11 #define LOG_CATEGORY UCLASS_PCI
18 int pci_map_physmem(phys_addr_t paddr, unsigned long *lenp,
19 struct udevice **devp, void **ptrp)
25 for (uclass_first_device(UCLASS_PCI_EMUL, &dev);
27 uclass_next_device(&dev)) {
28 struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
30 if (!ops || !ops->map_physmem)
32 ret = (ops->map_physmem)(dev, paddr, lenp, ptrp);
36 log_debug("addr=%lx, dev=%s\n", (ulong)paddr, dev->name);
40 log_debug("%s: failed: addr=%pap\n", __func__, &paddr);
44 int pci_unmap_physmem(const void *vaddr, unsigned long len,
47 struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
49 if (!ops || !ops->unmap_physmem)
51 return (ops->unmap_physmem)(dev, vaddr, len);
54 static int pci_io_read(unsigned int addr, ulong *valuep, pci_size_t size)
59 *valuep = pci_get_ff(size);
60 for (uclass_first_device(UCLASS_PCI_EMUL, &dev);
62 uclass_next_device(&dev)) {
63 struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
65 if (ops && ops->read_io) {
66 ret = (ops->read_io)(dev, addr, valuep, size);
72 log_debug("%s: failed: addr=%x\n", __func__, addr);
76 static int pci_io_write(unsigned int addr, ulong value, pci_size_t size)
81 for (uclass_first_device(UCLASS_PCI_EMUL, &dev);
83 uclass_next_device(&dev)) {
84 struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
86 if (ops && ops->write_io) {
87 ret = (ops->write_io)(dev, addr, value, size);
93 log_debug("%s: failed: addr=%x, value=%lx\n", __func__, addr, value);
97 int _inl(unsigned int addr)
102 ret = pci_io_read(addr, &value, PCI_SIZE_32);
104 return ret ? 0 : value;
107 int _inw(unsigned int addr)
112 ret = pci_io_read(addr, &value, PCI_SIZE_16);
114 return ret ? 0 : value;
117 int _inb(unsigned int addr)
122 ret = pci_io_read(addr, &value, PCI_SIZE_8);
124 return ret ? 0 : value;
127 void _outl(unsigned int value, unsigned int addr)
129 pci_io_write(addr, value, PCI_SIZE_32);
132 void _outw(unsigned int value, unsigned int addr)
134 pci_io_write(addr, value, PCI_SIZE_16);
137 void _outb(unsigned int value, unsigned int addr)
139 pci_io_write(addr, value, PCI_SIZE_8);