Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

arch/tile: improve support for PCI hotplug

Note that this is not complete hot-plug support; hot-unplug is not included.

Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>

+129 -93
+8
arch/tile/Kconfig
··· 339 339 340 340 source "drivers/pci/Kconfig" 341 341 342 + config HOTPLUG 343 + bool "Support for hot-pluggable devices" 344 + ---help--- 345 + Say Y here if you want to plug devices into your computer while 346 + the system is running, and be able to use them quickly. In many 347 + cases, the devices can likewise be unplugged at any time too. 348 + One well-known example of this is USB. 349 + 342 350 source "drivers/pci/hotplug/Kconfig" 343 351 344 352 endmenu
+2 -1
arch/tile/include/asm/pci.h
··· 46 46 */ 47 47 #define PCI_DMA_BUS_IS_PHYS 1 48 48 49 - int __init tile_pci_init(void); 49 + int __devinit tile_pci_init(void); 50 + int __devinit pcibios_init(void); 50 51 51 52 void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max); 52 53 static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr) {}
+119 -92
arch/tile/kernel/pci.c
··· 1 1 /* 2 - * Copyright 2010 Tilera Corporation. All Rights Reserved. 2 + * Copyright 2011 Tilera Corporation. All Rights Reserved. 3 3 * 4 4 * This program is free software; you can redistribute it and/or 5 5 * modify it under the terms of the GNU General Public License ··· 59 59 60 60 static struct pci_controller controllers[TILE_NUM_PCIE]; 61 61 static int num_controllers; 62 + static int pci_scan_flags[TILE_NUM_PCIE]; 62 63 63 64 static struct pci_ops tile_cfg_ops; 64 65 ··· 80 79 * controller_id is the controller number, config type is 0 or 1 for 81 80 * config0 or config1 operations. 82 81 */ 83 - static int __init tile_pcie_open(int controller_id, int config_type) 82 + static int __devinit tile_pcie_open(int controller_id, int config_type) 84 83 { 85 84 char filename[32]; 86 85 int fd; ··· 96 95 /* 97 96 * Get the IRQ numbers from the HV and set up the handlers for them. 98 97 */ 99 - static int __init tile_init_irqs(int controller_id, 98 + static int __devinit tile_init_irqs(int controller_id, 100 99 struct pci_controller *controller) 101 100 { 102 101 char filename[32]; ··· 140 139 * 141 140 * Returns the number of controllers discovered. 142 141 */ 143 - int __init tile_pci_init(void) 142 + int __devinit tile_pci_init(void) 144 143 { 145 144 int i; 146 145 147 146 pr_info("PCI: Searching for controllers...\n"); 148 147 148 + /* Re-init number of PCIe controllers to support hot-plug feature. */ 149 + num_controllers = 0; 150 + 149 151 /* Do any configuration we need before using the PCIe */ 150 152 151 153 for (i = 0; i < TILE_NUM_PCIE; i++) { 152 - int hv_cfg_fd0 = -1; 153 - int hv_cfg_fd1 = -1; 154 - int hv_mem_fd = -1; 155 - char name[32]; 156 - struct pci_controller *controller; 157 - 158 154 /* 159 - * Open the fd to the HV. If it fails then this 160 - * device doesn't exist. 155 + * To see whether we need a real config op based on 156 + * the results of pcibios_init(), to support PCIe hot-plug. 161 157 */ 162 - hv_cfg_fd0 = tile_pcie_open(i, 0); 163 - if (hv_cfg_fd0 < 0) 158 + if (pci_scan_flags[i] == 0) { 159 + int hv_cfg_fd0 = -1; 160 + int hv_cfg_fd1 = -1; 161 + int hv_mem_fd = -1; 162 + char name[32]; 163 + struct pci_controller *controller; 164 + 165 + /* 166 + * Open the fd to the HV. If it fails then this 167 + * device doesn't exist. 168 + */ 169 + hv_cfg_fd0 = tile_pcie_open(i, 0); 170 + if (hv_cfg_fd0 < 0) 171 + continue; 172 + hv_cfg_fd1 = tile_pcie_open(i, 1); 173 + if (hv_cfg_fd1 < 0) { 174 + pr_err("PCI: Couldn't open config fd to HV " 175 + "for controller %d\n", i); 176 + goto err_cont; 177 + } 178 + 179 + sprintf(name, "pcie/%d/mem", i); 180 + hv_mem_fd = hv_dev_open((HV_VirtAddr)name, 0); 181 + if (hv_mem_fd < 0) { 182 + pr_err("PCI: Could not open mem fd to HV!\n"); 183 + goto err_cont; 184 + } 185 + 186 + pr_info("PCI: Found PCI controller #%d\n", i); 187 + 188 + controller = &controllers[i]; 189 + 190 + if (tile_init_irqs(i, controller)) { 191 + pr_err("PCI: Could not initialize " 192 + "IRQs, aborting.\n"); 193 + goto err_cont; 194 + } 195 + 196 + controller->index = i; 197 + controller->hv_cfg_fd[0] = hv_cfg_fd0; 198 + controller->hv_cfg_fd[1] = hv_cfg_fd1; 199 + controller->hv_mem_fd = hv_mem_fd; 200 + controller->first_busno = 0; 201 + controller->last_busno = 0xff; 202 + controller->ops = &tile_cfg_ops; 203 + 204 + num_controllers++; 164 205 continue; 165 - hv_cfg_fd1 = tile_pcie_open(i, 1); 166 - if (hv_cfg_fd1 < 0) { 167 - pr_err("PCI: Couldn't open config fd to HV " 168 - "for controller %d\n", i); 169 - goto err_cont; 170 - } 171 - 172 - sprintf(name, "pcie/%d/mem", i); 173 - hv_mem_fd = hv_dev_open((HV_VirtAddr)name, 0); 174 - if (hv_mem_fd < 0) { 175 - pr_err("PCI: Could not open mem fd to HV!\n"); 176 - goto err_cont; 177 - } 178 - 179 - pr_info("PCI: Found PCI controller #%d\n", i); 180 - 181 - controller = &controllers[num_controllers]; 182 - 183 - if (tile_init_irqs(i, controller)) { 184 - pr_err("PCI: Could not initialize " 185 - "IRQs, aborting.\n"); 186 - goto err_cont; 187 - } 188 - 189 - controller->index = num_controllers; 190 - controller->hv_cfg_fd[0] = hv_cfg_fd0; 191 - controller->hv_cfg_fd[1] = hv_cfg_fd1; 192 - controller->hv_mem_fd = hv_mem_fd; 193 - controller->first_busno = 0; 194 - controller->last_busno = 0xff; 195 - controller->ops = &tile_cfg_ops; 196 - 197 - num_controllers++; 198 - continue; 199 206 200 207 err_cont: 201 - if (hv_cfg_fd0 >= 0) 202 - hv_dev_close(hv_cfg_fd0); 203 - if (hv_cfg_fd1 >= 0) 204 - hv_dev_close(hv_cfg_fd1); 205 - if (hv_mem_fd >= 0) 206 - hv_dev_close(hv_mem_fd); 207 - continue; 208 + if (hv_cfg_fd0 >= 0) 209 + hv_dev_close(hv_cfg_fd0); 210 + if (hv_cfg_fd1 >= 0) 211 + hv_dev_close(hv_cfg_fd1); 212 + if (hv_mem_fd >= 0) 213 + hv_dev_close(hv_mem_fd); 214 + continue; 215 + } 208 216 } 209 217 210 218 /* ··· 242 232 } 243 233 244 234 245 - static void __init fixup_read_and_payload_sizes(void) 235 + static void __devinit fixup_read_and_payload_sizes(void) 246 236 { 247 237 struct pci_dev *dev = NULL; 248 238 int smallest_max_payload = 0x1; /* Tile maxes out at 256 bytes. */ ··· 292 282 * The controllers have been set up by the time we get here, by a call to 293 283 * tile_pci_init. 294 284 */ 295 - static int __init pcibios_init(void) 285 + int __devinit pcibios_init(void) 296 286 { 297 287 int i; 298 288 ··· 306 296 mdelay(250); 307 297 308 298 /* Scan all of the recorded PCI controllers. */ 309 - for (i = 0; i < num_controllers; i++) { 310 - struct pci_controller *controller = &controllers[i]; 311 - struct pci_bus *bus; 312 - 313 - pr_info("PCI: initializing controller #%d\n", i); 314 - 299 + for (i = 0; i < TILE_NUM_PCIE; i++) { 315 300 /* 316 - * This comes from the generic Linux PCI driver. 317 - * 318 - * It reads the PCI tree for this bus into the Linux 319 - * data structures. 320 - * 321 - * This is inlined in linux/pci.h and calls into 322 - * pci_scan_bus_parented() in probe.c. 301 + * Do real pcibios init ops if the controller is initialized 302 + * by tile_pci_init() successfully and not initialized by 303 + * pcibios_init() yet to support PCIe hot-plug. 323 304 */ 324 - bus = pci_scan_bus(0, controller->ops, controller); 325 - controller->root_bus = bus; 326 - controller->last_busno = bus->subordinate; 305 + if (pci_scan_flags[i] == 0 && controllers[i].ops != NULL) { 306 + struct pci_controller *controller = &controllers[i]; 307 + struct pci_bus *bus; 327 308 309 + pr_info("PCI: initializing controller #%d\n", i); 310 + 311 + /* 312 + * This comes from the generic Linux PCI driver. 313 + * 314 + * It reads the PCI tree for this bus into the Linux 315 + * data structures. 316 + * 317 + * This is inlined in linux/pci.h and calls into 318 + * pci_scan_bus_parented() in probe.c. 319 + */ 320 + bus = pci_scan_bus(0, controller->ops, controller); 321 + controller->root_bus = bus; 322 + controller->last_busno = bus->subordinate; 323 + } 328 324 } 329 325 330 326 /* Do machine dependent PCI interrupt routing */ ··· 342 326 * It allocates all of the resources (I/O memory, etc) 343 327 * associated with the devices read in above. 344 328 */ 345 - 346 329 pci_assign_unassigned_resources(); 347 330 348 331 /* Configure the max_read_size and max_payload_size values. */ 349 332 fixup_read_and_payload_sizes(); 350 333 351 334 /* Record the I/O resources in the PCI controller structure. */ 352 - for (i = 0; i < num_controllers; i++) { 353 - struct pci_bus *root_bus = controllers[i].root_bus; 354 - struct pci_bus *next_bus; 355 - struct pci_dev *dev; 335 + for (i = 0; i < TILE_NUM_PCIE; i++) { 336 + /* 337 + * Do real pcibios init ops if the controller is initialized 338 + * by tile_pci_init() successfully and not initialized by 339 + * pcibios_init() yet to support PCIe hot-plug. 340 + */ 341 + if (pci_scan_flags[i] == 0 && controllers[i].ops != NULL) { 342 + struct pci_bus *root_bus = controllers[i].root_bus; 343 + struct pci_bus *next_bus; 344 + struct pci_dev *dev; 356 345 357 - list_for_each_entry(dev, &root_bus->devices, bus_list) { 358 - /* Find the PCI host controller, ie. the 1st bridge. */ 359 - if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI && 360 - (PCI_SLOT(dev->devfn) == 0)) { 361 - next_bus = dev->subordinate; 362 - controllers[i].mem_resources[0] = 363 - *next_bus->resource[0]; 364 - controllers[i].mem_resources[1] = 365 - *next_bus->resource[1]; 366 - controllers[i].mem_resources[2] = 367 - *next_bus->resource[2]; 346 + list_for_each_entry(dev, &root_bus->devices, bus_list) { 347 + /* 348 + * Find the PCI host controller, ie. the 1st 349 + * bridge. 350 + */ 351 + if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI && 352 + (PCI_SLOT(dev->devfn) == 0)) { 353 + next_bus = dev->subordinate; 354 + controllers[i].mem_resources[0] = 355 + *next_bus->resource[0]; 356 + controllers[i].mem_resources[1] = 357 + *next_bus->resource[1]; 358 + controllers[i].mem_resources[2] = 359 + *next_bus->resource[2]; 368 360 369 - break; 361 + /* Setup flags. */ 362 + pci_scan_flags[i] = 1; 363 + 364 + break; 365 + } 370 366 } 371 367 } 372 - 373 368 } 374 369 375 370 return 0; ··· 408 381 /* 409 382 * This is called from the generic Linux layer. 410 383 */ 411 - void __init pcibios_update_irq(struct pci_dev *dev, int irq) 384 + void __devinit pcibios_update_irq(struct pci_dev *dev, int irq) 412 385 { 413 386 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq); 414 387 }