Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * The file intends to implement dynamic creation of EEH device, which will |
| 3 | * be bound with OF node and PCI device simutaneously. The EEH devices would |
| 4 | * be foundamental information for EEH core components to work proerly. Besides, |
| 5 | * We have to support multiple situations where dynamic creation of EEH device |
| 6 | * is required: |
| 7 | * |
| 8 | * 1) Before PCI emunation starts, we need create EEH devices according to the |
| 9 | * PCI sensitive OF nodes. |
| 10 | * 2) When PCI emunation is done, we need do the binding between PCI device and |
| 11 | * the associated EEH device. |
| 12 | * 3) DR (Dynamic Reconfiguration) would create PCI sensitive OF node. EEH device |
| 13 | * will be created while PCI sensitive OF node is detected from DR. |
| 14 | * 4) PCI hotplug needs redoing the binding between PCI device and EEH device. If |
| 15 | * PHB is newly inserted, we also need create EEH devices accordingly. |
| 16 | * |
| 17 | * Copyright Benjamin Herrenschmidt & Gavin Shan, IBM Corporation 2012. |
| 18 | * |
| 19 | * This program is free software; you can redistribute it and/or modify |
| 20 | * it under the terms of the GNU General Public License as published by |
| 21 | * the Free Software Foundation; either version 2 of the License, or |
| 22 | * (at your option) any later version. |
| 23 | * |
| 24 | * This program is distributed in the hope that it will be useful, |
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 | * GNU General Public License for more details. |
| 28 | * |
| 29 | * You should have received a copy of the GNU General Public License |
| 30 | * along with this program; if not, write to the Free Software |
| 31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 32 | */ |
| 33 | |
| 34 | #include <linux/export.h> |
| 35 | #include <linux/gfp.h> |
| 36 | #include <linux/init.h> |
| 37 | #include <linux/kernel.h> |
| 38 | #include <linux/pci.h> |
| 39 | #include <linux/string.h> |
| 40 | |
| 41 | #include <asm/pci-bridge.h> |
| 42 | #include <asm/ppc-pci.h> |
| 43 | |
| 44 | /** |
| 45 | * eeh_dev_init - Create EEH device according to OF node |
| 46 | * @dn: device node |
| 47 | * @data: PHB |
| 48 | * |
| 49 | * It will create EEH device according to the given OF node. The function |
| 50 | * might be called by PCI emunation, DR, PHB hotplug. |
| 51 | */ |
Greg Kroah-Hartman | cad5cef | 2012-12-21 14:04:10 -0800 | [diff] [blame] | 52 | void *eeh_dev_init(struct device_node *dn, void *data) |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 53 | { |
| 54 | struct pci_controller *phb = data; |
| 55 | struct eeh_dev *edev; |
| 56 | |
| 57 | /* Allocate EEH device */ |
Gavin Shan | 7e4bbaf | 2012-09-07 22:44:03 +0000 | [diff] [blame] | 58 | edev = kzalloc(sizeof(*edev), GFP_KERNEL); |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 59 | if (!edev) { |
| 60 | pr_warning("%s: out of memory\n", __func__); |
| 61 | return NULL; |
| 62 | } |
| 63 | |
| 64 | /* Associate EEH device with OF node */ |
Gavin Shan | 2a0352f | 2012-03-20 21:30:27 +0000 | [diff] [blame] | 65 | PCI_DN(dn)->edev = edev; |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 66 | edev->dn = dn; |
| 67 | edev->phb = phb; |
Gavin Shan | 55037d1 | 2012-09-07 22:44:07 +0000 | [diff] [blame] | 68 | INIT_LIST_HEAD(&edev->list); |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 69 | |
| 70 | return NULL; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * eeh_dev_phb_init_dynamic - Create EEH devices for devices included in PHB |
| 75 | * @phb: PHB |
| 76 | * |
| 77 | * Scan the PHB OF node and its child association, then create the |
| 78 | * EEH devices accordingly |
| 79 | */ |
Greg Kroah-Hartman | cad5cef | 2012-12-21 14:04:10 -0800 | [diff] [blame] | 80 | void eeh_dev_phb_init_dynamic(struct pci_controller *phb) |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 81 | { |
| 82 | struct device_node *dn = phb->dn; |
| 83 | |
Gavin Shan | 55037d1 | 2012-09-07 22:44:07 +0000 | [diff] [blame] | 84 | /* EEH PE for PHB */ |
| 85 | eeh_phb_pe_create(phb); |
| 86 | |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 87 | /* EEH device for PHB */ |
| 88 | eeh_dev_init(dn, phb); |
| 89 | |
| 90 | /* EEH devices for children OF nodes */ |
| 91 | traverse_pci_devices(dn, eeh_dev_init, phb); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * eeh_dev_phb_init - Create EEH devices for devices included in existing PHBs |
| 96 | * |
| 97 | * Scan all the existing PHBs and create EEH devices for their OF |
| 98 | * nodes and their children OF nodes |
| 99 | */ |
Gavin Shan | 35e5cfe | 2012-09-07 22:44:02 +0000 | [diff] [blame] | 100 | static int __init eeh_dev_phb_init(void) |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 101 | { |
| 102 | struct pci_controller *phb, *tmp; |
| 103 | |
| 104 | list_for_each_entry_safe(phb, tmp, &hose_list, list_node) |
| 105 | eeh_dev_phb_init_dynamic(phb); |
Gavin Shan | 35e5cfe | 2012-09-07 22:44:02 +0000 | [diff] [blame] | 106 | |
Gavin Shan | 3ea1ae9 | 2012-09-07 22:44:04 +0000 | [diff] [blame] | 107 | pr_info("EEH: devices created\n"); |
| 108 | |
Gavin Shan | 35e5cfe | 2012-09-07 22:44:02 +0000 | [diff] [blame] | 109 | return 0; |
Gavin Shan | eb740b5 | 2012-02-27 20:04:04 +0000 | [diff] [blame] | 110 | } |
Gavin Shan | 35e5cfe | 2012-09-07 22:44:02 +0000 | [diff] [blame] | 111 | |
| 112 | core_initcall(eeh_dev_phb_init); |