1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2014 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
8 * IO space access commands.
16 int pci_map_physmem(phys_addr_t paddr, unsigned long *lenp,
17 struct udevice **devp, void **ptrp)
23 for (uclass_first_device(UCLASS_PCI_EMUL, &dev);
25 uclass_next_device(&dev)) {
26 struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
28 if (!ops || !ops->map_physmem)
30 ret = (ops->map_physmem)(dev, paddr, lenp, ptrp);
37 debug("%s: failed: addr=%x\n", __func__, paddr);
41 int pci_unmap_physmem(const void *vaddr, unsigned long len,
44 struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
46 if (!ops || !ops->unmap_physmem)
48 return (ops->unmap_physmem)(dev, vaddr, len);
51 static int pci_io_read(unsigned int addr, ulong *valuep, pci_size_t size)
56 *valuep = pci_get_ff(size);
57 for (uclass_first_device(UCLASS_PCI_EMUL, &dev);
59 uclass_next_device(&dev)) {
60 struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
62 if (ops && ops->read_io) {
63 ret = (ops->read_io)(dev, addr, valuep, size);
69 debug("%s: failed: addr=%x\n", __func__, addr);
73 static int pci_io_write(unsigned int addr, ulong value, pci_size_t size)
78 for (uclass_first_device(UCLASS_PCI_EMUL, &dev);
80 uclass_next_device(&dev)) {
81 struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
83 if (ops && ops->write_io) {
84 ret = (ops->write_io)(dev, addr, value, size);
90 debug("%s: failed: addr=%x, value=%lx\n", __func__, addr, value);
94 int inl(unsigned int addr)
99 ret = pci_io_read(addr, &value, PCI_SIZE_32);
101 return ret ? 0 : value;
104 int inw(unsigned int addr)
109 ret = pci_io_read(addr, &value, PCI_SIZE_16);
111 return ret ? 0 : value;
114 int inb(unsigned int addr)
119 ret = pci_io_read(addr, &value, PCI_SIZE_8);
121 return ret ? 0 : value;
124 void outl(unsigned int value, unsigned int addr)
126 pci_io_write(addr, value, PCI_SIZE_32);
129 void outw(unsigned int value, unsigned int addr)
131 pci_io_write(addr, value, PCI_SIZE_16);
134 void outb(unsigned int value, unsigned int addr)
136 pci_io_write(addr, value, PCI_SIZE_8);