15 #include <linux/kernel.h>
16 #include <linux/pci.h>
18 #include <linux/string.h>
20 #include <linux/capability.h>
21 #include <linux/sched.h>
22 #include <linux/errno.h>
27 #include <linux/export.h>
29 #include <asm/processor.h>
30 #include <asm/sections.h>
31 #include <asm/byteorder.h>
62 static int num_controllers;
65 static struct pci_ops tile_cfg_ops;
89 sprintf(filename,
"pcie/%d/config%d", controller_id, config_type);
100 static int __devinit tile_init_irqs(
int controller_id,
109 sprintf(filename,
"pcie/%d/ctl", controller_id);
112 pr_err(
"PCI: hv_dev_open(%s) failed\n", filename);
118 if (ret !=
sizeof(rc_config)) {
119 pr_err(
"PCI: wanted %zd bytes, got %d\n",
120 sizeof(rc_config), ret);
124 controller->
irq_base = rc_config.intr;
126 for (x = 0; x < 4; x++)
130 if (rc_config.plx_gen1)
148 pr_info(
"PCI: Searching for controllers...\n");
160 if (pci_scan_flags[i] == 0) {
171 hv_cfg_fd0 = tile_pcie_open(i, 0);
174 hv_cfg_fd1 = tile_pcie_open(i, 1);
175 if (hv_cfg_fd1 < 0) {
176 pr_err(
"PCI: Couldn't open config fd to HV "
177 "for controller %d\n", i);
181 sprintf(name,
"pcie/%d/mem", i);
184 pr_err(
"PCI: Could not open mem fd to HV!\n");
188 pr_info(
"PCI: Found PCI controller #%d\n", i);
190 controller = &controllers[
i];
198 controller->
ops = &tile_cfg_ops;
218 for (i = 0; i < num_controllers; i++) {
225 return num_controllers;
240 static void __devinit fixup_read_and_payload_sizes(
void)
243 int smallest_max_payload = 0x1;
244 int max_read_size = 0x2;
252 if (!pci_is_pcie(dev))
257 if (max_payload < smallest_max_payload)
262 new_values = (max_read_size << 12) | (smallest_max_payload << 5);
280 pr_info(
"PCI: Probing PCI hardware\n");
296 if (pci_scan_flags[i] == 0 && controllers[i].
ops !=
NULL) {
301 if (tile_init_irqs(i, controller)) {
302 pr_err(
"PCI: Could not initialize IRQs\n");
306 pr_info(
"PCI: initializing controller #%d\n", i);
337 fixup_read_and_payload_sizes();
346 if (pci_scan_flags[i] == 0 && controllers[i].
ops !=
NULL) {
347 struct pci_bus *root_bus = controllers[
i].root_bus;
359 controllers[
i].mem_resources[0] =
361 controllers[
i].mem_resources[1] =
363 controllers[
i].mem_resources[2] =
367 pci_scan_flags[
i] = 1;
422 for (i = 0; i < 6; i++) {
425 pr_err(
"PCI: Device %s not available "
426 "because of resource collisions\n",
469 int slot = (devfn >> 3) & 0x1f;
470 int function = devfn & 0x7;
495 addr |=
function << 12;
496 addr |= (offset & 0xFFF);
514 int busnum = bus->
number & 0xff;
515 int slot = (devfn >> 3) & 0x1f;
516 int function = devfn & 0x7;
536 addr |=
function << 12;
537 addr |= (offset & 0xFFF);
549 static struct pci_ops tile_cfg_ops = {
550 .read = tile_cfg_read,
551 .write = tile_cfg_write,
565 #define TILE_READ(size, type) \
566 type _tile_read##size(unsigned long addr) \
570 if (addr > controllers[0].mem_resources[1].end && \
571 addr > controllers[0].mem_resources[2].end) \
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); \
579 EXPORT_SYMBOL(_tile_read##size)
586 #define TILE_WRITE(size, type) \
587 void _tile_write##size(type val, unsigned long addr) \
590 if (addr > controllers[0].mem_resources[1].end && \
591 addr > controllers[0].mem_resources[2].end) \
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); \
598 EXPORT_SYMBOL(_tile_write##size)