blob: b7180e6e900da624e14758138037fd103009881f [file] [log] [blame]
Chris Metcalff02cbbe2010-11-02 12:05:10 -04001/*
Chris Metcalf398fa5a2011-05-02 15:09:42 -04002 * Copyright 2011 Tilera Corporation. All Rights Reserved.
Chris Metcalff02cbbe2010-11-02 12:05:10 -04003 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
12 * more details.
13 */
14
15#include <linux/kernel.h>
16#include <linux/pci.h>
17#include <linux/delay.h>
18#include <linux/string.h>
19#include <linux/init.h>
20#include <linux/capability.h>
21#include <linux/sched.h>
22#include <linux/errno.h>
Chris Metcalff02cbbe2010-11-02 12:05:10 -040023#include <linux/irq.h>
24#include <linux/io.h>
25#include <linux/uaccess.h>
Chris Metcalf3989efb2011-12-01 11:37:20 -050026#include <linux/export.h>
Chris Metcalff02cbbe2010-11-02 12:05:10 -040027
28#include <asm/processor.h>
29#include <asm/sections.h>
30#include <asm/byteorder.h>
31#include <asm/hv_driver.h>
32#include <hv/drv_pcie_rc_intf.h>
33
34
35/*
36 * Initialization flow and process
37 * -------------------------------
38 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -030039 * This files contains the routines to search for PCI buses,
Chris Metcalff02cbbe2010-11-02 12:05:10 -040040 * enumerate the buses, and configure any attached devices.
41 *
42 * There are two entry points here:
43 * 1) tile_pci_init
44 * This sets up the pci_controller structs, and opens the
45 * FDs to the hypervisor. This is called from setup_arch() early
46 * in the boot process.
47 * 2) pcibios_init
48 * This probes the PCI bus(es) for any attached hardware. It's
49 * called by subsys_initcall. All of the real work is done by the
50 * generic Linux PCI layer.
51 *
52 */
53
Chris Metcalf2be70552013-08-05 15:02:03 -040054static int pci_probe = 1;
55
Chris Metcalff02cbbe2010-11-02 12:05:10 -040056/*
57 * This flag tells if the platform is TILEmpower that needs
58 * special configuration for the PLX switch chip.
59 */
60int __write_once tile_plx_gen1;
61
62static struct pci_controller controllers[TILE_NUM_PCIE];
63static int num_controllers;
Chris Metcalf398fa5a2011-05-02 15:09:42 -040064static int pci_scan_flags[TILE_NUM_PCIE];
Chris Metcalff02cbbe2010-11-02 12:05:10 -040065
66static struct pci_ops tile_cfg_ops;
67
68
69/*
70 * We don't need to worry about the alignment of resources.
71 */
72resource_size_t pcibios_align_resource(void *data, const struct resource *res,
73 resource_size_t size, resource_size_t align)
74{
75 return res->start;
76}
77EXPORT_SYMBOL(pcibios_align_resource);
78
79/*
80 * Open a FD to the hypervisor PCI device.
81 *
82 * controller_id is the controller number, config type is 0 or 1 for
83 * config0 or config1 operations.
84 */
Greg Kroah-Hartmanb881bc42012-12-21 14:06:37 -080085static int tile_pcie_open(int controller_id, int config_type)
Chris Metcalff02cbbe2010-11-02 12:05:10 -040086{
87 char filename[32];
88 int fd;
89
90 sprintf(filename, "pcie/%d/config%d", controller_id, config_type);
91
92 fd = hv_dev_open((HV_VirtAddr)filename, 0);
93
94 return fd;
95}
96
97
98/*
99 * Get the IRQ numbers from the HV and set up the handlers for them.
100 */
Greg Kroah-Hartmanb881bc42012-12-21 14:06:37 -0800101static int tile_init_irqs(int controller_id, struct pci_controller *controller)
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400102{
103 char filename[32];
104 int fd;
105 int ret;
106 int x;
107 struct pcie_rc_config rc_config;
108
109 sprintf(filename, "pcie/%d/ctl", controller_id);
110 fd = hv_dev_open((HV_VirtAddr)filename, 0);
111 if (fd < 0) {
112 pr_err("PCI: hv_dev_open(%s) failed\n", filename);
113 return -1;
114 }
115 ret = hv_dev_pread(fd, 0, (HV_VirtAddr)(&rc_config),
116 sizeof(rc_config), PCIE_RC_CONFIG_MASK_OFF);
117 hv_dev_close(fd);
118 if (ret != sizeof(rc_config)) {
119 pr_err("PCI: wanted %zd bytes, got %d\n",
120 sizeof(rc_config), ret);
121 return -1;
122 }
123 /* Record irq_base so that we can map INTx to IRQ # later. */
124 controller->irq_base = rc_config.intr;
125
126 for (x = 0; x < 4; x++)
127 tile_irq_activate(rc_config.intr + x,
128 TILE_IRQ_HW_CLEAR);
129
130 if (rc_config.plx_gen1)
131 controller->plx_gen1 = 1;
132
133 return 0;
134}
135
136/*
137 * First initialization entry point, called from setup_arch().
138 *
139 * Find valid controllers and fill in pci_controller structs for each
140 * of them.
141 *
142 * Returns the number of controllers discovered.
143 */
Chris Metcalf05ef1b72012-04-25 12:45:26 -0400144int __init tile_pci_init(void)
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400145{
146 int i;
147
Chris Metcalf2be70552013-08-05 15:02:03 -0400148 if (!pci_probe) {
149 pr_info("PCI: disabled by boot argument\n");
150 return 0;
151 }
152
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400153 pr_info("PCI: Searching for controllers...\n");
154
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400155 /* Re-init number of PCIe controllers to support hot-plug feature. */
156 num_controllers = 0;
157
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400158 /* Do any configuration we need before using the PCIe */
159
160 for (i = 0; i < TILE_NUM_PCIE; i++) {
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400161 /*
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400162 * To see whether we need a real config op based on
163 * the results of pcibios_init(), to support PCIe hot-plug.
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400164 */
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400165 if (pci_scan_flags[i] == 0) {
166 int hv_cfg_fd0 = -1;
167 int hv_cfg_fd1 = -1;
168 int hv_mem_fd = -1;
169 char name[32];
170 struct pci_controller *controller;
171
172 /*
173 * Open the fd to the HV. If it fails then this
174 * device doesn't exist.
175 */
176 hv_cfg_fd0 = tile_pcie_open(i, 0);
177 if (hv_cfg_fd0 < 0)
178 continue;
179 hv_cfg_fd1 = tile_pcie_open(i, 1);
180 if (hv_cfg_fd1 < 0) {
181 pr_err("PCI: Couldn't open config fd to HV "
182 "for controller %d\n", i);
183 goto err_cont;
184 }
185
186 sprintf(name, "pcie/%d/mem", i);
187 hv_mem_fd = hv_dev_open((HV_VirtAddr)name, 0);
188 if (hv_mem_fd < 0) {
189 pr_err("PCI: Could not open mem fd to HV!\n");
190 goto err_cont;
191 }
192
193 pr_info("PCI: Found PCI controller #%d\n", i);
194
195 controller = &controllers[i];
196
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400197 controller->index = i;
198 controller->hv_cfg_fd[0] = hv_cfg_fd0;
199 controller->hv_cfg_fd[1] = hv_cfg_fd1;
200 controller->hv_mem_fd = hv_mem_fd;
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400201 controller->last_busno = 0xff;
202 controller->ops = &tile_cfg_ops;
203
204 num_controllers++;
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400205 continue;
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400206
207err_cont:
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400208 if (hv_cfg_fd0 >= 0)
209 hv_dev_close(hv_cfg_fd0);
210 if (hv_cfg_fd1 >= 0)
211 hv_dev_close(hv_cfg_fd1);
212 if (hv_mem_fd >= 0)
213 hv_dev_close(hv_mem_fd);
214 continue;
215 }
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400216 }
217
218 /*
219 * Before using the PCIe, see if we need to do any platform-specific
220 * configuration, such as the PLX switch Gen 1 issue on TILEmpower.
221 */
222 for (i = 0; i < num_controllers; i++) {
223 struct pci_controller *controller = &controllers[i];
224
225 if (controller->plx_gen1)
226 tile_plx_gen1 = 1;
227 }
228
229 return num_controllers;
230}
231
232/*
233 * (pin - 1) converts from the PCI standard's [1:4] convention to
234 * a normal [0:3] range.
235 */
Ralf Baechled5341942011-06-10 15:30:21 +0100236static int tile_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400237{
238 struct pci_controller *controller =
239 (struct pci_controller *)dev->sysdata;
240 return (pin - 1) + controller->irq_base;
241}
242
243
Greg Kroah-Hartmanb881bc42012-12-21 14:06:37 -0800244static void fixup_read_and_payload_sizes(void)
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400245{
246 struct pci_dev *dev = NULL;
247 int smallest_max_payload = 0x1; /* Tile maxes out at 256 bytes. */
248 int max_read_size = 0x2; /* Limit to 512 byte reads. */
249 u16 new_values;
250
251 /* Scan for the smallest maximum payload size. */
Wei Yongjun17a26352012-12-03 08:28:36 -0500252 for_each_pci_dev(dev) {
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400253 u32 devcap;
254 int max_payload;
255
Jiang Liu424ffc92012-07-24 17:20:15 +0800256 if (!pci_is_pcie(dev))
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400257 continue;
258
Jiang Liu424ffc92012-07-24 17:20:15 +0800259 pcie_capability_read_dword(dev, PCI_EXP_DEVCAP, &devcap);
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400260 max_payload = devcap & PCI_EXP_DEVCAP_PAYLOAD;
261 if (max_payload < smallest_max_payload)
262 smallest_max_payload = max_payload;
263 }
264
265 /* Now, set the max_payload_size for all devices to that value. */
266 new_values = (max_read_size << 12) | (smallest_max_payload << 5);
Wei Yongjun17a26352012-12-03 08:28:36 -0500267 for_each_pci_dev(dev)
Jiang Liu424ffc92012-07-24 17:20:15 +0800268 pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
269 PCI_EXP_DEVCTL_PAYLOAD | PCI_EXP_DEVCTL_READRQ,
270 new_values);
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400271}
272
273
274/*
275 * Second PCI initialization entry point, called by subsys_initcall.
276 *
277 * The controllers have been set up by the time we get here, by a call to
278 * tile_pci_init.
279 */
Chris Metcalf05ef1b72012-04-25 12:45:26 -0400280int __init pcibios_init(void)
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400281{
282 int i;
283
284 pr_info("PCI: Probing PCI hardware\n");
285
286 /*
287 * Delay a bit in case devices aren't ready. Some devices are
288 * known to require at least 20ms here, but we use a more
289 * conservative value.
290 */
Chris Metcalf9bbb08f2013-08-02 11:59:06 -0400291 msleep(250);
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400292
293 /* Scan all of the recorded PCI controllers. */
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400294 for (i = 0; i < TILE_NUM_PCIE; i++) {
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400295 /*
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400296 * Do real pcibios init ops if the controller is initialized
297 * by tile_pci_init() successfully and not initialized by
298 * pcibios_init() yet to support PCIe hot-plug.
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400299 */
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400300 if (pci_scan_flags[i] == 0 && controllers[i].ops != NULL) {
301 struct pci_controller *controller = &controllers[i];
302 struct pci_bus *bus;
Yinghai Lub17c0e62012-05-17 18:51:13 -0700303 LIST_HEAD(resources);
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400304
Chris Metcalff4de51d2011-05-17 15:25:21 -0400305 if (tile_init_irqs(i, controller)) {
306 pr_err("PCI: Could not initialize IRQs\n");
307 continue;
308 }
309
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400310 pr_info("PCI: initializing controller #%d\n", i);
311
Yinghai Lub17c0e62012-05-17 18:51:13 -0700312 pci_add_resource(&resources, &ioport_resource);
313 pci_add_resource(&resources, &iomem_resource);
Chris Metcalf9bbb08f2013-08-02 11:59:06 -0400314 bus = pci_scan_root_bus(NULL, 0, controller->ops,
315 controller, &resources);
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400316 controller->root_bus = bus;
Yinghai Lub918c622012-05-17 18:51:11 -0700317 controller->last_busno = bus->busn_res.end;
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400318 }
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400319 }
320
321 /* Do machine dependent PCI interrupt routing */
322 pci_fixup_irqs(pci_common_swizzle, tile_map_irq);
323
324 /*
325 * This comes from the generic Linux PCI driver.
326 *
327 * It allocates all of the resources (I/O memory, etc)
328 * associated with the devices read in above.
329 */
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400330 pci_assign_unassigned_resources();
331
332 /* Configure the max_read_size and max_payload_size values. */
333 fixup_read_and_payload_sizes();
334
335 /* Record the I/O resources in the PCI controller structure. */
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400336 for (i = 0; i < TILE_NUM_PCIE; i++) {
337 /*
338 * Do real pcibios init ops if the controller is initialized
339 * by tile_pci_init() successfully and not initialized by
340 * pcibios_init() yet to support PCIe hot-plug.
341 */
342 if (pci_scan_flags[i] == 0 && controllers[i].ops != NULL) {
343 struct pci_bus *root_bus = controllers[i].root_bus;
344 struct pci_bus *next_bus;
345 struct pci_dev *dev;
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400346
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400347 list_for_each_entry(dev, &root_bus->devices, bus_list) {
348 /*
349 * Find the PCI host controller, ie. the 1st
350 * bridge.
351 */
352 if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI &&
353 (PCI_SLOT(dev->devfn) == 0)) {
Chris Metcalf7f240b72012-07-25 15:49:23 -0400354 next_bus = dev->subordinate;
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400355 controllers[i].mem_resources[0] =
356 *next_bus->resource[0];
357 controllers[i].mem_resources[1] =
358 *next_bus->resource[1];
359 controllers[i].mem_resources[2] =
360 *next_bus->resource[2];
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400361
Chris Metcalf398fa5a2011-05-02 15:09:42 -0400362 /* Setup flags. */
363 pci_scan_flags[i] = 1;
364
365 break;
366 }
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400367 }
368 }
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400369 }
370
371 return 0;
372}
373subsys_initcall(pcibios_init);
374
375/*
376 * No bus fixups needed.
377 */
Greg Kroah-Hartmanb881bc42012-12-21 14:06:37 -0800378void pcibios_fixup_bus(struct pci_bus *bus)
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400379{
380 /* Nothing needs to be done. */
381}
382
Myron Stowecf1c5232011-10-28 15:48:17 -0600383void pcibios_set_master(struct pci_dev *dev)
384{
385 /* No special bus mastering setup handling. */
386}
387
Chris Metcalf2be70552013-08-05 15:02:03 -0400388/* Process any "pci=" kernel boot arguments. */
Chris Metcalf7b770a62013-08-13 15:17:38 -0400389char *__init pcibios_setup(char *str)
Chris Metcalf2be70552013-08-05 15:02:03 -0400390{
391 if (!strcmp(str, "off")) {
392 pci_probe = 0;
393 return NULL;
394 }
395 return str;
396}
397
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400398/*
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400399 * Enable memory and/or address decoding, as appropriate, for the
400 * device described by the 'dev' struct.
401 *
402 * This is called from the generic PCI layer, and can be called
403 * for bridges or endpoints.
404 */
405int pcibios_enable_device(struct pci_dev *dev, int mask)
406{
407 u16 cmd, old_cmd;
408 u8 header_type;
409 int i;
410 struct resource *r;
411
412 pci_read_config_byte(dev, PCI_HEADER_TYPE, &header_type);
413
414 pci_read_config_word(dev, PCI_COMMAND, &cmd);
415 old_cmd = cmd;
416 if ((header_type & 0x7F) == PCI_HEADER_TYPE_BRIDGE) {
417 /*
418 * For bridges, we enable both memory and I/O decoding
419 * in call cases.
420 */
421 cmd |= PCI_COMMAND_IO;
422 cmd |= PCI_COMMAND_MEMORY;
423 } else {
424 /*
425 * For endpoints, we enable memory and/or I/O decoding
426 * only if they have a memory resource of that type.
427 */
428 for (i = 0; i < 6; i++) {
429 r = &dev->resource[i];
430 if (r->flags & IORESOURCE_UNSET) {
431 pr_err("PCI: Device %s not available "
432 "because of resource collisions\n",
433 pci_name(dev));
434 return -EINVAL;
435 }
436 if (r->flags & IORESOURCE_IO)
437 cmd |= PCI_COMMAND_IO;
438 if (r->flags & IORESOURCE_MEM)
439 cmd |= PCI_COMMAND_MEMORY;
440 }
441 }
442
443 /*
444 * We only write the command if it changed.
445 */
446 if (cmd != old_cmd)
447 pci_write_config_word(dev, PCI_COMMAND, cmd);
448 return 0;
449}
450
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400451/****************************************************************
452 *
453 * Tile PCI config space read/write routines
454 *
455 ****************************************************************/
456
457/*
458 * These are the normal read and write ops
459 * These are expanded with macros from pci_bus_read_config_byte() etc.
460 *
461 * devfn is the combined PCI slot & function.
462 *
463 * offset is in bytes, from the start of config space for the
464 * specified bus & slot.
465 */
466
Greg Kroah-Hartmanb881bc42012-12-21 14:06:37 -0800467static int tile_cfg_read(struct pci_bus *bus, unsigned int devfn, int offset,
468 int size, u32 *val)
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400469{
470 struct pci_controller *controller = bus->sysdata;
471 int busnum = bus->number & 0xff;
472 int slot = (devfn >> 3) & 0x1f;
473 int function = devfn & 0x7;
474 u32 addr;
475 int config_mode = 1;
476
477 /*
478 * There is no bridge between the Tile and bus 0, so we
479 * use config0 to talk to bus 0.
480 *
481 * If we're talking to a bus other than zero then we
482 * must have found a bridge.
483 */
484 if (busnum == 0) {
485 /*
486 * We fake an empty slot for (busnum == 0) && (slot > 0),
487 * since there is only one slot on bus 0.
488 */
489 if (slot) {
490 *val = 0xFFFFFFFF;
491 return 0;
492 }
493 config_mode = 0;
494 }
495
496 addr = busnum << 20; /* Bus in 27:20 */
497 addr |= slot << 15; /* Slot (device) in 19:15 */
498 addr |= function << 12; /* Function is in 14:12 */
499 addr |= (offset & 0xFFF); /* byte address in 0:11 */
500
501 return hv_dev_pread(controller->hv_cfg_fd[config_mode], 0,
502 (HV_VirtAddr)(val), size, addr);
503}
504
505
506/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300507 * See tile_cfg_read() for relevant comments.
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400508 * Note that "val" is the value to write, not a pointer to that value.
509 */
Greg Kroah-Hartmanb881bc42012-12-21 14:06:37 -0800510static int tile_cfg_write(struct pci_bus *bus, unsigned int devfn, int offset,
511 int size, u32 val)
Chris Metcalff02cbbe2010-11-02 12:05:10 -0400512{
513 struct pci_controller *controller = bus->sysdata;
514 int busnum = bus->number & 0xff;
515 int slot = (devfn >> 3) & 0x1f;
516 int function = devfn & 0x7;
517 u32 addr;
518 int config_mode = 1;
519 HV_VirtAddr valp = (HV_VirtAddr)&val;
520
521 /*
522 * For bus 0 slot 0 we use config 0 accesses.
523 */
524 if (busnum == 0) {
525 /*
526 * We fake an empty slot for (busnum == 0) && (slot > 0),
527 * since there is only one slot on bus 0.
528 */
529 if (slot)
530 return 0;
531 config_mode = 0;
532 }
533
534 addr = busnum << 20; /* Bus in 27:20 */
535 addr |= slot << 15; /* Slot (device) in 19:15 */
536 addr |= function << 12; /* Function is in 14:12 */
537 addr |= (offset & 0xFFF); /* byte address in 0:11 */
538
539#ifdef __BIG_ENDIAN
540 /* Point to the correct part of the 32-bit "val". */
541 valp += 4 - size;
542#endif
543
544 return hv_dev_pwrite(controller->hv_cfg_fd[config_mode], 0,
545 valp, size, addr);
546}
547
548
549static struct pci_ops tile_cfg_ops = {
550 .read = tile_cfg_read,
551 .write = tile_cfg_write,
552};
553
554
555/*
556 * In the following, each PCI controller's mem_resources[1]
557 * represents its (non-prefetchable) PCI memory resource.
558 * mem_resources[0] and mem_resources[2] refer to its PCI I/O and
559 * prefetchable PCI memory resources, respectively.
560 * For more details, see pci_setup_bridge() in setup-bus.c.
561 * By comparing the target PCI memory address against the
562 * end address of controller 0, we can determine the controller
563 * that should accept the PCI memory access.
564 */
565#define TILE_READ(size, type) \
566type _tile_read##size(unsigned long addr) \
567{ \
568 type val; \
569 int idx = 0; \
570 if (addr > controllers[0].mem_resources[1].end && \
571 addr > controllers[0].mem_resources[2].end) \
572 idx = 1; \
573 if (hv_dev_pread(controllers[idx].hv_mem_fd, 0, \
574 (HV_VirtAddr)(&val), sizeof(type), addr)) \
575 pr_err("PCI: read %zd bytes at 0x%lX failed\n", \
576 sizeof(type), addr); \
577 return val; \
578} \
579EXPORT_SYMBOL(_tile_read##size)
580
581TILE_READ(b, u8);
582TILE_READ(w, u16);
583TILE_READ(l, u32);
584TILE_READ(q, u64);
585
586#define TILE_WRITE(size, type) \
587void _tile_write##size(type val, unsigned long addr) \
588{ \
589 int idx = 0; \
590 if (addr > controllers[0].mem_resources[1].end && \
591 addr > controllers[0].mem_resources[2].end) \
592 idx = 1; \
593 if (hv_dev_pwrite(controllers[idx].hv_mem_fd, 0, \
594 (HV_VirtAddr)(&val), sizeof(type), addr)) \
595 pr_err("PCI: write %zd bytes at 0x%lX failed\n", \
596 sizeof(type), addr); \
597} \
598EXPORT_SYMBOL(_tile_write##size)
599
600TILE_WRITE(b, u8);
601TILE_WRITE(w, u16);
602TILE_WRITE(l, u32);
603TILE_WRITE(q, u64);