1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2014 Google, Inc
* Written by Simon Glass <sjg@chromium.org>
*/
/*
* IO space access commands.
*/
#define LOG_CATEGORY UCLASS_PCI
#include <command.h>
#include <dm.h>
#include <log.h>
#include <asm/io.h>
int pci_map_physmem(phys_addr_t paddr, unsigned long *lenp,
struct udevice **devp, void **ptrp)
{
struct udevice *dev;
int ret;
*ptrp = 0;
for (uclass_first_device(UCLASS_PCI_EMUL, &dev);
dev;
uclass_next_device(&dev)) {
struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
if (!ops || !ops->map_physmem)
continue;
ret = (ops->map_physmem)(dev, paddr, lenp, ptrp);
if (ret)
continue;
*devp = dev;
log_debug("addr=%lx, dev=%s\n", (ulong)paddr, dev->name);
return 0;
}
log_debug("%s: failed: addr=%pap\n", __func__, &paddr);
return -ENOSYS;
}
int pci_unmap_physmem(const void *vaddr, unsigned long len,
struct udevice *dev)
{
struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
if (!ops || !ops->unmap_physmem)
return -ENOSYS;
return (ops->unmap_physmem)(dev, vaddr, len);
}
static int pci_io_read(unsigned int addr, ulong *valuep, pci_size_t size)
{
struct udevice *dev;
int ret;
*valuep = pci_get_ff(size);
for (uclass_first_device(UCLASS_PCI_EMUL, &dev);
dev;
uclass_next_device(&dev)) {
struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
if (ops && ops->read_io) {
ret = (ops->read_io)(dev, addr, valuep, size);
if (!ret)
return 0;
}
}
log_debug("%s: failed: addr=%x\n", __func__, addr);
return -ENOSYS;
}
static int pci_io_write(unsigned int addr, ulong value, pci_size_t size)
{
struct udevice *dev;
int ret;
for (uclass_first_device(UCLASS_PCI_EMUL, &dev);
dev;
uclass_next_device(&dev)) {
struct dm_pci_emul_ops *ops = pci_get_emul_ops(dev);
if (ops && ops->write_io) {
ret = (ops->write_io)(dev, addr, value, size);
if (!ret)
return 0;
}
}
log_debug("%s: failed: addr=%x, value=%lx\n", __func__, addr, value);
return -ENOSYS;
}
int _inl(unsigned int addr)
{
unsigned long value;
int ret;
ret = pci_io_read(addr, &value, PCI_SIZE_32);
return ret ? 0 : value;
}
int _inw(unsigned int addr)
{
unsigned long value;
int ret;
ret = pci_io_read(addr, &value, PCI_SIZE_16);
return ret ? 0 : value;
}
int _inb(unsigned int addr)
{
unsigned long value;
int ret;
ret = pci_io_read(addr, &value, PCI_SIZE_8);
return ret ? 0 : value;
}
void _outl(unsigned int value, unsigned int addr)
{
pci_io_write(addr, value, PCI_SIZE_32);
}
void _outw(unsigned int value, unsigned int addr)
{
pci_io_write(addr, value, PCI_SIZE_16);
}
void _outb(unsigned int value, unsigned int addr)
{
pci_io_write(addr, value, PCI_SIZE_8);
}
|