diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-07-31 00:01:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-07-31 00:01:36 -0400 |
commit | bad60e6f259a01cf9f29a1ef8d435ab6c60b2de9 (patch) | |
tree | c9aaa8166735659761239c117af2b11b022bc6cb /drivers/pci/hotplug/pnv_php.c | |
parent | dd0f0cf58af70dc9267409f113bea772d57f675c (diff) | |
parent | 719dbb2df78fc9a40e28392b07cd715bfc5a665c (diff) |
Merge tag 'powerpc-4.8-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux
Pull powerpc updates from Michael Ellerman:
"Highlights:
- PowerNV PCI hotplug support.
- Lots more Power9 support.
- eBPF JIT support on ppc64le.
- Lots of cxl updates.
- Boot code consolidation.
Bug fixes:
- Fix spin_unlock_wait() from Boqun Feng
- Fix stack pointer corruption in __tm_recheckpoint() from Michael
Neuling
- Fix multiple bugs in memory_hotplug_max() from Bharata B Rao
- mm: Ensure "special" zones are empty from Oliver O'Halloran
- ftrace: Separate the heuristics for checking call sites from
Michael Ellerman
- modules: Never restore r2 for a mprofile-kernel style mcount() call
from Michael Ellerman
- Fix endianness when reading TCEs from Alexey Kardashevskiy
- start rtasd before PCI probing from Greg Kurz
- PCI: rpaphp: Fix slot registration for multiple slots under a PHB
from Tyrel Datwyler
- powerpc/mm: Add memory barrier in __hugepte_alloc() from Sukadev
Bhattiprolu
Cleanups & fixes:
- Drop support for MPIC in pseries from Rashmica Gupta
- Define and use PPC64_ELF_ABI_v2/v1 from Michael Ellerman
- Remove unused symbols in asm-offsets.c from Rashmica Gupta
- Fix SRIOV not building without EEH enabled from Russell Currey
- Remove kretprobe_trampoline_holder from Thiago Jung Bauermann
- Reduce log level of PCI I/O space warning from Benjamin
Herrenschmidt
- Add array bounds checking to crash_shutdown_handlers from Suraj
Jitindar Singh
- Avoid -maltivec when using clang integrated assembler from Anton
Blanchard
- Fix array overrun in ppc_rtas() syscall from Andrew Donnellan
- Fix error return value in cmm_mem_going_offline() from Rasmus
Villemoes
- export cpu_to_core_id() from Mauricio Faria de Oliveira
- Remove old symbols from defconfigs from Andrew Donnellan
- Update obsolete comments in setup_32.c about entry conditions from
Benjamin Herrenschmidt
- Add comment explaining the purpose of setup_kdump_trampoline() from
Benjamin Herrenschmidt
- Merge the RELOCATABLE config entries for ppc32 and ppc64 from Kevin
Hao
- Remove RELOCATABLE_PPC32 from Kevin Hao
- Fix .long's in tlb-radix.c to more meaningful from Balbir Singh
Minor cleanups & fixes:
- Andrew Donnellan, Anna-Maria Gleixner, Anton Blanchard, Benjamin
Herrenschmidt, Bharata B Rao, Christophe Leroy, Colin Ian King,
Geliang Tang, Greg Kurz, Madhavan Srinivasan, Michael Ellerman,
Michael Ellerman, Stephen Rothwell, Stewart Smith.
Freescale updates from Scott:
- "Highlights include more 8xx optimizations, device tree updates,
and MVME7100 support."
PowerNV PCI hotplug from Gavin Shan:
- PCI: Add pcibios_setup_bridge()
- Override pcibios_setup_bridge()
- Remove PCI_RESET_DELAY_US
- Move pnv_pci_ioda_setup_opal_tce_kill() around
- Increase PE# capacity
- Allocate PE# in reverse order
- Create PEs in pcibios_setup_bridge()
- Setup PE for root bus
- Extend PCI bridge resources
- Make pnv_ioda_deconfigure_pe() visible
- Dynamically release PE
- Update bridge windows on PCI plug
- Delay populating pdn
- Support PCI slot ID
- Use PCI slot reset infrastructure
- Introduce pnv_pci_get_slot_id()
- Functions to get/set PCI slot state
- PCI/hotplug: PowerPC PowerNV PCI hotplug driver
- Print correct PHB type names
Power9 idle support from Shreyas B. Prabhu:
- set power_save func after the idle states are initialized
- Use PNV_THREAD_WINKLE macro while requesting for winkle
- make hypervisor state restore a function
- Rename idle_power7.S to idle_book3s.S
- Rename reusable idle functions to hardware agnostic names
- Make pnv_powersave_common more generic
- abstraction for saving SPRs before entering deep idle states
- Add platform support for stop instruction
- cpuidle/powernv: Use CPUIDLE_STATE_MAX instead of MAX_POWERNV_IDLE_STATES
- cpuidle/powernv: cleanup cpuidle-powernv.c
- cpuidle/powernv: Add support for POWER ISA v3 idle states
- Use deepest stop state when cpu is offlined
Power9 PMU from Madhavan Srinivasan:
- factor out power8 pmu macros and defines
- factor out power8 pmu functions
- factor out power8 __init_pmu code
- Add power9 event list macros for generic and cache events
- Power9 PMU support
- Export Power9 generic and cache events to sysfs
Power9 preliminary interrupt & PCI support from Benjamin Herrenschmidt:
- Add XICS emulation APIs
- Move a few exception common handlers to make room
- Add support for HV virtualization interrupts
- Add mechanism to force a replay of interrupts
- Add ICP OPAL backend
- Discover IODA3 PHBs
- pci: Remove obsolete SW invalidate
- opal: Add real mode call wrappers
- Rename TCE invalidation calls
- Remove SWINV constants and obsolete TCE code
- Rework accessing the TCE invalidate register
- Fallback to OPAL for TCE invalidations
- Use the device-tree to get available range of M64's
- Check status of a PHB before using it
- pci: Don't try to allocate resources that will be reassigned
Other Power9:
- Send SIGBUS on unaligned copy and paste from Chris Smart
- Large Decrementer support from Oliver O'Halloran
- Load Monitor Register Support from Jack Miller
Performance improvements from Anton Blanchard:
- Avoid load hit store in __giveup_fpu() and __giveup_altivec()
- Avoid load hit store in setup_sigcontext()
- Remove assembly versions of strcpy, strcat, strlen and strcmp
- Align hot loops of some string functions
eBPF JIT from Naveen N. Rao:
- Fix/enhance 32-bit Load Immediate implementation
- Optimize 64-bit Immediate loads
- Introduce rotate immediate instructions
- A few cleanups
- Isolate classic BPF JIT specifics into a separate header
- Implement JIT compiler for extended BPF
Operator Panel driver from Suraj Jitindar Singh:
- devicetree/bindings: Add binding for operator panel on FSP machines
- Add inline function to get rc from an ASYNC_COMP opal_msg
- Add driver for operator panel on FSP machines
Sparse fixes from Daniel Axtens:
- make some things static
- Introduce asm-prototypes.h
- Include headers containing prototypes
- Use #ifdef __BIG_ENDIAN__ #else for REG_BYTE
- kvm: Clarify __user annotations
- Pass endianness to sparse
- Make ppc_md.{halt, restart} __noreturn
MM fixes & cleanups from Aneesh Kumar K.V:
- radix: Update LPCR HR bit as per ISA
- use _raw variant of page table accessors
- Compile out radix related functions if RADIX_MMU is disabled
- Clear top 16 bits of va only on older cpus
- Print formation regarding the the MMU mode
- hash: Update SDR1 size encoding as documented in ISA 3.0
- radix: Update PID switch sequence
- radix: Update machine call back to support new HCALL.
- radix: Add LPID based tlb flush helpers
- radix: Add a kernel command line to disable radix
- Cleanup LPCR defines
Boot code consolidation from Benjamin Herrenschmidt:
- Move epapr_paravirt_early_init() to early_init_devtree()
- cell: Don't use flat device-tree after boot
- ge_imp3a: Don't use the flat device-tree after boot
- mpc85xx_ds: Don't use the flat device-tree after boot
- mpc85xx_rdb: Don't use the flat device-tree after boot
- Don't test for machine type in rtas_initialize()
- Don't test for machine type in smp_setup_cpu_maps()
- dt: Add of_device_compatible_match()
- Factor do_feature_fixup calls
- Move 64-bit feature fixup earlier
- Move 64-bit memory reserves to setup_arch()
- Use a cachable DART
- Move FW feature probing out of pseries probe()
- Put exception configuration in a common place
- Remove early allocation of the SMU command buffer
- Move MMU backend selection out of platform code
- pasemi: Remove IOBMAP allocation from platform probe()
- mm/hash: Don't use machine_is() early during boot
- Don't test for machine type to detect HEA special case
- pmac: Remove spurrious machine type test
- Move hash table ops to a separate structure
- Ensure that ppc_md is empty before probing for machine type
- Move 64-bit probe_machine() to later in the boot process
- Move 32-bit probe() machine to later in the boot process
- Get rid of ppc_md.init_early()
- Move the boot time info banner to a separate function
- Move setting of {i,d}cache_bsize to initialize_cache_info()
- Move the content of setup_system() to setup_arch()
- Move cache info inits to a separate function
- Re-order the call to smp_setup_cpu_maps()
- Re-order setup_panic()
- Make a few boot functions __init
- Merge 32-bit and 64-bit setup_arch()
Other new features:
- tty/hvc: Use IRQF_SHARED for OPAL hvc consoles from Sam Mendoza-Jonas
- tty/hvc: Use opal irqchip interface if available from Sam Mendoza-Jonas
- powerpc: Add module autoloading based on CPU features from Alastair D'Silva
- crypto: vmx - Convert to CPU feature based module autoloading from Alastair D'Silva
- Wake up kopald polling thread before waiting for events from Benjamin Herrenschmidt
- xmon: Dump ISA 2.06 SPRs from Michael Ellerman
- xmon: Dump ISA 2.07 SPRs from Michael Ellerman
- Add a parameter to disable 1TB segs from Oliver O'Halloran
- powerpc/boot: Add OPAL console to epapr wrappers from Oliver O'Halloran
- Assign fixed PHB number based on device-tree properties from Guilherme G. Piccoli
- pseries: Add pseries hotplug workqueue from John Allen
- pseries: Add support for hotplug interrupt source from John Allen
- pseries: Use kernel hotplug queue for PowerVM hotplug events from John Allen
- pseries: Move property cloning into its own routine from Nathan Fontenot
- pseries: Dynamic add entires to associativity lookup array from Nathan Fontenot
- pseries: Auto-online hotplugged memory from Nathan Fontenot
- pseries: Remove call to memblock_add() from Nathan Fontenot
cxl:
- Add set and get private data to context struct from Michael Neuling
- make base more explicitly non-modular from Paul Gortmaker
- Use for_each_compatible_node() macro from Wei Yongjun
- Frederic Barrat
- Abstract the differences between the PSL and XSL
- Make vPHB device node match adapter's
- Philippe Bergheaud
- Add mechanism for delivering AFU driver specific events
- Ignore CAPI adapters misplaced in switched slots
- Refine slice error debug messages
- Andrew Donnellan
- static-ify variables to fix sparse warnings
- PCI/hotplug: pnv_php: export symbols and move struct types needed by cxl
- PCI/hotplug: pnv_php: handle OPAL_PCI_SLOT_OFFLINE power state
- Add cxl_check_and_switch_mode() API to switch bi-modal cards
- remove dead Kconfig options
- fix potential NULL dereference in free_adapter()
- Ian Munsie
- Update process element after allocating interrupts
- Add support for CAPP DMA mode
- Fix allowing bogus AFU descriptors with 0 maximum processes
- Fix allocating a minimum of 2 pages for the SPA
- Fix bug where AFU disable operation had no effect
- Workaround XSL bug that does not clear the RA bit after a reset
- Fix NULL pointer dereference on kernel contexts with no AFU interrupts
- powerpc/powernv: Split cxl code out into a separate file
- Add cxl_slot_is_supported API
- Enable bus mastering for devices using CAPP DMA mode
- Move cxl_afu_get / cxl_afu_put to base
- Allow a default context to be associated with an external pci_dev
- Do not create vPHB if there are no AFU configuration records
- powerpc/powernv: Add support for the cxl kernel api on the real phb
- Add support for using the kernel API with a real PHB
- Add kernel APIs to get & set the max irqs per context
- Add preliminary workaround for CX4 interrupt limitation
- Add support for interrupts on the Mellanox CX4
- Workaround PE=0 hardware limitation in Mellanox CX4
- powerpc/powernv: Fix pci-cxl.c build when CONFIG_MODULES=n
selftests:
- Test unaligned copy and paste from Chris Smart
- Load Monitor Register Tests from Jack Miller
- Cyril Bur
- exec() with suspended transaction
- Use signed long to read perf_event_paranoid
- Fix usage message in context_switch
- Fix generation of vector instructions/types in context_switch
- Michael Ellerman
- Use "Delta" rather than "Error" in normal output
- Import Anton's mmap & futex micro benchmarks
- Add a test for PROT_SAO"
* tag 'powerpc-4.8-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux: (263 commits)
powerpc/mm: Parenthesise IS_ENABLED() in if condition
tty/hvc: Use opal irqchip interface if available
tty/hvc: Use IRQF_SHARED for OPAL hvc consoles
selftests/powerpc: exec() with suspended transaction
powerpc: Improve comment explaining why we modify VRSAVE
powerpc/mm: Drop unused externs for hpte_init_beat[_v3]()
powerpc/mm: Rename hpte_init_lpar() and move the fallback to a header
powerpc/mm: Fix build break when PPC_NATIVE=n
crypto: vmx - Convert to CPU feature based module autoloading
powerpc: Add module autoloading based on CPU features
powerpc/powernv/ioda: Fix endianness when reading TCEs
powerpc/mm: Add memory barrier in __hugepte_alloc()
powerpc/modules: Never restore r2 for a mprofile-kernel style mcount() call
powerpc/ftrace: Separate the heuristics for checking call sites
powerpc: Merge 32-bit and 64-bit setup_arch()
powerpc/64: Make a few boot functions __init
powerpc: Re-order setup_panic()
powerpc: Re-order the call to smp_setup_cpu_maps()
powerpc/32: Move cache info inits to a separate function
powerpc/64: Move the content of setup_system() to setup_arch()
...
Diffstat (limited to 'drivers/pci/hotplug/pnv_php.c')
-rw-r--r-- | drivers/pci/hotplug/pnv_php.c | 711 |
1 files changed, 711 insertions, 0 deletions
diff --git a/drivers/pci/hotplug/pnv_php.c b/drivers/pci/hotplug/pnv_php.c new file mode 100644 index 000000000000..e6245b03f0a1 --- /dev/null +++ b/drivers/pci/hotplug/pnv_php.c | |||
@@ -0,0 +1,711 @@ | |||
1 | /* | ||
2 | * PCI Hotplug Driver for PowerPC PowerNV platform. | ||
3 | * | ||
4 | * Copyright Gavin Shan, IBM Corporation 2016. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <linux/libfdt.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <linux/pci.h> | ||
15 | #include <linux/pci_hotplug.h> | ||
16 | |||
17 | #include <asm/opal.h> | ||
18 | #include <asm/pnv-pci.h> | ||
19 | #include <asm/ppc-pci.h> | ||
20 | |||
21 | #define DRIVER_VERSION "0.1" | ||
22 | #define DRIVER_AUTHOR "Gavin Shan, IBM Corporation" | ||
23 | #define DRIVER_DESC "PowerPC PowerNV PCI Hotplug Driver" | ||
24 | |||
25 | static LIST_HEAD(pnv_php_slot_list); | ||
26 | static DEFINE_SPINLOCK(pnv_php_lock); | ||
27 | |||
28 | static void pnv_php_register(struct device_node *dn); | ||
29 | static void pnv_php_unregister_one(struct device_node *dn); | ||
30 | static void pnv_php_unregister(struct device_node *dn); | ||
31 | |||
32 | static void pnv_php_free_slot(struct kref *kref) | ||
33 | { | ||
34 | struct pnv_php_slot *php_slot = container_of(kref, | ||
35 | struct pnv_php_slot, kref); | ||
36 | |||
37 | WARN_ON(!list_empty(&php_slot->children)); | ||
38 | kfree(php_slot->name); | ||
39 | kfree(php_slot); | ||
40 | } | ||
41 | |||
42 | static inline void pnv_php_put_slot(struct pnv_php_slot *php_slot) | ||
43 | { | ||
44 | |||
45 | if (WARN_ON(!php_slot)) | ||
46 | return; | ||
47 | |||
48 | kref_put(&php_slot->kref, pnv_php_free_slot); | ||
49 | } | ||
50 | |||
51 | static struct pnv_php_slot *pnv_php_match(struct device_node *dn, | ||
52 | struct pnv_php_slot *php_slot) | ||
53 | { | ||
54 | struct pnv_php_slot *target, *tmp; | ||
55 | |||
56 | if (php_slot->dn == dn) { | ||
57 | kref_get(&php_slot->kref); | ||
58 | return php_slot; | ||
59 | } | ||
60 | |||
61 | list_for_each_entry(tmp, &php_slot->children, link) { | ||
62 | target = pnv_php_match(dn, tmp); | ||
63 | if (target) | ||
64 | return target; | ||
65 | } | ||
66 | |||
67 | return NULL; | ||
68 | } | ||
69 | |||
70 | struct pnv_php_slot *pnv_php_find_slot(struct device_node *dn) | ||
71 | { | ||
72 | struct pnv_php_slot *php_slot, *tmp; | ||
73 | unsigned long flags; | ||
74 | |||
75 | spin_lock_irqsave(&pnv_php_lock, flags); | ||
76 | list_for_each_entry(tmp, &pnv_php_slot_list, link) { | ||
77 | php_slot = pnv_php_match(dn, tmp); | ||
78 | if (php_slot) { | ||
79 | spin_unlock_irqrestore(&pnv_php_lock, flags); | ||
80 | return php_slot; | ||
81 | } | ||
82 | } | ||
83 | spin_unlock_irqrestore(&pnv_php_lock, flags); | ||
84 | |||
85 | return NULL; | ||
86 | } | ||
87 | EXPORT_SYMBOL_GPL(pnv_php_find_slot); | ||
88 | |||
89 | /* | ||
90 | * Remove pdn for all children of the indicated device node. | ||
91 | * The function should remove pdn in a depth-first manner. | ||
92 | */ | ||
93 | static void pnv_php_rmv_pdns(struct device_node *dn) | ||
94 | { | ||
95 | struct device_node *child; | ||
96 | |||
97 | for_each_child_of_node(dn, child) { | ||
98 | pnv_php_rmv_pdns(child); | ||
99 | |||
100 | pci_remove_device_node_info(child); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | /* | ||
105 | * Detach all child nodes of the indicated device nodes. The | ||
106 | * function should handle device nodes in depth-first manner. | ||
107 | * | ||
108 | * We should not invoke of_node_release() as the memory for | ||
109 | * individual device node is part of large memory block. The | ||
110 | * large block is allocated from memblock (system bootup) or | ||
111 | * kmalloc() when unflattening the device tree by OF changeset. | ||
112 | * We can not free the large block allocated from memblock. For | ||
113 | * later case, it should be released at once. | ||
114 | */ | ||
115 | static void pnv_php_detach_device_nodes(struct device_node *parent) | ||
116 | { | ||
117 | struct device_node *dn; | ||
118 | int refcount; | ||
119 | |||
120 | for_each_child_of_node(parent, dn) { | ||
121 | pnv_php_detach_device_nodes(dn); | ||
122 | |||
123 | of_node_put(dn); | ||
124 | refcount = atomic_read(&dn->kobj.kref.refcount); | ||
125 | if (unlikely(refcount != 1)) | ||
126 | pr_warn("Invalid refcount %d on <%s>\n", | ||
127 | refcount, of_node_full_name(dn)); | ||
128 | |||
129 | of_detach_node(dn); | ||
130 | } | ||
131 | } | ||
132 | |||
133 | static void pnv_php_rmv_devtree(struct pnv_php_slot *php_slot) | ||
134 | { | ||
135 | pnv_php_rmv_pdns(php_slot->dn); | ||
136 | |||
137 | /* | ||
138 | * Decrease the refcount if the device nodes were created | ||
139 | * through OF changeset before detaching them. | ||
140 | */ | ||
141 | if (php_slot->fdt) | ||
142 | of_changeset_destroy(&php_slot->ocs); | ||
143 | pnv_php_detach_device_nodes(php_slot->dn); | ||
144 | |||
145 | if (php_slot->fdt) { | ||
146 | kfree(php_slot->dt); | ||
147 | kfree(php_slot->fdt); | ||
148 | php_slot->dt = NULL; | ||
149 | php_slot->dn->child = NULL; | ||
150 | php_slot->fdt = NULL; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | /* | ||
155 | * As the nodes in OF changeset are applied in reverse order, we | ||
156 | * need revert the nodes in advance so that we have correct node | ||
157 | * order after the changeset is applied. | ||
158 | */ | ||
159 | static void pnv_php_reverse_nodes(struct device_node *parent) | ||
160 | { | ||
161 | struct device_node *child, *next; | ||
162 | |||
163 | /* In-depth first */ | ||
164 | for_each_child_of_node(parent, child) | ||
165 | pnv_php_reverse_nodes(child); | ||
166 | |||
167 | /* Reverse the nodes in the child list */ | ||
168 | child = parent->child; | ||
169 | parent->child = NULL; | ||
170 | while (child) { | ||
171 | next = child->sibling; | ||
172 | |||
173 | child->sibling = parent->child; | ||
174 | parent->child = child; | ||
175 | child = next; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | static int pnv_php_populate_changeset(struct of_changeset *ocs, | ||
180 | struct device_node *dn) | ||
181 | { | ||
182 | struct device_node *child; | ||
183 | int ret = 0; | ||
184 | |||
185 | for_each_child_of_node(dn, child) { | ||
186 | ret = of_changeset_attach_node(ocs, child); | ||
187 | if (unlikely(ret)) | ||
188 | break; | ||
189 | |||
190 | ret = pnv_php_populate_changeset(ocs, child); | ||
191 | if (unlikely(ret)) | ||
192 | break; | ||
193 | } | ||
194 | |||
195 | return ret; | ||
196 | } | ||
197 | |||
198 | static void *pnv_php_add_one_pdn(struct device_node *dn, void *data) | ||
199 | { | ||
200 | struct pci_controller *hose = (struct pci_controller *)data; | ||
201 | struct pci_dn *pdn; | ||
202 | |||
203 | pdn = pci_add_device_node_info(hose, dn); | ||
204 | if (unlikely(!pdn)) | ||
205 | return ERR_PTR(-ENOMEM); | ||
206 | |||
207 | return NULL; | ||
208 | } | ||
209 | |||
210 | static void pnv_php_add_pdns(struct pnv_php_slot *slot) | ||
211 | { | ||
212 | struct pci_controller *hose = pci_bus_to_host(slot->bus); | ||
213 | |||
214 | pci_traverse_device_nodes(slot->dn, pnv_php_add_one_pdn, hose); | ||
215 | } | ||
216 | |||
217 | static int pnv_php_add_devtree(struct pnv_php_slot *php_slot) | ||
218 | { | ||
219 | void *fdt, *fdt1, *dt; | ||
220 | int ret; | ||
221 | |||
222 | /* We don't know the FDT blob size. We try to get it through | ||
223 | * maximal memory chunk and then copy it to another chunk that | ||
224 | * fits the real size. | ||
225 | */ | ||
226 | fdt1 = kzalloc(0x10000, GFP_KERNEL); | ||
227 | if (unlikely(!fdt1)) { | ||
228 | ret = -ENOMEM; | ||
229 | dev_warn(&php_slot->pdev->dev, "Cannot alloc FDT blob\n"); | ||
230 | goto out; | ||
231 | } | ||
232 | |||
233 | ret = pnv_pci_get_device_tree(php_slot->dn->phandle, fdt1, 0x10000); | ||
234 | if (unlikely(ret)) { | ||
235 | dev_warn(&php_slot->pdev->dev, "Error %d getting FDT blob\n", | ||
236 | ret); | ||
237 | goto free_fdt1; | ||
238 | } | ||
239 | |||
240 | fdt = kzalloc(fdt_totalsize(fdt1), GFP_KERNEL); | ||
241 | if (unlikely(!fdt)) { | ||
242 | ret = -ENOMEM; | ||
243 | dev_warn(&php_slot->pdev->dev, "Cannot %d bytes memory\n", | ||
244 | fdt_totalsize(fdt1)); | ||
245 | goto free_fdt1; | ||
246 | } | ||
247 | |||
248 | /* Unflatten device tree blob */ | ||
249 | memcpy(fdt, fdt1, fdt_totalsize(fdt1)); | ||
250 | dt = of_fdt_unflatten_tree(fdt, php_slot->dn, NULL); | ||
251 | if (unlikely(!dt)) { | ||
252 | ret = -EINVAL; | ||
253 | dev_warn(&php_slot->pdev->dev, "Cannot unflatten FDT\n"); | ||
254 | goto free_fdt; | ||
255 | } | ||
256 | |||
257 | /* Initialize and apply the changeset */ | ||
258 | of_changeset_init(&php_slot->ocs); | ||
259 | pnv_php_reverse_nodes(php_slot->dn); | ||
260 | ret = pnv_php_populate_changeset(&php_slot->ocs, php_slot->dn); | ||
261 | if (unlikely(ret)) { | ||
262 | pnv_php_reverse_nodes(php_slot->dn); | ||
263 | dev_warn(&php_slot->pdev->dev, "Error %d populating changeset\n", | ||
264 | ret); | ||
265 | goto free_dt; | ||
266 | } | ||
267 | |||
268 | php_slot->dn->child = NULL; | ||
269 | ret = of_changeset_apply(&php_slot->ocs); | ||
270 | if (unlikely(ret)) { | ||
271 | dev_warn(&php_slot->pdev->dev, "Error %d applying changeset\n", | ||
272 | ret); | ||
273 | goto destroy_changeset; | ||
274 | } | ||
275 | |||
276 | /* Add device node firmware data */ | ||
277 | pnv_php_add_pdns(php_slot); | ||
278 | php_slot->fdt = fdt; | ||
279 | php_slot->dt = dt; | ||
280 | kfree(fdt1); | ||
281 | goto out; | ||
282 | |||
283 | destroy_changeset: | ||
284 | of_changeset_destroy(&php_slot->ocs); | ||
285 | free_dt: | ||
286 | kfree(dt); | ||
287 | php_slot->dn->child = NULL; | ||
288 | free_fdt: | ||
289 | kfree(fdt); | ||
290 | free_fdt1: | ||
291 | kfree(fdt1); | ||
292 | out: | ||
293 | return ret; | ||
294 | } | ||
295 | |||
296 | int pnv_php_set_slot_power_state(struct hotplug_slot *slot, | ||
297 | uint8_t state) | ||
298 | { | ||
299 | struct pnv_php_slot *php_slot = slot->private; | ||
300 | struct opal_msg msg; | ||
301 | int ret; | ||
302 | |||
303 | ret = pnv_pci_set_power_state(php_slot->id, state, &msg); | ||
304 | if (likely(ret > 0)) { | ||
305 | if (be64_to_cpu(msg.params[1]) != php_slot->dn->phandle || | ||
306 | be64_to_cpu(msg.params[2]) != state || | ||
307 | be64_to_cpu(msg.params[3]) != OPAL_SUCCESS) { | ||
308 | dev_warn(&php_slot->pdev->dev, "Wrong msg (%lld, %lld, %lld)\n", | ||
309 | be64_to_cpu(msg.params[1]), | ||
310 | be64_to_cpu(msg.params[2]), | ||
311 | be64_to_cpu(msg.params[3])); | ||
312 | return -ENOMSG; | ||
313 | } | ||
314 | } else if (unlikely(ret < 0)) { | ||
315 | dev_warn(&php_slot->pdev->dev, "Error %d powering %s\n", | ||
316 | ret, (state == OPAL_PCI_SLOT_POWER_ON) ? "on" : "off"); | ||
317 | return ret; | ||
318 | } | ||
319 | |||
320 | if (state == OPAL_PCI_SLOT_POWER_OFF || state == OPAL_PCI_SLOT_OFFLINE) | ||
321 | pnv_php_rmv_devtree(php_slot); | ||
322 | else | ||
323 | ret = pnv_php_add_devtree(php_slot); | ||
324 | |||
325 | return ret; | ||
326 | } | ||
327 | EXPORT_SYMBOL_GPL(pnv_php_set_slot_power_state); | ||
328 | |||
329 | static int pnv_php_get_power_state(struct hotplug_slot *slot, u8 *state) | ||
330 | { | ||
331 | struct pnv_php_slot *php_slot = slot->private; | ||
332 | uint8_t power_state = OPAL_PCI_SLOT_POWER_ON; | ||
333 | int ret; | ||
334 | |||
335 | /* | ||
336 | * Retrieve power status from firmware. If we fail | ||
337 | * getting that, the power status fails back to | ||
338 | * be on. | ||
339 | */ | ||
340 | ret = pnv_pci_get_power_state(php_slot->id, &power_state); | ||
341 | if (unlikely(ret)) { | ||
342 | dev_warn(&php_slot->pdev->dev, "Error %d getting power status\n", | ||
343 | ret); | ||
344 | } else { | ||
345 | *state = power_state; | ||
346 | slot->info->power_status = power_state; | ||
347 | } | ||
348 | |||
349 | return 0; | ||
350 | } | ||
351 | |||
352 | static int pnv_php_get_adapter_state(struct hotplug_slot *slot, u8 *state) | ||
353 | { | ||
354 | struct pnv_php_slot *php_slot = slot->private; | ||
355 | uint8_t presence = OPAL_PCI_SLOT_EMPTY; | ||
356 | int ret; | ||
357 | |||
358 | /* | ||
359 | * Retrieve presence status from firmware. If we can't | ||
360 | * get that, it will fail back to be empty. | ||
361 | */ | ||
362 | ret = pnv_pci_get_presence_state(php_slot->id, &presence); | ||
363 | if (likely(ret >= 0)) { | ||
364 | *state = presence; | ||
365 | slot->info->adapter_status = presence; | ||
366 | ret = 0; | ||
367 | } else { | ||
368 | dev_warn(&php_slot->pdev->dev, "Error %d getting presence\n", | ||
369 | ret); | ||
370 | } | ||
371 | |||
372 | return ret; | ||
373 | } | ||
374 | |||
375 | static int pnv_php_set_attention_state(struct hotplug_slot *slot, u8 state) | ||
376 | { | ||
377 | /* FIXME: Make it real once firmware supports it */ | ||
378 | slot->info->attention_status = state; | ||
379 | |||
380 | return 0; | ||
381 | } | ||
382 | |||
383 | static int pnv_php_enable(struct pnv_php_slot *php_slot, bool rescan) | ||
384 | { | ||
385 | struct hotplug_slot *slot = &php_slot->slot; | ||
386 | uint8_t presence = OPAL_PCI_SLOT_EMPTY; | ||
387 | uint8_t power_status = OPAL_PCI_SLOT_POWER_ON; | ||
388 | int ret; | ||
389 | |||
390 | /* Check if the slot has been configured */ | ||
391 | if (php_slot->state != PNV_PHP_STATE_REGISTERED) | ||
392 | return 0; | ||
393 | |||
394 | /* Retrieve slot presence status */ | ||
395 | ret = pnv_php_get_adapter_state(slot, &presence); | ||
396 | if (unlikely(ret)) | ||
397 | return ret; | ||
398 | |||
399 | /* Proceed if there have nothing behind the slot */ | ||
400 | if (presence == OPAL_PCI_SLOT_EMPTY) | ||
401 | goto scan; | ||
402 | |||
403 | /* | ||
404 | * If the power supply to the slot is off, we can't detect | ||
405 | * adapter presence state. That means we have to turn the | ||
406 | * slot on before going to probe slot's presence state. | ||
407 | * | ||
408 | * On the first time, we don't change the power status to | ||
409 | * boost system boot with assumption that the firmware | ||
410 | * supplies consistent slot power status: empty slot always | ||
411 | * has its power off and non-empty slot has its power on. | ||
412 | */ | ||
413 | if (!php_slot->power_state_check) { | ||
414 | php_slot->power_state_check = true; | ||
415 | |||
416 | ret = pnv_php_get_power_state(slot, &power_status); | ||
417 | if (unlikely(ret)) | ||
418 | return ret; | ||
419 | |||
420 | if (power_status != OPAL_PCI_SLOT_POWER_ON) | ||
421 | return 0; | ||
422 | } | ||
423 | |||
424 | /* Check the power status. Scan the slot if it is already on */ | ||
425 | ret = pnv_php_get_power_state(slot, &power_status); | ||
426 | if (unlikely(ret)) | ||
427 | return ret; | ||
428 | |||
429 | if (power_status == OPAL_PCI_SLOT_POWER_ON) | ||
430 | goto scan; | ||
431 | |||
432 | /* Power is off, turn it on and then scan the slot */ | ||
433 | ret = pnv_php_set_slot_power_state(slot, OPAL_PCI_SLOT_POWER_ON); | ||
434 | if (unlikely(ret)) | ||
435 | return ret; | ||
436 | |||
437 | scan: | ||
438 | if (presence == OPAL_PCI_SLOT_PRESENT) { | ||
439 | if (rescan) { | ||
440 | pci_lock_rescan_remove(); | ||
441 | pci_hp_add_devices(php_slot->bus); | ||
442 | pci_unlock_rescan_remove(); | ||
443 | } | ||
444 | |||
445 | /* Rescan for child hotpluggable slots */ | ||
446 | php_slot->state = PNV_PHP_STATE_POPULATED; | ||
447 | if (rescan) | ||
448 | pnv_php_register(php_slot->dn); | ||
449 | } else { | ||
450 | php_slot->state = PNV_PHP_STATE_POPULATED; | ||
451 | } | ||
452 | |||
453 | return 0; | ||
454 | } | ||
455 | |||
456 | static int pnv_php_enable_slot(struct hotplug_slot *slot) | ||
457 | { | ||
458 | struct pnv_php_slot *php_slot = container_of(slot, | ||
459 | struct pnv_php_slot, slot); | ||
460 | |||
461 | return pnv_php_enable(php_slot, true); | ||
462 | } | ||
463 | |||
464 | static int pnv_php_disable_slot(struct hotplug_slot *slot) | ||
465 | { | ||
466 | struct pnv_php_slot *php_slot = slot->private; | ||
467 | int ret; | ||
468 | |||
469 | if (php_slot->state != PNV_PHP_STATE_POPULATED) | ||
470 | return 0; | ||
471 | |||
472 | /* Remove all devices behind the slot */ | ||
473 | pci_lock_rescan_remove(); | ||
474 | pci_hp_remove_devices(php_slot->bus); | ||
475 | pci_unlock_rescan_remove(); | ||
476 | |||
477 | /* Detach the child hotpluggable slots */ | ||
478 | pnv_php_unregister(php_slot->dn); | ||
479 | |||
480 | /* Notify firmware and remove device nodes */ | ||
481 | ret = pnv_php_set_slot_power_state(slot, OPAL_PCI_SLOT_POWER_OFF); | ||
482 | |||
483 | php_slot->state = PNV_PHP_STATE_REGISTERED; | ||
484 | return ret; | ||
485 | } | ||
486 | |||
487 | static struct hotplug_slot_ops php_slot_ops = { | ||
488 | .get_power_status = pnv_php_get_power_state, | ||
489 | .get_adapter_status = pnv_php_get_adapter_state, | ||
490 | .set_attention_status = pnv_php_set_attention_state, | ||
491 | .enable_slot = pnv_php_enable_slot, | ||
492 | .disable_slot = pnv_php_disable_slot, | ||
493 | }; | ||
494 | |||
495 | static void pnv_php_release(struct hotplug_slot *slot) | ||
496 | { | ||
497 | struct pnv_php_slot *php_slot = slot->private; | ||
498 | unsigned long flags; | ||
499 | |||
500 | /* Remove from global or child list */ | ||
501 | spin_lock_irqsave(&pnv_php_lock, flags); | ||
502 | list_del(&php_slot->link); | ||
503 | spin_unlock_irqrestore(&pnv_php_lock, flags); | ||
504 | |||
505 | /* Detach from parent */ | ||
506 | pnv_php_put_slot(php_slot); | ||
507 | pnv_php_put_slot(php_slot->parent); | ||
508 | } | ||
509 | |||
510 | static struct pnv_php_slot *pnv_php_alloc_slot(struct device_node *dn) | ||
511 | { | ||
512 | struct pnv_php_slot *php_slot; | ||
513 | struct pci_bus *bus; | ||
514 | const char *label; | ||
515 | uint64_t id; | ||
516 | |||
517 | label = of_get_property(dn, "ibm,slot-label", NULL); | ||
518 | if (unlikely(!label)) | ||
519 | return NULL; | ||
520 | |||
521 | if (pnv_pci_get_slot_id(dn, &id)) | ||
522 | return NULL; | ||
523 | |||
524 | bus = pci_find_bus_by_node(dn); | ||
525 | if (unlikely(!bus)) | ||
526 | return NULL; | ||
527 | |||
528 | php_slot = kzalloc(sizeof(*php_slot), GFP_KERNEL); | ||
529 | if (unlikely(!php_slot)) | ||
530 | return NULL; | ||
531 | |||
532 | php_slot->name = kstrdup(label, GFP_KERNEL); | ||
533 | if (unlikely(!php_slot->name)) { | ||
534 | kfree(php_slot); | ||
535 | return NULL; | ||
536 | } | ||
537 | |||
538 | if (likely(dn->child && PCI_DN(dn->child))) | ||
539 | php_slot->slot_no = PCI_SLOT(PCI_DN(dn->child)->devfn); | ||
540 | else | ||
541 | php_slot->slot_no = -1; /* Placeholder slot */ | ||
542 | |||
543 | kref_init(&php_slot->kref); | ||
544 | php_slot->state = PNV_PHP_STATE_INITIALIZED; | ||
545 | php_slot->dn = dn; | ||
546 | php_slot->pdev = bus->self; | ||
547 | php_slot->bus = bus; | ||
548 | php_slot->id = id; | ||
549 | php_slot->power_state_check = false; | ||
550 | php_slot->slot.ops = &php_slot_ops; | ||
551 | php_slot->slot.info = &php_slot->slot_info; | ||
552 | php_slot->slot.release = pnv_php_release; | ||
553 | php_slot->slot.private = php_slot; | ||
554 | |||
555 | INIT_LIST_HEAD(&php_slot->children); | ||
556 | INIT_LIST_HEAD(&php_slot->link); | ||
557 | |||
558 | return php_slot; | ||
559 | } | ||
560 | |||
561 | static int pnv_php_register_slot(struct pnv_php_slot *php_slot) | ||
562 | { | ||
563 | struct pnv_php_slot *parent; | ||
564 | struct device_node *dn = php_slot->dn; | ||
565 | unsigned long flags; | ||
566 | int ret; | ||
567 | |||
568 | /* Check if the slot is registered or not */ | ||
569 | parent = pnv_php_find_slot(php_slot->dn); | ||
570 | if (unlikely(parent)) { | ||
571 | pnv_php_put_slot(parent); | ||
572 | return -EEXIST; | ||
573 | } | ||
574 | |||
575 | /* Register PCI slot */ | ||
576 | ret = pci_hp_register(&php_slot->slot, php_slot->bus, | ||
577 | php_slot->slot_no, php_slot->name); | ||
578 | if (unlikely(ret)) { | ||
579 | dev_warn(&php_slot->pdev->dev, "Error %d registering slot\n", | ||
580 | ret); | ||
581 | return ret; | ||
582 | } | ||
583 | |||
584 | /* Attach to the parent's child list or global list */ | ||
585 | while ((dn = of_get_parent(dn))) { | ||
586 | if (!PCI_DN(dn)) { | ||
587 | of_node_put(dn); | ||
588 | break; | ||
589 | } | ||
590 | |||
591 | parent = pnv_php_find_slot(dn); | ||
592 | if (parent) { | ||
593 | of_node_put(dn); | ||
594 | break; | ||
595 | } | ||
596 | |||
597 | of_node_put(dn); | ||
598 | } | ||
599 | |||
600 | spin_lock_irqsave(&pnv_php_lock, flags); | ||
601 | php_slot->parent = parent; | ||
602 | if (parent) | ||
603 | list_add_tail(&php_slot->link, &parent->children); | ||
604 | else | ||
605 | list_add_tail(&php_slot->link, &pnv_php_slot_list); | ||
606 | spin_unlock_irqrestore(&pnv_php_lock, flags); | ||
607 | |||
608 | php_slot->state = PNV_PHP_STATE_REGISTERED; | ||
609 | return 0; | ||
610 | } | ||
611 | |||
612 | static int pnv_php_register_one(struct device_node *dn) | ||
613 | { | ||
614 | struct pnv_php_slot *php_slot; | ||
615 | const __be32 *prop32; | ||
616 | int ret; | ||
617 | |||
618 | /* Check if it's hotpluggable slot */ | ||
619 | prop32 = of_get_property(dn, "ibm,slot-pluggable", NULL); | ||
620 | if (!prop32 || !of_read_number(prop32, 1)) | ||
621 | return -ENXIO; | ||
622 | |||
623 | prop32 = of_get_property(dn, "ibm,reset-by-firmware", NULL); | ||
624 | if (!prop32 || !of_read_number(prop32, 1)) | ||
625 | return -ENXIO; | ||
626 | |||
627 | php_slot = pnv_php_alloc_slot(dn); | ||
628 | if (unlikely(!php_slot)) | ||
629 | return -ENODEV; | ||
630 | |||
631 | ret = pnv_php_register_slot(php_slot); | ||
632 | if (unlikely(ret)) | ||
633 | goto free_slot; | ||
634 | |||
635 | ret = pnv_php_enable(php_slot, false); | ||
636 | if (unlikely(ret)) | ||
637 | goto unregister_slot; | ||
638 | |||
639 | return 0; | ||
640 | |||
641 | unregister_slot: | ||
642 | pnv_php_unregister_one(php_slot->dn); | ||
643 | free_slot: | ||
644 | pnv_php_put_slot(php_slot); | ||
645 | return ret; | ||
646 | } | ||
647 | |||
648 | static void pnv_php_register(struct device_node *dn) | ||
649 | { | ||
650 | struct device_node *child; | ||
651 | |||
652 | /* | ||
653 | * The parent slots should be registered before their | ||
654 | * child slots. | ||
655 | */ | ||
656 | for_each_child_of_node(dn, child) { | ||
657 | pnv_php_register_one(child); | ||
658 | pnv_php_register(child); | ||
659 | } | ||
660 | } | ||
661 | |||
662 | static void pnv_php_unregister_one(struct device_node *dn) | ||
663 | { | ||
664 | struct pnv_php_slot *php_slot; | ||
665 | |||
666 | php_slot = pnv_php_find_slot(dn); | ||
667 | if (!php_slot) | ||
668 | return; | ||
669 | |||
670 | php_slot->state = PNV_PHP_STATE_OFFLINE; | ||
671 | pnv_php_put_slot(php_slot); | ||
672 | pci_hp_deregister(&php_slot->slot); | ||
673 | } | ||
674 | |||
675 | static void pnv_php_unregister(struct device_node *dn) | ||
676 | { | ||
677 | struct device_node *child; | ||
678 | |||
679 | /* The child slots should go before their parent slots */ | ||
680 | for_each_child_of_node(dn, child) { | ||
681 | pnv_php_unregister(child); | ||
682 | pnv_php_unregister_one(child); | ||
683 | } | ||
684 | } | ||
685 | |||
686 | static int __init pnv_php_init(void) | ||
687 | { | ||
688 | struct device_node *dn; | ||
689 | |||
690 | pr_info(DRIVER_DESC " version: " DRIVER_VERSION "\n"); | ||
691 | for_each_compatible_node(dn, NULL, "ibm,ioda2-phb") | ||
692 | pnv_php_register(dn); | ||
693 | |||
694 | return 0; | ||
695 | } | ||
696 | |||
697 | static void __exit pnv_php_exit(void) | ||
698 | { | ||
699 | struct device_node *dn; | ||
700 | |||
701 | for_each_compatible_node(dn, NULL, "ibm,ioda2-phb") | ||
702 | pnv_php_unregister(dn); | ||
703 | } | ||
704 | |||
705 | module_init(pnv_php_init); | ||
706 | module_exit(pnv_php_exit); | ||
707 | |||
708 | MODULE_VERSION(DRIVER_VERSION); | ||
709 | MODULE_LICENSE("GPL v2"); | ||
710 | MODULE_AUTHOR(DRIVER_AUTHOR); | ||
711 | MODULE_DESCRIPTION(DRIVER_DESC); | ||