📄 cpqphp_core.c
字号:
ctrl->pcix_speed_capability = 0; } break; default: err(msg_HPC_not_supported); rc = -ENODEV; goto err_free_ctrl; } } else { err(msg_HPC_not_supported); return -ENODEV; } // Tell the user that we found one. info("Initializing the PCI hot plug controller residing on PCI bus %d\n", pdev->bus->number); dbg ("Hotplug controller capabilities:\n"); dbg (" speed_capability %s\n", ctrl->speed_capability == CTRL_SPEED_33MHz ? "33MHz" : "66Mhz"); dbg (" slot_switch_type %s\n", ctrl->slot_switch_type == 0 ? "no switch" : "switch present"); dbg (" defeature_PHP %s\n", ctrl->defeature_PHP == 0 ? "PHP not supported" : "PHP supported"); dbg (" alternate_base_address %s\n", ctrl->alternate_base_address == 0 ? "not supported" : "supported"); dbg (" pci_config_space %s\n", ctrl->pci_config_space == 0 ? "not supported" : "supported"); dbg (" pcix_speed_capability %s\n", ctrl->pcix_speed_capability == 0 ? "not supported" : "supported"); dbg (" pcix_support %s\n", ctrl->pcix_support == 0 ? "not supported" : "supported"); ctrl->pci_dev = pdev; ctrl->pci_ops = pdev->bus->ops; ctrl->bus = pdev->bus->number; ctrl->device = PCI_SLOT(pdev->devfn); ctrl->function = PCI_FUNC(pdev->devfn); ctrl->rev = rev; dbg("bus device function rev: %d %d %d %d\n", ctrl->bus, ctrl->device, ctrl->function, ctrl->rev); init_MUTEX(&ctrl->crit_sect); init_waitqueue_head(&ctrl->queue); /* initialize our threads if they haven't already been started up */ rc = one_time_init(); if (rc) { goto err_free_ctrl; } dbg("pdev = %p\n", pdev); dbg("pci resource start %lx\n", pci_resource_start(pdev, 0)); dbg("pci resource len %lx\n", pci_resource_len(pdev, 0)); if (!request_mem_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0), MY_NAME)) { err("cannot reserve MMIO region\n"); rc = -ENOMEM; goto err_free_ctrl; } ctrl->hpc_reg = ioremap(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0)); if (!ctrl->hpc_reg) { err("cannot remap MMIO region %lx @ %lx\n", pci_resource_len(pdev, 0), pci_resource_start(pdev, 0)); rc = -ENODEV; goto err_free_mem_region; } // Check for 66Mhz operation // TODO: Add PCI-X support ctrl->speed = get_controller_speed(ctrl); //************************************************** // // Save configuration headers for this and // subordinate PCI buses // //************************************************** // find the physical slot number of the first hot plug slot // Get slot won't work for devices behind bridges, but // in this case it will always be called for the "base" // bus/dev/func of a slot. // CS: this is leveraging the PCIIRQ routing code from the kernel (pci-pc.c: get_irq_routing_table) rc = get_slot_mapping(ctrl->pci_ops, pdev->bus->number, (readb(ctrl->hpc_reg + SLOT_MASK) >> 4), &(ctrl->first_slot)); dbg("get_slot_mapping: first_slot = %d, returned = %d\n", ctrl->first_slot, rc); if (rc) { err(msg_initialization_err, rc); goto err_iounmap; } // Store PCI Config Space for all devices on this bus rc = cpqhp_save_config(ctrl, ctrl->bus, readb(ctrl->hpc_reg + SLOT_MASK)); if (rc) { err(__FUNCTION__": unable to save PCI configuration data, error %d\n", rc); goto err_iounmap; } /* * Get IO, memory, and IRQ resources for new devices */ rc = cpqhp_find_available_resources(ctrl, cpqhp_rom_start); ctrl->add_support = !rc; if (rc) { dbg("cpqhp_find_available_resources = 0x%x\n", rc); err("unable to locate PCI configuration resources for hot plug add.\n"); goto err_iounmap; } /* * Finish setting up the hot plug ctrl device */ ctrl->slot_device_offset = readb(ctrl->hpc_reg + SLOT_MASK) >> 4; dbg("NumSlots %d \n", ctrl->slot_device_offset); ctrl->next_event = 0; /* Setup the slot information structures */ rc = ctrl_slot_setup(ctrl, smbios_start, smbios_table); if (rc) { err(msg_initialization_err, 6); err(__FUNCTION__": unable to save PCI configuration data, error %d\n", rc); goto err_iounmap; } /* Mask all general input interrupts */ writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_MASK); /* set up the interrupt */ ctrl->interrupt = pdev->irq; dbg("HPC interrupt = %d \n", ctrl->interrupt); if (request_irq(ctrl->interrupt, (void (*)(int, void *, struct pt_regs *)) &cpqhp_ctrl_intr, SA_SHIRQ, MY_NAME, ctrl)) { err("Can't get irq %d for the hotplug pci controller\n", ctrl->interrupt); rc = -ENODEV; goto err_iounmap; } /* Enable Shift Out interrupt and clear it, also enable SERR on power fault */ temp_word = readw(ctrl->hpc_reg + MISC); temp_word |= 0x4006; writew(temp_word, ctrl->hpc_reg + MISC); // Changed 05/05/97 to clear all interrupts at start writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_INPUT_CLEAR); ctrl->ctrl_int_comp = readl(ctrl->hpc_reg + INT_INPUT_CLEAR); writel(0x0L, ctrl->hpc_reg + INT_MASK); if (!cpqhp_ctrl_list) { cpqhp_ctrl_list = ctrl; ctrl->next = NULL; } else { ctrl->next = cpqhp_ctrl_list; cpqhp_ctrl_list = ctrl; } // turn off empty slots here unless command line option "ON" set // Wait for exclusive access to hardware down(&ctrl->crit_sect); num_of_slots = readb(ctrl->hpc_reg + SLOT_MASK) & 0x0F; // find first device number for the ctrl device = readb(ctrl->hpc_reg + SLOT_MASK) >> 4; while (num_of_slots) { dbg("num_of_slots: %d\n", num_of_slots); func = cpqhp_slot_find(ctrl->bus, device, 0); if (!func) break; hp_slot = func->device - ctrl->slot_device_offset; dbg("hp_slot: %d\n", hp_slot); // We have to save the presence info for these slots temp_word = ctrl->ctrl_int_comp >> 16; func->presence_save = (temp_word >> hp_slot) & 0x01; func->presence_save |= (temp_word >> (hp_slot + 7)) & 0x02; if (ctrl->ctrl_int_comp & (0x1L << hp_slot)) { func->switch_save = 0; } else { func->switch_save = 0x10; } if (!power_mode) { if (!func->is_a_board) { green_LED_off (ctrl, hp_slot); slot_disable (ctrl, hp_slot); } } device++; num_of_slots--; } if (!power_mode) { set_SOGO(ctrl); // Wait for SOBS to be unset wait_for_ctrl_irq (ctrl); } rc = init_SERR(ctrl); if (rc) { err("init_SERR failed\n"); up(&ctrl->crit_sect); goto err_free_irq; } // Done with exclusive hardware access up(&ctrl->crit_sect); rc = cpqhp_proc_create_ctrl (ctrl); if (rc) { err("cpqhp_proc_create_ctrl failed\n"); goto err_free_irq; } return 0;err_free_irq: free_irq(ctrl->interrupt, ctrl);err_iounmap: iounmap(ctrl->hpc_reg);err_free_mem_region: release_mem_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));err_free_ctrl: kfree(ctrl); return rc;}static int one_time_init(void){ int loop; int retval = 0; static int initialized = 0; if (initialized) return 0; power_mode = 0; retval = pci_print_IRQ_route(); if (retval) goto error; dbg("Initialize + Start the notification mechanism \n"); retval = cpqhp_event_start_thread(); if (retval) goto error; dbg("Initialize slot lists\n"); for (loop = 0; loop < 256; loop++) { cpqhp_slot_list[loop] = NULL; } // FIXME: We also need to hook the NMI handler eventually. // this also needs to be worked with Christoph // register_NMI_handler(); // Map rom address cpqhp_rom_start = ioremap(ROM_PHY_ADDR, ROM_PHY_LEN); if (!cpqhp_rom_start) { err ("Could not ioremap memory region for ROM\n"); retval = -EIO;; goto error; } /* Now, map the int15 entry point if we are on compaq specific hardware */ compaq_nvram_init(cpqhp_rom_start); /* Map smbios table entry point structure */ smbios_table = detect_SMBIOS_pointer(cpqhp_rom_start, cpqhp_rom_start + ROM_PHY_LEN); if (!smbios_table) { err ("Could not find the SMBIOS pointer in memory\n"); retval = -EIO;; goto error; } smbios_start = ioremap(readl(smbios_table + ST_ADDRESS), readw(smbios_table + ST_LENGTH)); if (!smbios_start) { err ("Could not ioremap memory region taken from SMBIOS values\n"); retval = -EIO;; goto error; } retval = cpqhp_proc_init_ctrl(); if (retval) goto error; initialized = 1; return retval;error: if (cpqhp_rom_start) iounmap(cpqhp_rom_start); if (smbios_start) iounmap(smbios_start); return retval;}static void unload_cpqphpd(void){ struct pci_func *next; struct pci_func *TempSlot; int loop; u32 rc; struct controller *ctrl; struct controller *tctrl; struct pci_resource *res; struct pci_resource *tres; rc = compaq_nvram_store(cpqhp_rom_start); ctrl = cpqhp_ctrl_list; while (ctrl) { cpqhp_proc_remove_ctrl (ctrl); if (ctrl->hpc_reg) { u16 misc; rc = read_slot_enable (ctrl); writeb(0, ctrl->hpc_reg + SLOT_SERR); writel(0xFFFFFFC0L | ~rc, ctrl->hpc_reg + INT_MASK); misc = readw(ctrl->hpc_reg + MISC); misc &= 0xFFFD; writew(misc, ctrl->hpc_reg + MISC); } ctrl_slot_cleanup(ctrl); res = ctrl->io_head; while (res) { tres = res; res = res->next; kfree(tres); } res = ctrl->mem_head; while (res) { tres = res; res = res->next; kfree(tres); } res = ctrl->p_mem_head; while (res) { tres = res; res = res->next; kfree(tres); } res = ctrl->bus_head; while (res) { tres = res; res = res->next; kfree(tres); } tctrl = ctrl; ctrl = ctrl->next; kfree(tctrl); } for (loop = 0; loop < 256; loop++) { next = cpqhp_slot_list[loop]; while (next != NULL) { res = next->io_head; while (res) { tres = res; res = res->next; kfree(tres); } res = next->mem_head; while (res) { tres = res; res = res->next; kfree(tres); } res = next->p_mem_head; while (res) { tres = res; res = res->next; kfree(tres); } res = next->bus_head; while (res) { tres = res; res = res->next; kfree(tres); } TempSlot = next; next = next->next; kfree(TempSlot); } } remove_proc_entry("hpc", 0); // Stop the notification mechanism cpqhp_event_stop_thread(); //unmap the rom address if (cpqhp_rom_start) iounmap(cpqhp_rom_start); if (smbios_start) iounmap(smbios_start);}static struct pci_device_id hpcd_pci_tbl[] __devinitdata = { { /* handle any PCI Hotplug controller */ class: ((PCI_CLASS_SYSTEM_PCI_HOTPLUG << 8) | 0x00), class_mask: ~0, /* no matter who makes it */ vendor: PCI_ANY_ID, device: PCI_ANY_ID, subvendor: PCI_ANY_ID, subdevice: PCI_ANY_ID, }, { /* end: all zeroes */ }};MODULE_DEVICE_TABLE(pci, hpcd_pci_tbl);static struct pci_driver cpqhpc_driver = { name: "pci_hotplug", id_table: hpcd_pci_tbl, probe: cpqhpc_probe, /* remove: cpqhpc_remove_one, */};static int __init cpqhpc_init(void){ int result; cpqhp_debug = debug; result = pci_module_init(&cpqhpc_driver); dbg("pci_module_init = %d\n", result); if (result) return result; info (DRIVER_DESC " version: " DRIVER_VERSION "\n"); return 0;}static void __exit cpqhpc_cleanup(void){ dbg("cleaning up proc entries\n"); cpqhp_proc_destroy_ctrl(); dbg("unload_cpqphpd()\n"); unload_cpqphpd(); dbg("pci_unregister_driver\n"); pci_unregister_driver(&cpqhpc_driver);}module_init(cpqhpc_init);module_exit(cpqhpc_cleanup);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -