Liviu Dudau | d1e6dc9 | 2014-09-29 15:29:31 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Code borrowed from powerpc/kernel/pci-common.c |
| 3 | * |
| 4 | * Copyright (C) 2003 Anton Blanchard <anton@au.ibm.com>, IBM |
| 5 | * Copyright (C) 2014 ARM Ltd. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * version 2 as published by the Free Software Foundation. |
| 10 | * |
| 11 | */ |
| 12 | |
Hanjun Guo | a9cb97f | 2015-03-24 14:02:40 +0000 | [diff] [blame] | 13 | #include <linux/acpi.h> |
Liviu Dudau | d1e6dc9 | 2014-09-29 15:29:31 +0100 | [diff] [blame] | 14 | #include <linux/init.h> |
| 15 | #include <linux/io.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/mm.h> |
| 18 | #include <linux/of_pci.h> |
| 19 | #include <linux/of_platform.h> |
Tomasz Nowicki | 2ab51dd | 2016-06-10 15:36:26 -0500 | [diff] [blame] | 20 | #include <linux/pci.h> |
Liviu Dudau | d1e6dc9 | 2014-09-29 15:29:31 +0100 | [diff] [blame] | 21 | #include <linux/slab.h> |
| 22 | |
Liviu Dudau | d1e6dc9 | 2014-09-29 15:29:31 +0100 | [diff] [blame] | 23 | /* |
| 24 | * Called after each bus is probed, but before its children are examined |
| 25 | */ |
| 26 | void pcibios_fixup_bus(struct pci_bus *bus) |
| 27 | { |
| 28 | /* nothing to do, expected to be removed in the future */ |
| 29 | } |
| 30 | |
| 31 | /* |
| 32 | * We don't have to worry about legacy ISA devices, so nothing to do here |
| 33 | */ |
| 34 | resource_size_t pcibios_align_resource(void *data, const struct resource *res, |
| 35 | resource_size_t size, resource_size_t align) |
| 36 | { |
| 37 | return res->start; |
| 38 | } |
| 39 | |
Lorenzo Pieralisi | 7240751 | 2015-07-30 14:13:59 +0100 | [diff] [blame] | 40 | /** |
| 41 | * pcibios_enable_device - Enable I/O and memory. |
| 42 | * @dev: PCI device to be enabled |
| 43 | * @mask: bitmask of BARs to enable |
| 44 | */ |
| 45 | int pcibios_enable_device(struct pci_dev *dev, int mask) |
| 46 | { |
| 47 | if (pci_has_flag(PCI_PROBE_ONLY)) |
| 48 | return 0; |
| 49 | |
| 50 | return pci_enable_resources(dev, mask); |
| 51 | } |
| 52 | |
Liviu Dudau | d1e6dc9 | 2014-09-29 15:29:31 +0100 | [diff] [blame] | 53 | /* |
Tomasz Nowicki | d8ed75d | 2016-06-10 21:55:17 +0200 | [diff] [blame] | 54 | * Try to assign the IRQ number when probing a new device |
Liviu Dudau | d1e6dc9 | 2014-09-29 15:29:31 +0100 | [diff] [blame] | 55 | */ |
Tomasz Nowicki | d8ed75d | 2016-06-10 21:55:17 +0200 | [diff] [blame] | 56 | int pcibios_alloc_irq(struct pci_dev *dev) |
Liviu Dudau | d1e6dc9 | 2014-09-29 15:29:31 +0100 | [diff] [blame] | 57 | { |
Tomasz Nowicki | d8ed75d | 2016-06-10 21:55:17 +0200 | [diff] [blame] | 58 | if (acpi_disabled) |
| 59 | dev->irq = of_irq_parse_and_map_pci(dev, 0, 0); |
| 60 | #ifdef CONFIG_ACPI |
| 61 | else |
| 62 | return acpi_pci_irq_enable(dev); |
| 63 | #endif |
Liviu Dudau | d1e6dc9 | 2014-09-29 15:29:31 +0100 | [diff] [blame] | 64 | |
| 65 | return 0; |
| 66 | } |
Hanjun Guo | a9cb97f | 2015-03-24 14:02:40 +0000 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | * raw_pci_read/write - Platform-specific PCI config space access. |
| 70 | */ |
| 71 | int raw_pci_read(unsigned int domain, unsigned int bus, |
| 72 | unsigned int devfn, int reg, int len, u32 *val) |
| 73 | { |
Tomasz Nowicki | f058f4f | 2016-06-10 21:55:18 +0200 | [diff] [blame^] | 74 | struct pci_bus *b = pci_find_bus(domain, bus); |
| 75 | |
| 76 | if (!b) |
| 77 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 78 | return b->ops->read(b, devfn, reg, len, val); |
Hanjun Guo | a9cb97f | 2015-03-24 14:02:40 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | int raw_pci_write(unsigned int domain, unsigned int bus, |
| 82 | unsigned int devfn, int reg, int len, u32 val) |
| 83 | { |
Tomasz Nowicki | f058f4f | 2016-06-10 21:55:18 +0200 | [diff] [blame^] | 84 | struct pci_bus *b = pci_find_bus(domain, bus); |
| 85 | |
| 86 | if (!b) |
| 87 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 88 | return b->ops->write(b, devfn, reg, len, val); |
Hanjun Guo | a9cb97f | 2015-03-24 14:02:40 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Ganapatrao Kulkarni | 1a2db30 | 2016-04-08 15:50:27 -0700 | [diff] [blame] | 91 | #ifdef CONFIG_NUMA |
| 92 | |
| 93 | int pcibus_to_node(struct pci_bus *bus) |
| 94 | { |
| 95 | return dev_to_node(&bus->dev); |
| 96 | } |
| 97 | EXPORT_SYMBOL(pcibus_to_node); |
| 98 | |
| 99 | #endif |
| 100 | |
Hanjun Guo | a9cb97f | 2015-03-24 14:02:40 +0000 | [diff] [blame] | 101 | #ifdef CONFIG_ACPI |
Tomasz Nowicki | 2ab51dd | 2016-06-10 15:36:26 -0500 | [diff] [blame] | 102 | |
| 103 | int acpi_pci_bus_find_domain_nr(struct pci_bus *bus) |
| 104 | { |
| 105 | return 0; |
| 106 | } |
| 107 | |
Hanjun Guo | a9cb97f | 2015-03-24 14:02:40 +0000 | [diff] [blame] | 108 | /* Root bridge scanning */ |
| 109 | struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root) |
| 110 | { |
| 111 | /* TODO: Should be revisited when implementing PCI on ACPI */ |
| 112 | return NULL; |
| 113 | } |
| 114 | #endif |