Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 2 | /* |
| 3 | * PCI emulation device which swaps the case of text |
| 4 | * |
| 5 | * Copyright (c) 2014 Google, Inc |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | 07a3b23 | 2015-05-04 11:31:08 -0600 | [diff] [blame] | 10 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 12 | #include <pci.h> |
| 13 | #include <asm/test.h> |
| 14 | #include <linux/ctype.h> |
| 15 | |
| 16 | /** |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 17 | * struct swap_case_plat - platform data for this device |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 18 | * |
| 19 | * @command: Current PCI command value |
| 20 | * @bar: Current base address values |
| 21 | */ |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 22 | struct swap_case_plat { |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 23 | u16 command; |
Simon Glass | ff7dd58 | 2018-06-12 00:05:02 -0600 | [diff] [blame] | 24 | u32 bar[6]; |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 25 | }; |
| 26 | |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 27 | enum { |
| 28 | MEM_TEXT_SIZE = 0x100, |
| 29 | }; |
| 30 | |
| 31 | enum swap_case_op { |
| 32 | OP_TO_LOWER, |
| 33 | OP_TO_UPPER, |
| 34 | OP_SWAP, |
| 35 | }; |
| 36 | |
| 37 | static struct pci_bar { |
| 38 | int type; |
| 39 | u32 size; |
| 40 | } barinfo[] = { |
| 41 | { PCI_BASE_ADDRESS_SPACE_IO, 1 }, |
| 42 | { PCI_BASE_ADDRESS_MEM_TYPE_32, MEM_TEXT_SIZE }, |
| 43 | { 0, 0 }, |
| 44 | { 0, 0 }, |
| 45 | { 0, 0 }, |
| 46 | { 0, 0 }, |
| 47 | }; |
| 48 | |
| 49 | struct swap_case_priv { |
| 50 | enum swap_case_op op; |
| 51 | char mem_text[MEM_TEXT_SIZE]; |
| 52 | }; |
| 53 | |
Simon Glass | 2a311e8 | 2020-01-27 08:49:37 -0700 | [diff] [blame] | 54 | static int sandbox_swap_case_use_ea(const struct udevice *dev) |
Alex Marginean | f127443 | 2019-06-07 11:24:24 +0300 | [diff] [blame] | 55 | { |
Simon Glass | a7ece58 | 2020-12-19 10:40:14 -0700 | [diff] [blame] | 56 | return !!ofnode_get_property(dev_ofnode(dev), "use-ea", NULL); |
Alex Marginean | f127443 | 2019-06-07 11:24:24 +0300 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /* Please keep these macros in sync with ea_regs below */ |
| 60 | #define PCI_CAP_ID_EA_SIZE (sizeof(ea_regs) + 4) |
| 61 | #define PCI_CAP_ID_EA_ENTRY_CNT 4 |
| 62 | /* Hardcoded EA structure, excluding 1st DW. */ |
| 63 | static const u32 ea_regs[] = { |
| 64 | /* BEI=0, ES=2, BAR0 32b Base + 32b MaxOffset, I/O space */ |
| 65 | (2 << 8) | 2, |
| 66 | PCI_CAP_EA_BASE_LO0, |
| 67 | 0, |
| 68 | /* BEI=1, ES=2, BAR1 32b Base + 32b MaxOffset */ |
| 69 | (1 << 4) | 2, |
| 70 | PCI_CAP_EA_BASE_LO1, |
| 71 | MEM_TEXT_SIZE - 1, |
| 72 | /* BEI=2, ES=3, BAR2 64b Base + 32b MaxOffset */ |
| 73 | (2 << 4) | 3, |
| 74 | PCI_CAP_EA_BASE_LO2 | PCI_EA_IS_64, |
| 75 | PCI_CAP_EA_SIZE_LO, |
| 76 | PCI_CAP_EA_BASE_HI2, |
| 77 | /* BEI=4, ES=4, BAR4 64b Base + 64b MaxOffset */ |
| 78 | (4 << 4) | 4, |
| 79 | PCI_CAP_EA_BASE_LO4 | PCI_EA_IS_64, |
| 80 | PCI_CAP_EA_SIZE_LO | PCI_EA_IS_64, |
| 81 | PCI_CAP_EA_BASE_HI4, |
| 82 | PCI_CAP_EA_SIZE_HI, |
| 83 | }; |
| 84 | |
Simon Glass | 2a311e8 | 2020-01-27 08:49:37 -0700 | [diff] [blame] | 85 | static int sandbox_swap_case_read_ea(const struct udevice *emul, uint offset, |
Alex Marginean | f127443 | 2019-06-07 11:24:24 +0300 | [diff] [blame] | 86 | ulong *valuep, enum pci_size_t size) |
| 87 | { |
| 88 | u32 reg; |
| 89 | |
| 90 | offset = offset - PCI_CAP_ID_EA_OFFSET - 4; |
| 91 | reg = ea_regs[offset >> 2]; |
| 92 | reg >>= (offset % 4) * 8; |
| 93 | |
| 94 | *valuep = reg; |
| 95 | return 0; |
| 96 | } |
| 97 | |
Simon Glass | 2a311e8 | 2020-01-27 08:49:37 -0700 | [diff] [blame] | 98 | static int sandbox_swap_case_read_config(const struct udevice *emul, |
| 99 | uint offset, ulong *valuep, |
| 100 | enum pci_size_t size) |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 101 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 102 | struct swap_case_plat *plat = dev_get_plat(emul); |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 103 | |
Alex Marginean | f127443 | 2019-06-07 11:24:24 +0300 | [diff] [blame] | 104 | /* |
| 105 | * The content of the EA capability structure is handled elsewhere to |
| 106 | * keep the switch/case below sane |
| 107 | */ |
| 108 | if (offset > PCI_CAP_ID_EA_OFFSET + PCI_CAP_LIST_NEXT && |
| 109 | offset < PCI_CAP_ID_EA_OFFSET + PCI_CAP_ID_EA_SIZE) |
| 110 | return sandbox_swap_case_read_ea(emul, offset, valuep, size); |
| 111 | |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 112 | switch (offset) { |
| 113 | case PCI_COMMAND: |
| 114 | *valuep = plat->command; |
| 115 | break; |
| 116 | case PCI_HEADER_TYPE: |
| 117 | *valuep = 0; |
| 118 | break; |
| 119 | case PCI_VENDOR_ID: |
| 120 | *valuep = SANDBOX_PCI_VENDOR_ID; |
| 121 | break; |
| 122 | case PCI_DEVICE_ID: |
Simon Glass | 21c8f1a | 2019-09-25 08:56:01 -0600 | [diff] [blame] | 123 | *valuep = SANDBOX_PCI_SWAP_CASE_EMUL_ID; |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 124 | break; |
| 125 | case PCI_CLASS_DEVICE: |
| 126 | if (size == PCI_SIZE_8) { |
| 127 | *valuep = SANDBOX_PCI_CLASS_SUB_CODE; |
| 128 | } else { |
| 129 | *valuep = (SANDBOX_PCI_CLASS_CODE << 8) | |
| 130 | SANDBOX_PCI_CLASS_SUB_CODE; |
| 131 | } |
| 132 | break; |
| 133 | case PCI_CLASS_CODE: |
| 134 | *valuep = SANDBOX_PCI_CLASS_CODE; |
| 135 | break; |
| 136 | case PCI_BASE_ADDRESS_0: |
| 137 | case PCI_BASE_ADDRESS_1: |
| 138 | case PCI_BASE_ADDRESS_2: |
| 139 | case PCI_BASE_ADDRESS_3: |
| 140 | case PCI_BASE_ADDRESS_4: |
| 141 | case PCI_BASE_ADDRESS_5: { |
| 142 | int barnum; |
Simon Glass | 72231f7 | 2019-09-25 08:56:42 -0600 | [diff] [blame] | 143 | u32 *bar; |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 144 | |
Simon Glass | 130d7ff | 2019-09-25 08:56:06 -0600 | [diff] [blame] | 145 | barnum = pci_offset_to_barnum(offset); |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 146 | bar = &plat->bar[barnum]; |
| 147 | |
Simon Glass | 72231f7 | 2019-09-25 08:56:42 -0600 | [diff] [blame] | 148 | *valuep = sandbox_pci_read_bar(*bar, barinfo[barnum].type, |
| 149 | barinfo[barnum].size); |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 150 | break; |
| 151 | } |
Bin Meng | d74d312 | 2018-08-03 01:14:53 -0700 | [diff] [blame] | 152 | case PCI_CAPABILITY_LIST: |
| 153 | *valuep = PCI_CAP_ID_PM_OFFSET; |
| 154 | break; |
| 155 | case PCI_CAP_ID_PM_OFFSET: |
| 156 | *valuep = (PCI_CAP_ID_EXP_OFFSET << 8) | PCI_CAP_ID_PM; |
| 157 | break; |
Bin Meng | b59b369 | 2018-10-15 02:21:22 -0700 | [diff] [blame] | 158 | case PCI_CAP_ID_PM_OFFSET + PCI_CAP_LIST_NEXT: |
| 159 | *valuep = PCI_CAP_ID_EXP_OFFSET; |
| 160 | break; |
Bin Meng | d74d312 | 2018-08-03 01:14:53 -0700 | [diff] [blame] | 161 | case PCI_CAP_ID_EXP_OFFSET: |
| 162 | *valuep = (PCI_CAP_ID_MSIX_OFFSET << 8) | PCI_CAP_ID_EXP; |
| 163 | break; |
Bin Meng | b59b369 | 2018-10-15 02:21:22 -0700 | [diff] [blame] | 164 | case PCI_CAP_ID_EXP_OFFSET + PCI_CAP_LIST_NEXT: |
| 165 | *valuep = PCI_CAP_ID_MSIX_OFFSET; |
| 166 | break; |
Stephen Carlson | 710862d | 2023-03-10 11:07:14 -0800 | [diff] [blame] | 167 | case PCI_CAP_ID_EXP_OFFSET + PCI_EXP_DEVCAP: |
| 168 | *valuep = PCI_EXP_DEVCAP_PAYLOAD_256B; |
| 169 | break; |
Bin Meng | d74d312 | 2018-08-03 01:14:53 -0700 | [diff] [blame] | 170 | case PCI_CAP_ID_MSIX_OFFSET: |
Alex Marginean | f127443 | 2019-06-07 11:24:24 +0300 | [diff] [blame] | 171 | if (sandbox_swap_case_use_ea(emul)) |
| 172 | *valuep = (PCI_CAP_ID_EA_OFFSET << 8) | PCI_CAP_ID_MSIX; |
| 173 | else |
| 174 | *valuep = PCI_CAP_ID_MSIX; |
Bin Meng | d74d312 | 2018-08-03 01:14:53 -0700 | [diff] [blame] | 175 | break; |
Bin Meng | b59b369 | 2018-10-15 02:21:22 -0700 | [diff] [blame] | 176 | case PCI_CAP_ID_MSIX_OFFSET + PCI_CAP_LIST_NEXT: |
Alex Marginean | f127443 | 2019-06-07 11:24:24 +0300 | [diff] [blame] | 177 | if (sandbox_swap_case_use_ea(emul)) |
| 178 | *valuep = PCI_CAP_ID_EA_OFFSET; |
| 179 | else |
| 180 | *valuep = 0; |
| 181 | break; |
| 182 | case PCI_CAP_ID_EA_OFFSET: |
| 183 | *valuep = (PCI_CAP_ID_EA_ENTRY_CNT << 16) | PCI_CAP_ID_EA; |
| 184 | break; |
| 185 | case PCI_CAP_ID_EA_OFFSET + PCI_CAP_LIST_NEXT: |
Bin Meng | b59b369 | 2018-10-15 02:21:22 -0700 | [diff] [blame] | 186 | *valuep = 0; |
| 187 | break; |
Bin Meng | d74d312 | 2018-08-03 01:14:53 -0700 | [diff] [blame] | 188 | case PCI_EXT_CAP_ID_ERR_OFFSET: |
| 189 | *valuep = (PCI_EXT_CAP_ID_VC_OFFSET << 20) | PCI_EXT_CAP_ID_ERR; |
| 190 | break; |
| 191 | case PCI_EXT_CAP_ID_VC_OFFSET: |
| 192 | *valuep = (PCI_EXT_CAP_ID_DSN_OFFSET << 20) | PCI_EXT_CAP_ID_VC; |
| 193 | break; |
| 194 | case PCI_EXT_CAP_ID_DSN_OFFSET: |
| 195 | *valuep = PCI_EXT_CAP_ID_DSN; |
| 196 | break; |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | static int sandbox_swap_case_write_config(struct udevice *emul, uint offset, |
| 203 | ulong value, enum pci_size_t size) |
| 204 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 205 | struct swap_case_plat *plat = dev_get_plat(emul); |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 206 | |
| 207 | switch (offset) { |
| 208 | case PCI_COMMAND: |
| 209 | plat->command = value; |
| 210 | break; |
| 211 | case PCI_BASE_ADDRESS_0: |
| 212 | case PCI_BASE_ADDRESS_1: { |
| 213 | int barnum; |
| 214 | u32 *bar; |
| 215 | |
Simon Glass | 130d7ff | 2019-09-25 08:56:06 -0600 | [diff] [blame] | 216 | barnum = pci_offset_to_barnum(offset); |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 217 | bar = &plat->bar[barnum]; |
| 218 | |
| 219 | debug("w bar %d=%lx\n", barnum, value); |
| 220 | *bar = value; |
Bin Meng | 5b87baf | 2018-08-03 01:14:40 -0700 | [diff] [blame] | 221 | /* space indicator (bit#0) is read-only */ |
| 222 | *bar |= barinfo[barnum].type; |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 223 | break; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | static int sandbox_swap_case_find_bar(struct udevice *emul, unsigned int addr, |
| 231 | int *barnump, unsigned int *offsetp) |
| 232 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 233 | struct swap_case_plat *plat = dev_get_plat(emul); |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 234 | int barnum; |
| 235 | |
| 236 | for (barnum = 0; barnum < ARRAY_SIZE(barinfo); barnum++) { |
| 237 | unsigned int size = barinfo[barnum].size; |
Bin Meng | 5b87baf | 2018-08-03 01:14:40 -0700 | [diff] [blame] | 238 | u32 base = plat->bar[barnum] & ~PCI_BASE_ADDRESS_SPACE; |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 239 | |
Bin Meng | 5b87baf | 2018-08-03 01:14:40 -0700 | [diff] [blame] | 240 | if (addr >= base && addr < base + size) { |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 241 | *barnump = barnum; |
Bin Meng | 5b87baf | 2018-08-03 01:14:40 -0700 | [diff] [blame] | 242 | *offsetp = addr - base; |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 243 | return 0; |
| 244 | } |
| 245 | } |
| 246 | *barnump = -1; |
| 247 | |
| 248 | return -ENOENT; |
| 249 | } |
| 250 | |
| 251 | static void sandbox_swap_case_do_op(enum swap_case_op op, char *str, int len) |
| 252 | { |
| 253 | for (; len > 0; len--, str++) { |
| 254 | switch (op) { |
| 255 | case OP_TO_UPPER: |
| 256 | *str = toupper(*str); |
| 257 | break; |
| 258 | case OP_TO_LOWER: |
| 259 | *str = tolower(*str); |
| 260 | break; |
| 261 | case OP_SWAP: |
| 262 | if (isupper(*str)) |
| 263 | *str = tolower(*str); |
| 264 | else |
| 265 | *str = toupper(*str); |
| 266 | break; |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
Simon Glass | 81ae778 | 2019-09-25 08:56:03 -0600 | [diff] [blame] | 271 | static int sandbox_swap_case_read_io(struct udevice *dev, unsigned int addr, |
| 272 | ulong *valuep, enum pci_size_t size) |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 273 | { |
| 274 | struct swap_case_priv *priv = dev_get_priv(dev); |
| 275 | unsigned int offset; |
| 276 | int barnum; |
| 277 | int ret; |
| 278 | |
| 279 | ret = sandbox_swap_case_find_bar(dev, addr, &barnum, &offset); |
| 280 | if (ret) |
| 281 | return ret; |
| 282 | |
| 283 | if (barnum == 0 && offset == 0) |
| 284 | *valuep = (*valuep & ~0xff) | priv->op; |
| 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
Simon Glass | 81ae778 | 2019-09-25 08:56:03 -0600 | [diff] [blame] | 289 | static int sandbox_swap_case_write_io(struct udevice *dev, unsigned int addr, |
| 290 | ulong value, enum pci_size_t size) |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 291 | { |
| 292 | struct swap_case_priv *priv = dev_get_priv(dev); |
| 293 | unsigned int offset; |
| 294 | int barnum; |
| 295 | int ret; |
| 296 | |
| 297 | ret = sandbox_swap_case_find_bar(dev, addr, &barnum, &offset); |
| 298 | if (ret) |
| 299 | return ret; |
| 300 | if (barnum == 0 && offset == 0) |
| 301 | priv->op = value; |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
Alex Marginean | f127443 | 2019-06-07 11:24:24 +0300 | [diff] [blame] | 306 | static int pci_ea_bar2_magic = PCI_EA_BAR2_MAGIC; |
Alex Marginean | f127443 | 2019-06-07 11:24:24 +0300 | [diff] [blame] | 307 | |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 308 | static int sandbox_swap_case_map_physmem(struct udevice *dev, |
| 309 | phys_addr_t addr, unsigned long *lenp, void **ptrp) |
| 310 | { |
| 311 | struct swap_case_priv *priv = dev_get_priv(dev); |
| 312 | unsigned int offset, avail; |
| 313 | int barnum; |
| 314 | int ret; |
| 315 | |
Alex Marginean | f127443 | 2019-06-07 11:24:24 +0300 | [diff] [blame] | 316 | if (sandbox_swap_case_use_ea(dev)) { |
| 317 | /* |
| 318 | * only support mapping base address in EA test for now, we |
| 319 | * don't handle mapping an offset inside a BAR. Seems good |
| 320 | * enough for the current test. |
| 321 | */ |
| 322 | switch (addr) { |
| 323 | case (phys_addr_t)PCI_CAP_EA_BASE_LO0: |
| 324 | *ptrp = &priv->op; |
| 325 | *lenp = 4; |
| 326 | break; |
| 327 | case (phys_addr_t)PCI_CAP_EA_BASE_LO1: |
| 328 | *ptrp = priv->mem_text; |
| 329 | *lenp = barinfo[1].size - 1; |
| 330 | break; |
| 331 | case (phys_addr_t)((PCI_CAP_EA_BASE_HI2 << 32) | |
| 332 | PCI_CAP_EA_BASE_LO2): |
| 333 | *ptrp = &pci_ea_bar2_magic; |
| 334 | *lenp = PCI_CAP_EA_SIZE_LO; |
| 335 | break; |
Simon Glass | c40a98c | 2021-07-18 14:14:23 -0600 | [diff] [blame] | 336 | #ifdef CONFIG_HOST_64BIT |
| 337 | /* |
| 338 | * This cannot be work on a 32-bit machine since *lenp is ulong |
| 339 | * which is 32-bits, but it needs to have a 64-bit value |
| 340 | * assigned |
| 341 | */ |
Alex Marginean | f127443 | 2019-06-07 11:24:24 +0300 | [diff] [blame] | 342 | case (phys_addr_t)((PCI_CAP_EA_BASE_HI4 << 32) | |
Simon Glass | c40a98c | 2021-07-18 14:14:23 -0600 | [diff] [blame] | 343 | PCI_CAP_EA_BASE_LO4): { |
| 344 | static int pci_ea_bar4_magic = PCI_EA_BAR4_MAGIC; |
| 345 | |
Alex Marginean | f127443 | 2019-06-07 11:24:24 +0300 | [diff] [blame] | 346 | *ptrp = &pci_ea_bar4_magic; |
| 347 | *lenp = (PCI_CAP_EA_SIZE_HI << 32) | |
| 348 | PCI_CAP_EA_SIZE_LO; |
| 349 | break; |
Simon Glass | c40a98c | 2021-07-18 14:14:23 -0600 | [diff] [blame] | 350 | } |
| 351 | #endif |
Alex Marginean | f127443 | 2019-06-07 11:24:24 +0300 | [diff] [blame] | 352 | default: |
| 353 | return -ENOENT; |
| 354 | } |
| 355 | return 0; |
| 356 | } |
| 357 | |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 358 | ret = sandbox_swap_case_find_bar(dev, addr, &barnum, &offset); |
| 359 | if (ret) |
| 360 | return ret; |
Alex Marginean | f127443 | 2019-06-07 11:24:24 +0300 | [diff] [blame] | 361 | |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 362 | if (barnum == 1) { |
| 363 | *ptrp = priv->mem_text + offset; |
| 364 | avail = barinfo[1].size - offset; |
| 365 | if (avail > barinfo[1].size) |
| 366 | *lenp = 0; |
| 367 | else |
| 368 | *lenp = min(*lenp, (ulong)avail); |
| 369 | |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | return -ENOENT; |
| 374 | } |
| 375 | |
| 376 | static int sandbox_swap_case_unmap_physmem(struct udevice *dev, |
| 377 | const void *vaddr, unsigned long len) |
| 378 | { |
| 379 | struct swap_case_priv *priv = dev_get_priv(dev); |
| 380 | |
| 381 | sandbox_swap_case_do_op(priv->op, (void *)vaddr, len); |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
Simon Glass | 81ae778 | 2019-09-25 08:56:03 -0600 | [diff] [blame] | 386 | static struct dm_pci_emul_ops sandbox_swap_case_emul_ops = { |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 387 | .read_config = sandbox_swap_case_read_config, |
| 388 | .write_config = sandbox_swap_case_write_config, |
| 389 | .read_io = sandbox_swap_case_read_io, |
| 390 | .write_io = sandbox_swap_case_write_io, |
| 391 | .map_physmem = sandbox_swap_case_map_physmem, |
| 392 | .unmap_physmem = sandbox_swap_case_unmap_physmem, |
| 393 | }; |
| 394 | |
| 395 | static const struct udevice_id sandbox_swap_case_ids[] = { |
| 396 | { .compatible = "sandbox,swap-case" }, |
| 397 | { } |
| 398 | }; |
| 399 | |
| 400 | U_BOOT_DRIVER(sandbox_swap_case_emul) = { |
| 401 | .name = "sandbox_swap_case_emul", |
| 402 | .id = UCLASS_PCI_EMUL, |
| 403 | .of_match = sandbox_swap_case_ids, |
| 404 | .ops = &sandbox_swap_case_emul_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 405 | .priv_auto = sizeof(struct swap_case_priv), |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 406 | .plat_auto = sizeof(struct swap_case_plat), |
Simon Glass | 5a822e1 | 2015-03-05 12:25:29 -0700 | [diff] [blame] | 407 | }; |
Bin Meng | c69ae41 | 2018-08-03 01:14:46 -0700 | [diff] [blame] | 408 | |
| 409 | static struct pci_device_id sandbox_swap_case_supported[] = { |
Simon Glass | 21c8f1a | 2019-09-25 08:56:01 -0600 | [diff] [blame] | 410 | { PCI_VDEVICE(SANDBOX, SANDBOX_PCI_SWAP_CASE_EMUL_ID), |
| 411 | SWAP_CASE_DRV_DATA }, |
Bin Meng | c69ae41 | 2018-08-03 01:14:46 -0700 | [diff] [blame] | 412 | {}, |
| 413 | }; |
| 414 | |
| 415 | U_BOOT_PCI_DEVICE(sandbox_swap_case_emul, sandbox_swap_case_supported); |