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