···339339340340source "drivers/pci/Kconfig"341341342342+config HOTPLUG343343+ bool "Support for hot-pluggable devices"344344+ ---help---345345+ Say Y here if you want to plug devices into your computer while346346+ the system is running, and be able to use them quickly. In many347347+ cases, the devices can likewise be unplugged at any time too.348348+ One well-known example of this is USB.349349+342350source "drivers/pci/hotplug/Kconfig"343351344352endmenu
+2-1
arch/tile/include/asm/pci.h
···4646 */4747#define PCI_DMA_BUS_IS_PHYS 148484949-int __init tile_pci_init(void);4949+int __devinit tile_pci_init(void);5050+int __devinit pcibios_init(void);50515152void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);5253static inline void pci_iounmap(struct pci_dev *dev, void __iomem *addr) {}
+119-92
arch/tile/kernel/pci.c
···11/*22- * Copyright 2010 Tilera Corporation. All Rights Reserved.22+ * Copyright 2011 Tilera Corporation. All Rights Reserved.33 *44 * This program is free software; you can redistribute it and/or55 * modify it under the terms of the GNU General Public License···59596060static struct pci_controller controllers[TILE_NUM_PCIE];6161static int num_controllers;6262+static int pci_scan_flags[TILE_NUM_PCIE];62636364static struct pci_ops tile_cfg_ops;6465···8079 * controller_id is the controller number, config type is 0 or 1 for8180 * config0 or config1 operations.8281 */8383-static int __init tile_pcie_open(int controller_id, int config_type)8282+static int __devinit tile_pcie_open(int controller_id, int config_type)8483{8584 char filename[32];8685 int fd;···9695/*9796 * Get the IRQ numbers from the HV and set up the handlers for them.9897 */9999-static int __init tile_init_irqs(int controller_id,9898+static int __devinit tile_init_irqs(int controller_id,10099 struct pci_controller *controller)101100{102101 char filename[32];···140139 *141140 * Returns the number of controllers discovered.142141 */143143-int __init tile_pci_init(void)142142+int __devinit tile_pci_init(void)144143{145144 int i;146145147146 pr_info("PCI: Searching for controllers...\n");148147148148+ /* Re-init number of PCIe controllers to support hot-plug feature. */149149+ num_controllers = 0;150150+149151 /* Do any configuration we need before using the PCIe */150152151153 for (i = 0; i < TILE_NUM_PCIE; i++) {152152- int hv_cfg_fd0 = -1;153153- int hv_cfg_fd1 = -1;154154- int hv_mem_fd = -1;155155- char name[32];156156- struct pci_controller *controller;157157-158154 /*159159- * Open the fd to the HV. If it fails then this160160- * device doesn't exist.155155+ * To see whether we need a real config op based on156156+ * the results of pcibios_init(), to support PCIe hot-plug.161157 */162162- hv_cfg_fd0 = tile_pcie_open(i, 0);163163- if (hv_cfg_fd0 < 0)158158+ if (pci_scan_flags[i] == 0) {159159+ int hv_cfg_fd0 = -1;160160+ int hv_cfg_fd1 = -1;161161+ int hv_mem_fd = -1;162162+ char name[32];163163+ struct pci_controller *controller;164164+165165+ /*166166+ * Open the fd to the HV. If it fails then this167167+ * device doesn't exist.168168+ */169169+ hv_cfg_fd0 = tile_pcie_open(i, 0);170170+ if (hv_cfg_fd0 < 0)171171+ continue;172172+ hv_cfg_fd1 = tile_pcie_open(i, 1);173173+ if (hv_cfg_fd1 < 0) {174174+ pr_err("PCI: Couldn't open config fd to HV "175175+ "for controller %d\n", i);176176+ goto err_cont;177177+ }178178+179179+ sprintf(name, "pcie/%d/mem", i);180180+ hv_mem_fd = hv_dev_open((HV_VirtAddr)name, 0);181181+ if (hv_mem_fd < 0) {182182+ pr_err("PCI: Could not open mem fd to HV!\n");183183+ goto err_cont;184184+ }185185+186186+ pr_info("PCI: Found PCI controller #%d\n", i);187187+188188+ controller = &controllers[i];189189+190190+ if (tile_init_irqs(i, controller)) {191191+ pr_err("PCI: Could not initialize "192192+ "IRQs, aborting.\n");193193+ goto err_cont;194194+ }195195+196196+ controller->index = i;197197+ controller->hv_cfg_fd[0] = hv_cfg_fd0;198198+ controller->hv_cfg_fd[1] = hv_cfg_fd1;199199+ controller->hv_mem_fd = hv_mem_fd;200200+ controller->first_busno = 0;201201+ controller->last_busno = 0xff;202202+ controller->ops = &tile_cfg_ops;203203+204204+ num_controllers++;164205 continue;165165- hv_cfg_fd1 = tile_pcie_open(i, 1);166166- if (hv_cfg_fd1 < 0) {167167- pr_err("PCI: Couldn't open config fd to HV "168168- "for controller %d\n", i);169169- goto err_cont;170170- }171171-172172- sprintf(name, "pcie/%d/mem", i);173173- hv_mem_fd = hv_dev_open((HV_VirtAddr)name, 0);174174- if (hv_mem_fd < 0) {175175- pr_err("PCI: Could not open mem fd to HV!\n");176176- goto err_cont;177177- }178178-179179- pr_info("PCI: Found PCI controller #%d\n", i);180180-181181- controller = &controllers[num_controllers];182182-183183- if (tile_init_irqs(i, controller)) {184184- pr_err("PCI: Could not initialize "185185- "IRQs, aborting.\n");186186- goto err_cont;187187- }188188-189189- controller->index = num_controllers;190190- controller->hv_cfg_fd[0] = hv_cfg_fd0;191191- controller->hv_cfg_fd[1] = hv_cfg_fd1;192192- controller->hv_mem_fd = hv_mem_fd;193193- controller->first_busno = 0;194194- controller->last_busno = 0xff;195195- controller->ops = &tile_cfg_ops;196196-197197- num_controllers++;198198- continue;199206200207err_cont:201201- if (hv_cfg_fd0 >= 0)202202- hv_dev_close(hv_cfg_fd0);203203- if (hv_cfg_fd1 >= 0)204204- hv_dev_close(hv_cfg_fd1);205205- if (hv_mem_fd >= 0)206206- hv_dev_close(hv_mem_fd);207207- continue;208208+ if (hv_cfg_fd0 >= 0)209209+ hv_dev_close(hv_cfg_fd0);210210+ if (hv_cfg_fd1 >= 0)211211+ hv_dev_close(hv_cfg_fd1);212212+ if (hv_mem_fd >= 0)213213+ hv_dev_close(hv_mem_fd);214214+ continue;215215+ }208216 }209217210218 /*···242232}243233244234245245-static void __init fixup_read_and_payload_sizes(void)235235+static void __devinit fixup_read_and_payload_sizes(void)246236{247237 struct pci_dev *dev = NULL;248238 int smallest_max_payload = 0x1; /* Tile maxes out at 256 bytes. */···292282 * The controllers have been set up by the time we get here, by a call to293283 * tile_pci_init.294284 */295295-static int __init pcibios_init(void)285285+int __devinit pcibios_init(void)296286{297287 int i;298288···306296 mdelay(250);307297308298 /* Scan all of the recorded PCI controllers. */309309- for (i = 0; i < num_controllers; i++) {310310- struct pci_controller *controller = &controllers[i];311311- struct pci_bus *bus;312312-313313- pr_info("PCI: initializing controller #%d\n", i);314314-299299+ for (i = 0; i < TILE_NUM_PCIE; i++) {315300 /*316316- * This comes from the generic Linux PCI driver.317317- *318318- * It reads the PCI tree for this bus into the Linux319319- * data structures.320320- *321321- * This is inlined in linux/pci.h and calls into322322- * pci_scan_bus_parented() in probe.c.301301+ * Do real pcibios init ops if the controller is initialized302302+ * by tile_pci_init() successfully and not initialized by303303+ * pcibios_init() yet to support PCIe hot-plug.323304 */324324- bus = pci_scan_bus(0, controller->ops, controller);325325- controller->root_bus = bus;326326- controller->last_busno = bus->subordinate;305305+ if (pci_scan_flags[i] == 0 && controllers[i].ops != NULL) {306306+ struct pci_controller *controller = &controllers[i];307307+ struct pci_bus *bus;327308309309+ pr_info("PCI: initializing controller #%d\n", i);310310+311311+ /*312312+ * This comes from the generic Linux PCI driver.313313+ *314314+ * It reads the PCI tree for this bus into the Linux315315+ * data structures.316316+ *317317+ * This is inlined in linux/pci.h and calls into318318+ * pci_scan_bus_parented() in probe.c.319319+ */320320+ bus = pci_scan_bus(0, controller->ops, controller);321321+ controller->root_bus = bus;322322+ controller->last_busno = bus->subordinate;323323+ }328324 }329325330326 /* Do machine dependent PCI interrupt routing */···342326 * It allocates all of the resources (I/O memory, etc)343327 * associated with the devices read in above.344328 */345345-346329 pci_assign_unassigned_resources();347330348331 /* Configure the max_read_size and max_payload_size values. */349332 fixup_read_and_payload_sizes();350333351334 /* Record the I/O resources in the PCI controller structure. */352352- for (i = 0; i < num_controllers; i++) {353353- struct pci_bus *root_bus = controllers[i].root_bus;354354- struct pci_bus *next_bus;355355- struct pci_dev *dev;335335+ for (i = 0; i < TILE_NUM_PCIE; i++) {336336+ /*337337+ * Do real pcibios init ops if the controller is initialized338338+ * by tile_pci_init() successfully and not initialized by339339+ * pcibios_init() yet to support PCIe hot-plug.340340+ */341341+ if (pci_scan_flags[i] == 0 && controllers[i].ops != NULL) {342342+ struct pci_bus *root_bus = controllers[i].root_bus;343343+ struct pci_bus *next_bus;344344+ struct pci_dev *dev;356345357357- list_for_each_entry(dev, &root_bus->devices, bus_list) {358358- /* Find the PCI host controller, ie. the 1st bridge. */359359- if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI &&360360- (PCI_SLOT(dev->devfn) == 0)) {361361- next_bus = dev->subordinate;362362- controllers[i].mem_resources[0] =363363- *next_bus->resource[0];364364- controllers[i].mem_resources[1] =365365- *next_bus->resource[1];366366- controllers[i].mem_resources[2] =367367- *next_bus->resource[2];346346+ list_for_each_entry(dev, &root_bus->devices, bus_list) {347347+ /*348348+ * Find the PCI host controller, ie. the 1st349349+ * bridge.350350+ */351351+ if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI &&352352+ (PCI_SLOT(dev->devfn) == 0)) {353353+ next_bus = dev->subordinate;354354+ controllers[i].mem_resources[0] =355355+ *next_bus->resource[0];356356+ controllers[i].mem_resources[1] =357357+ *next_bus->resource[1];358358+ controllers[i].mem_resources[2] =359359+ *next_bus->resource[2];368360369369- break;361361+ /* Setup flags. */362362+ pci_scan_flags[i] = 1;363363+364364+ break;365365+ }370366 }371367 }372372-373368 }374369375370 return 0;···408381/*409382 * This is called from the generic Linux layer.410383 */411411-void __init pcibios_update_irq(struct pci_dev *dev, int irq)384384+void __devinit pcibios_update_irq(struct pci_dev *dev, int irq)412385{413386 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);414387}