Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 2 | /* |
| 3 | * The file intends to implement dynamic creation of EEH device, which will |
| 4 | * be bound with OF node and PCI device simutaneously. The EEH devices would |
| 5 | * be foundamental information for EEH core components to work proerly. Besides, |
| 6 | * We have to support multiple situations where dynamic creation of EEH device |
| 7 | * is required: |
| 8 | * |
| 9 | * 1) Before PCI emunation starts, we need create EEH devices according to the |
| 10 | * PCI sensitive OF nodes. |
| 11 | * 2) When PCI emunation is done, we need do the binding between PCI device and |
| 12 | * the associated EEH device. |
| 13 | * 3) DR (Dynamic Reconfiguration) would create PCI sensitive OF node. EEH device |
| 14 | * will be created while PCI sensitive OF node is detected from DR. |
| 15 | * 4) PCI hotplug needs redoing the binding between PCI device and EEH device. If |
| 16 | * PHB is newly inserted, we also need create EEH devices accordingly. |
| 17 | * |
| 18 | * Copyright Benjamin Herrenschmidt & Gavin Shan, IBM Corporation 2012. |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <linux/export.h> |
| 22 | #include <linux/gfp.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/string.h> |
| 27 | |
| 28 | #include <asm/pci-bridge.h> |
| 29 | #include <asm/ppc-pci.h> |
| 30 | |
| 31 | /** |
| 32 | * eeh_dev_init - Create EEH device according to OF node |
Gavin Shan | e8e9b34 | 2015-03-17 16:15:05 +1100 | [diff] [blame] | 33 | * @pdn: PCI device node |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 34 | * |
| 35 | * It will create EEH device according to the given OF node. The function |
| 36 | * might be called by PCI emunation, DR, PHB hotplug. |
| 37 | */ |
Gavin Shan | 8cc7581 | 2016-05-20 16:41:37 +1000 | [diff] [blame] | 38 | struct eeh_dev *eeh_dev_init(struct pci_dn *pdn) |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 39 | { |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 40 | struct eeh_dev *edev; |
| 41 | |
| 42 | /* Allocate EEH device */ |
Gavin Shan | 7e4bbaf | 2012-09-07 22:44:03 +0000 | [diff] [blame] | 43 | edev = kzalloc(sizeof(*edev), GFP_KERNEL); |
Markus Elfring | 6ab4116 | 2017-08-04 16:37:56 +0200 | [diff] [blame] | 44 | if (!edev) |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 45 | return NULL; |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 46 | |
| 47 | /* Associate EEH device with OF node */ |
Gavin Shan | e8e9b34 | 2015-03-17 16:15:05 +1100 | [diff] [blame] | 48 | pdn->edev = edev; |
| 49 | edev->pdn = pdn; |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 50 | |
Gavin Shan | 8cc7581 | 2016-05-20 16:41:37 +1000 | [diff] [blame] | 51 | return edev; |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * eeh_dev_phb_init_dynamic - Create EEH devices for devices included in PHB |
| 56 | * @phb: PHB |
| 57 | * |
| 58 | * Scan the PHB OF node and its child association, then create the |
| 59 | * EEH devices accordingly |
| 60 | */ |
Greg Kroah-Hartman | cad5cef | 2012-12-21 14:04:10 -0800 | [diff] [blame] | 61 | void eeh_dev_phb_init_dynamic(struct pci_controller *phb) |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 62 | { |
Gavin Shan | 55037d1 | 2012-09-07 22:44:07 +0000 | [diff] [blame] | 63 | /* EEH PE for PHB */ |
| 64 | eeh_phb_pe_create(phb); |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 65 | } |