📄 cpqphp_core.c
字号:
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 %d\n", ctrl->speed_capability); dbg(" slot_switch_type %s\n", ctrl->slot_switch_type ? "switch present" : "no switch"); dbg(" defeature_PHP %s\n", ctrl->defeature_PHP ? "PHP supported" : "PHP not supported"); dbg(" alternate_base_address %s\n", ctrl->alternate_base_address ? "supported" : "not supported"); dbg(" pci_config_space %s\n", ctrl->pci_config_space ? "supported" : "not supported"); dbg(" pcix_speed_capability %s\n", ctrl->pcix_speed_capability ? "supported" : "not supported"); dbg(" pcix_support %s\n", ctrl->pcix_support ? "supported" : "not supported"); ctrl->pci_dev = pdev; pci_set_drvdata(pdev, ctrl); /* make our own copy of the pci bus structure, * as we like tweaking it a lot */ ctrl->pci_bus = kmalloc(sizeof(*ctrl->pci_bus), GFP_KERNEL); if (!ctrl->pci_bus) { err("out of memory\n"); rc = -ENOMEM; goto err_free_ctrl; } memcpy(ctrl->pci_bus, pdev->bus, sizeof(*ctrl->pci_bus)); ctrl->bus = pdev->bus->number; ctrl->rev = rev; dbg("bus device function rev: %d %d %d %d\n", ctrl->bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), 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_bus; } 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_bus; } 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 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_bus, 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("%s: unable to save PCI configuration data, error %d\n", __FUNCTION__, rc); goto err_iounmap; } /* * Get IO, memory, and IRQ resources for new devices */ // The next line is required for cpqhp_find_available_resources ctrl->interrupt = pdev->irq; if (ctrl->interrupt < 0x10) { cpqhp_legacy_mode = 1; dbg("System seems to be configured for Full Table Mapped MPS mode\n"); } ctrl->cfgspc_irq = 0; pci_read_config_byte(pdev, PCI_INTERRUPT_LINE, &ctrl->cfgspc_irq); 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("%s: unable to save PCI configuration data, error %d\n", __FUNCTION__, rc); goto err_iounmap; } /* Mask all general input interrupts */ writel(0xFFFFFFFFL, ctrl->hpc_reg + INT_MASK); /* set up the interrupt */ dbg("HPC interrupt = %d \n", ctrl->interrupt); if (request_irq(ctrl->interrupt, 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); cpqhp_create_ctrl_files(ctrl); 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_bus: kfree(ctrl->pci_bus);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_rom_start; } 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_smbios_start; } initialized = 1; return retval;error_smbios_start: iounmap(smbios_start);error_rom_start: iounmap(cpqhp_rom_start);error: return retval;}static void __exit 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) { 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); } kfree (ctrl->pci_bus); 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); } } // 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[] = { { /* 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 = "compaq_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; info (DRIVER_DESC " version: " DRIVER_VERSION "\n"); result = pci_module_init(&cpqhpc_driver); dbg("pci_module_init = %d\n", result); return result;}static void __exit cpqhpc_cleanup(void){ 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 + -