Bjorn Helgaas | 736759e | 2018-01-26 14:22:04 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * CompactPCI Hot Plug Driver PCI functions |
| 4 | * |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 5 | * Copyright (C) 2002,2005 by SOMA Networks, Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * All rights reserved. |
| 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * Send feedback to <scottm@somanetworks.com> |
| 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/module.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/pci.h> |
Greg Kroah-Hartman | 7a54f25 | 2006-10-13 20:05:19 -0700 | [diff] [blame] | 15 | #include <linux/pci_hotplug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/proc_fs.h> |
| 17 | #include "../pci.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "cpci_hotplug.h" |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #define MY_NAME "cpci_hotplug" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #define dbg(format, arg...) \ |
| 23 | do { \ |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 24 | if (cpci_debug) \ |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 25 | printk(KERN_DEBUG "%s: " format "\n", \ |
| 26 | MY_NAME, ## arg); \ |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 27 | } while (0) |
Bogicevic Sasa | ff3ce48 | 2015-12-27 13:21:11 -0800 | [diff] [blame] | 28 | #define err(format, arg...) printk(KERN_ERR "%s: " format "\n", MY_NAME, ## arg) |
| 29 | #define info(format, arg...) printk(KERN_INFO "%s: " format "\n", MY_NAME, ## arg) |
| 30 | #define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n", MY_NAME, ## arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Ryan Desfosses | 3c78bc6 | 2014-04-18 20:13:49 -0400 | [diff] [blame] | 33 | u8 cpci_get_attention_status(struct slot *slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { |
| 35 | int hs_cap; |
| 36 | u16 hs_csr; |
| 37 | |
| 38 | hs_cap = pci_bus_find_capability(slot->bus, |
| 39 | slot->devfn, |
| 40 | PCI_CAP_ID_CHSWP); |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 41 | if (!hs_cap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 44 | if (pci_bus_read_config_word(slot->bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | slot->devfn, |
| 46 | hs_cap + 2, |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 47 | &hs_csr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | return 0; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | return hs_csr & 0x0008 ? 1 : 0; |
| 51 | } |
| 52 | |
Ryan Desfosses | 3c78bc6 | 2014-04-18 20:13:49 -0400 | [diff] [blame] | 53 | int cpci_set_attention_status(struct slot *slot, int status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
| 55 | int hs_cap; |
| 56 | u16 hs_csr; |
| 57 | |
| 58 | hs_cap = pci_bus_find_capability(slot->bus, |
| 59 | slot->devfn, |
| 60 | PCI_CAP_ID_CHSWP); |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 61 | if (!hs_cap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | return 0; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 63 | if (pci_bus_read_config_word(slot->bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | slot->devfn, |
| 65 | hs_cap + 2, |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 66 | &hs_csr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | return 0; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 68 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | hs_csr |= HS_CSR_LOO; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 70 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | hs_csr &= ~HS_CSR_LOO; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 72 | if (pci_bus_write_config_word(slot->bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | slot->devfn, |
| 74 | hs_cap + 2, |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 75 | hs_csr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | return 1; |
| 78 | } |
| 79 | |
Ryan Desfosses | 3c78bc6 | 2014-04-18 20:13:49 -0400 | [diff] [blame] | 80 | u16 cpci_get_hs_csr(struct slot *slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
| 82 | int hs_cap; |
| 83 | u16 hs_csr; |
| 84 | |
| 85 | hs_cap = pci_bus_find_capability(slot->bus, |
| 86 | slot->devfn, |
| 87 | PCI_CAP_ID_CHSWP); |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 88 | if (!hs_cap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | return 0xFFFF; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 90 | if (pci_bus_read_config_word(slot->bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | slot->devfn, |
| 92 | hs_cap + 2, |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 93 | &hs_csr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | return 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | return hs_csr; |
| 96 | } |
| 97 | |
Ryan Desfosses | 3c78bc6 | 2014-04-18 20:13:49 -0400 | [diff] [blame] | 98 | int cpci_check_and_clear_ins(struct slot *slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
| 100 | int hs_cap; |
| 101 | u16 hs_csr; |
| 102 | int ins = 0; |
| 103 | |
| 104 | hs_cap = pci_bus_find_capability(slot->bus, |
| 105 | slot->devfn, |
| 106 | PCI_CAP_ID_CHSWP); |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 107 | if (!hs_cap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | return 0; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 109 | if (pci_bus_read_config_word(slot->bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | slot->devfn, |
| 111 | hs_cap + 2, |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 112 | &hs_csr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | return 0; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 114 | if (hs_csr & HS_CSR_INS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | /* Clear INS (by setting it) */ |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 116 | if (pci_bus_write_config_word(slot->bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | slot->devfn, |
| 118 | hs_cap + 2, |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 119 | hs_csr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | ins = 0; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 121 | else |
| 122 | ins = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | return ins; |
| 125 | } |
| 126 | |
Ryan Desfosses | 3c78bc6 | 2014-04-18 20:13:49 -0400 | [diff] [blame] | 127 | int cpci_check_ext(struct slot *slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
| 129 | int hs_cap; |
| 130 | u16 hs_csr; |
| 131 | int ext = 0; |
| 132 | |
| 133 | hs_cap = pci_bus_find_capability(slot->bus, |
| 134 | slot->devfn, |
| 135 | PCI_CAP_ID_CHSWP); |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 136 | if (!hs_cap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | return 0; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 138 | if (pci_bus_read_config_word(slot->bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | slot->devfn, |
| 140 | hs_cap + 2, |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 141 | &hs_csr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | return 0; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 143 | if (hs_csr & HS_CSR_EXT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | ext = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | return ext; |
| 146 | } |
| 147 | |
Ryan Desfosses | 3c78bc6 | 2014-04-18 20:13:49 -0400 | [diff] [blame] | 148 | int cpci_clear_ext(struct slot *slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | { |
| 150 | int hs_cap; |
| 151 | u16 hs_csr; |
| 152 | |
| 153 | hs_cap = pci_bus_find_capability(slot->bus, |
| 154 | slot->devfn, |
| 155 | PCI_CAP_ID_CHSWP); |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 156 | if (!hs_cap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | return -ENODEV; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 158 | if (pci_bus_read_config_word(slot->bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | slot->devfn, |
| 160 | hs_cap + 2, |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 161 | &hs_csr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | return -ENODEV; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 163 | if (hs_csr & HS_CSR_EXT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | /* Clear EXT (by setting it) */ |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 165 | if (pci_bus_write_config_word(slot->bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | slot->devfn, |
| 167 | hs_cap + 2, |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 168 | hs_csr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | return 0; |
| 172 | } |
| 173 | |
Ryan Desfosses | 3c78bc6 | 2014-04-18 20:13:49 -0400 | [diff] [blame] | 174 | int cpci_led_on(struct slot *slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
| 176 | int hs_cap; |
| 177 | u16 hs_csr; |
| 178 | |
| 179 | hs_cap = pci_bus_find_capability(slot->bus, |
| 180 | slot->devfn, |
| 181 | PCI_CAP_ID_CHSWP); |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 182 | if (!hs_cap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | return -ENODEV; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 184 | if (pci_bus_read_config_word(slot->bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | slot->devfn, |
| 186 | hs_cap + 2, |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 187 | &hs_csr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | return -ENODEV; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 189 | if ((hs_csr & HS_CSR_LOO) != HS_CSR_LOO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | hs_csr |= HS_CSR_LOO; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 191 | if (pci_bus_write_config_word(slot->bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | slot->devfn, |
| 193 | hs_cap + 2, |
| 194 | hs_csr)) { |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 195 | err("Could not set LOO for slot %s", slot_name(slot)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | return -ENODEV; |
| 197 | } |
| 198 | } |
| 199 | return 0; |
| 200 | } |
| 201 | |
Ryan Desfosses | 3c78bc6 | 2014-04-18 20:13:49 -0400 | [diff] [blame] | 202 | int cpci_led_off(struct slot *slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
| 204 | int hs_cap; |
| 205 | u16 hs_csr; |
| 206 | |
| 207 | hs_cap = pci_bus_find_capability(slot->bus, |
| 208 | slot->devfn, |
| 209 | PCI_CAP_ID_CHSWP); |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 210 | if (!hs_cap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | return -ENODEV; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 212 | if (pci_bus_read_config_word(slot->bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | slot->devfn, |
| 214 | hs_cap + 2, |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 215 | &hs_csr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | return -ENODEV; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 217 | if (hs_csr & HS_CSR_LOO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | hs_csr &= ~HS_CSR_LOO; |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 219 | if (pci_bus_write_config_word(slot->bus, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | slot->devfn, |
| 221 | hs_cap + 2, |
| 222 | hs_csr)) { |
Lukas Wunner | 125450f | 2018-09-08 09:59:01 +0200 | [diff] [blame] | 223 | err("Could not clear LOO for slot %s", slot_name(slot)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | return -ENODEV; |
| 225 | } |
| 226 | } |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | |
| 231 | /* |
| 232 | * Device configuration functions |
| 233 | */ |
| 234 | |
Bjorn Helgaas | 10874f5a | 2014-04-14 16:11:40 -0600 | [diff] [blame] | 235 | int cpci_configure_slot(struct slot *slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
Yijing Wang | 05b12500 | 2013-01-15 11:12:20 +0800 | [diff] [blame] | 237 | struct pci_dev *dev; |
Scott Murray | cc702c2 | 2006-08-22 19:55:57 -0400 | [diff] [blame] | 238 | struct pci_bus *parent; |
Rafael J. Wysocki | c4ec84c | 2014-01-14 12:03:14 -0700 | [diff] [blame] | 239 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 241 | dbg("%s - enter", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Rafael J. Wysocki | c4ec84c | 2014-01-14 12:03:14 -0700 | [diff] [blame] | 243 | pci_lock_rescan_remove(); |
| 244 | |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 245 | if (slot->dev == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | dbg("pci_dev null, finding %02x:%02x:%x", |
| 247 | slot->bus->number, PCI_SLOT(slot->devfn), PCI_FUNC(slot->devfn)); |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 248 | slot->dev = pci_get_slot(slot->bus, slot->devfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /* Still NULL? Well then scan for it! */ |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 252 | if (slot->dev == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | int n; |
| 254 | dbg("pci_dev still null"); |
| 255 | |
| 256 | /* |
| 257 | * This will generate pci_dev structures for all functions, but |
| 258 | * we will only call this case when lookup fails. |
| 259 | */ |
| 260 | n = pci_scan_slot(slot->bus, slot->devfn); |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 261 | dbg("%s: pci_scan_slot returned %d", __func__, n); |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 262 | slot->dev = pci_get_slot(slot->bus, slot->devfn); |
| 263 | if (slot->dev == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | err("Could not find PCI device for slot %02x", slot->number); |
Rafael J. Wysocki | c4ec84c | 2014-01-14 12:03:14 -0700 | [diff] [blame] | 265 | ret = -ENODEV; |
| 266 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | } |
| 268 | } |
Scott Murray | cc702c2 | 2006-08-22 19:55:57 -0400 | [diff] [blame] | 269 | parent = slot->dev->bus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
Andy Shevchenko | 24a0c65 | 2017-10-20 15:38:54 -0500 | [diff] [blame] | 271 | for_each_pci_bridge(dev, parent) { |
| 272 | if (PCI_SLOT(dev->devfn) == PCI_SLOT(slot->devfn)) |
Yinghai Lu | 073ae10 | 2012-05-17 18:58:41 -0700 | [diff] [blame] | 273 | pci_hp_add_bridge(dev); |
Dan Carpenter | bc3b5b4 | 2015-02-25 16:23:22 +0300 | [diff] [blame] | 274 | } |
Yijing Wang | 05b12500 | 2013-01-15 11:12:20 +0800 | [diff] [blame] | 275 | |
Yinghai Lu | 073ae10 | 2012-05-17 18:58:41 -0700 | [diff] [blame] | 276 | pci_assign_unassigned_bridge_resources(parent->self); |
| 277 | |
Scott Murray | cc702c2 | 2006-08-22 19:55:57 -0400 | [diff] [blame] | 278 | pci_bus_add_devices(parent); |
Scott Murray | 43b7d7c | 2005-05-09 17:31:50 -0400 | [diff] [blame] | 279 | |
Rafael J. Wysocki | c4ec84c | 2014-01-14 12:03:14 -0700 | [diff] [blame] | 280 | out: |
| 281 | pci_unlock_rescan_remove(); |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 282 | dbg("%s - exit", __func__); |
Rafael J. Wysocki | c4ec84c | 2014-01-14 12:03:14 -0700 | [diff] [blame] | 283 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Ryan Desfosses | 3c78bc6 | 2014-04-18 20:13:49 -0400 | [diff] [blame] | 286 | int cpci_unconfigure_slot(struct slot *slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
Yijing Wang | 05b12500 | 2013-01-15 11:12:20 +0800 | [diff] [blame] | 288 | struct pci_dev *dev, *temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 290 | dbg("%s - enter", __func__); |
Scott Murray | bcc488a | 2005-05-27 16:48:52 -0400 | [diff] [blame] | 291 | if (!slot->dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | err("No device for slot %02x\n", slot->number); |
| 293 | return -ENODEV; |
| 294 | } |
| 295 | |
Rafael J. Wysocki | c4ec84c | 2014-01-14 12:03:14 -0700 | [diff] [blame] | 296 | pci_lock_rescan_remove(); |
| 297 | |
Yijing Wang | 05b12500 | 2013-01-15 11:12:20 +0800 | [diff] [blame] | 298 | list_for_each_entry_safe(dev, temp, &slot->bus->devices, bus_list) { |
| 299 | if (PCI_SLOT(dev->devfn) != PCI_SLOT(slot->devfn)) |
| 300 | continue; |
| 301 | pci_dev_get(dev); |
| 302 | pci_stop_and_remove_bus_device(dev); |
| 303 | pci_dev_put(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
Scott Murray | 03e49d4 | 2005-06-06 15:48:04 -0400 | [diff] [blame] | 305 | pci_dev_put(slot->dev); |
| 306 | slot->dev = NULL; |
| 307 | |
Rafael J. Wysocki | c4ec84c | 2014-01-14 12:03:14 -0700 | [diff] [blame] | 308 | pci_unlock_rescan_remove(); |
| 309 | |
Harvey Harrison | 66bef8c | 2008-03-03 19:09:46 -0800 | [diff] [blame] | 310 | dbg("%s - exit", __func__); |
Scott Murray | 43b7d7c | 2005-05-09 17:31:50 -0400 | [diff] [blame] | 311 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |