2 * Copyright (c) 2014 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
9 * IO space access commands.
17 int pci_map_physmem(phys_addr_t paddr, unsigned long *lenp,
18 struct udevice **devp, void **ptrp)
24 for (uclass_first_device(UCLASS_PCI_EMUL, &dev);
26 uclass_next_device(&dev)) {
27 struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
29 if (!ops || !ops->map_physmem)
31 ret = (ops->map_physmem)(dev, paddr, lenp, ptrp);
38 debug("%s: failed: addr=%x\n", __func__, paddr);
42 int pci_unmap_physmem(const void *vaddr, unsigned long len,
45 struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
47 if (!ops || !ops->unmap_physmem)
49 return (ops->unmap_physmem)(dev, vaddr, len);
52 static int pci_io_read(unsigned int addr, ulong *valuep, pci_size_t size)
57 *valuep = pci_get_ff(size);
58 for (uclass_first_device(UCLASS_PCI_EMUL, &dev);
60 uclass_next_device(&dev)) {
61 struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
63 if (ops && ops->read_io) {
64 ret = (ops->read_io)(dev, addr, valuep, size);
70 debug("%s: failed: addr=%x\n", __func__, addr);
74 static int pci_io_write(unsigned int addr, ulong value, pci_size_t size)
79 for (uclass_first_device(UCLASS_PCI_EMUL, &dev);
81 uclass_next_device(&dev)) {
82 struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
84 if (ops && ops->write_io) {
85 ret = (ops->write_io)(dev, addr, value, size);
91 debug("%s: failed: addr=%x, value=%lx\n", __func__, addr, value);
95 int inl(unsigned int addr)
100 ret = pci_io_read(addr, &value, PCI_SIZE_32);
102 return ret ? 0 : value;
105 int inw(unsigned int addr)
110 ret = pci_io_read(addr, &value, PCI_SIZE_16);
112 return ret ? 0 : value;
115 int inb(unsigned int addr)
120 ret = pci_io_read(addr, &value, PCI_SIZE_8);
122 return ret ? 0 : value;
125 void outl(unsigned int value, unsigned int addr)
127 pci_io_write(addr, value, PCI_SIZE_32);
130 void outw(unsigned int value, unsigned int addr)
132 pci_io_write(addr, value, PCI_SIZE_16);
135 void outb(unsigned int value, unsigned int addr)
137 pci_io_write(addr, value, PCI_SIZE_8);