Coverage Report

Created: 2026-03-11 06:21

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