?? pciehp_ctrl.c
字號:
u8 getstatus; pushbutton_pending = 0; if (!p_slot) { dbg("%s: Error! slot NULL\n", __FUNCTION__); return; } p_slot->hpc_ops->get_power_status(p_slot, &getstatus); if (getstatus) { p_slot->state = POWEROFF_STATE; dbg("%s: disabling bus:device(%x:%x)\n", __FUNCTION__, p_slot->bus, p_slot->device); pciehp_disable_slot(p_slot); p_slot->state = STATIC_STATE; } else { p_slot->state = POWERON_STATE; dbg("%s: adding bus:device(%x:%x)\n", __FUNCTION__, p_slot->bus, p_slot->device); if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) { /* Wait for exclusive access to hardware */ down(&p_slot->ctrl->crit_sect); p_slot->hpc_ops->green_led_off(p_slot); /* Wait for the command to complete */ wait_for_ctrl_irq (p_slot->ctrl); /* Done with exclusive hardware access */ up(&p_slot->ctrl->crit_sect); } p_slot->state = STATIC_STATE; } return;}/** * pciehp_surprise_rm_thread * * Scheduled procedure to handle blocking stuff for the surprise removal * Handles all pending events and exits. * */static void pciehp_surprise_rm_thread(unsigned long slot){ struct slot *p_slot = (struct slot *) slot; u8 getstatus; surprise_rm_pending = 0; if (!p_slot) { dbg("%s: Error! slot NULL\n", __FUNCTION__); return; } p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); if (!getstatus) { p_slot->state = POWEROFF_STATE; dbg("%s: removing bus:device(%x:%x)\n", __FUNCTION__, p_slot->bus, p_slot->device); pciehp_disable_slot(p_slot); p_slot->state = STATIC_STATE; } else { p_slot->state = POWERON_STATE; dbg("%s: adding bus:device(%x:%x)\n", __FUNCTION__, p_slot->bus, p_slot->device); if (pciehp_enable_slot(p_slot) && PWR_LED(p_slot->ctrl->ctrlcap)) { /* Wait for exclusive access to hardware */ down(&p_slot->ctrl->crit_sect); p_slot->hpc_ops->green_led_off(p_slot); /* Wait for the command to complete */ wait_for_ctrl_irq (p_slot->ctrl); /* Done with exclusive hardware access */ up(&p_slot->ctrl->crit_sect); } p_slot->state = STATIC_STATE; } return;}/* this is the main worker thread */static int event_thread(void* data){ struct controller *ctrl; lock_kernel(); daemonize("pciehpd_event"); unlock_kernel(); while (1) { dbg("!!!!event_thread sleeping\n"); down_interruptible (&event_semaphore); dbg("event_thread woken finished = %d\n", event_finished); if (event_finished || signal_pending(current)) break; /* Do stuff here */ if (pushbutton_pending) pciehp_pushbutton_thread(pushbutton_pending); else if (surprise_rm_pending) pciehp_surprise_rm_thread(surprise_rm_pending); else for (ctrl = pciehp_ctrl_list; ctrl; ctrl=ctrl->next) interrupt_event_handler(ctrl); } dbg("event_thread signals exit\n"); up(&event_exit); return 0;}int pciehp_event_start_thread(void){ int pid; /* initialize our semaphores */ init_MUTEX_LOCKED(&event_exit); event_finished=0; init_MUTEX_LOCKED(&event_semaphore); pid = kernel_thread(event_thread, NULL, 0); if (pid < 0) { err ("Can't start up our event thread\n"); return -1; } return 0;}void pciehp_event_stop_thread(void){ event_finished = 1; up(&event_semaphore); down(&event_exit);}static int update_slot_info(struct slot *slot){ struct hotplug_slot_info *info; /* char buffer[SLOT_NAME_SIZE]; */ int result; info = kmalloc(sizeof(struct hotplug_slot_info), GFP_KERNEL); if (!info) return -ENOMEM; /* make_slot_name (&buffer[0], SLOT_NAME_SIZE, slot); */ slot->hpc_ops->get_power_status(slot, &(info->power_status)); slot->hpc_ops->get_attention_status(slot, &(info->attention_status)); slot->hpc_ops->get_latch_status(slot, &(info->latch_status)); slot->hpc_ops->get_adapter_status(slot, &(info->adapter_status)); /* result = pci_hp_change_slot_info(buffer, info); */ result = pci_hp_change_slot_info(slot->hotplug_slot, info); kfree (info); return result;}static void interrupt_event_handler(struct controller *ctrl){ int loop = 0; int change = 1; u8 hp_slot; u8 getstatus; struct slot *p_slot; while (change) { change = 0; for (loop = 0; loop < MAX_EVENTS; loop++) { if (ctrl->event_queue[loop].event_type != 0) { hp_slot = ctrl->event_queue[loop].hp_slot; p_slot = pciehp_find_slot(ctrl, hp_slot + ctrl->slot_device_offset); if (ctrl->event_queue[loop].event_type == INT_BUTTON_CANCEL) { dbg("button cancel\n"); del_timer(&p_slot->task_event); switch (p_slot->state) { case BLINKINGOFF_STATE: /* Wait for exclusive access to hardware */ down(&ctrl->crit_sect); if (PWR_LED(ctrl->ctrlcap)) { p_slot->hpc_ops->green_led_on(p_slot); /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); } if (ATTN_LED(ctrl->ctrlcap)) { p_slot->hpc_ops->set_attention_status(p_slot, 0); /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); } /* Done with exclusive hardware access */ up(&ctrl->crit_sect); break; case BLINKINGON_STATE: /* Wait for exclusive access to hardware */ down(&ctrl->crit_sect); if (PWR_LED(ctrl->ctrlcap)) { p_slot->hpc_ops->green_led_off(p_slot); /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); } if (ATTN_LED(ctrl->ctrlcap)){ p_slot->hpc_ops->set_attention_status(p_slot, 0); /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); } /* Done with exclusive hardware access */ up(&ctrl->crit_sect); break; default: warn("Not a valid state\n"); return; } info(msg_button_cancel, p_slot->number); p_slot->state = STATIC_STATE; } /* ***********Button Pressed (No action on 1st press...) */ else if (ctrl->event_queue[loop].event_type == INT_BUTTON_PRESS) { if (ATTN_BUTTN(ctrl->ctrlcap)) { dbg("Button pressed\n"); p_slot->hpc_ops->get_power_status(p_slot, &getstatus); if (getstatus) { /* slot is on */ dbg("slot is on\n"); p_slot->state = BLINKINGOFF_STATE; info(msg_button_off, p_slot->number); } else { /* slot is off */ dbg("slot is off\n"); p_slot->state = BLINKINGON_STATE; info(msg_button_on, p_slot->number); } /* Wait for exclusive access to hardware */ down(&ctrl->crit_sect); /* blink green LED and turn off amber */ if (PWR_LED(ctrl->ctrlcap)) { p_slot->hpc_ops->green_led_blink(p_slot); /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); } if (ATTN_LED(ctrl->ctrlcap)) { p_slot->hpc_ops->set_attention_status(p_slot, 0); /* Wait for the command to complete */ wait_for_ctrl_irq (ctrl); } /* Done with exclusive hardware access */ up(&ctrl->crit_sect); init_timer(&p_slot->task_event); p_slot->task_event.expires = jiffies + 5 * HZ; /* 5 second delay */ p_slot->task_event.function = (void (*)(unsigned long)) pushbutton_helper_thread; p_slot->task_event.data = (unsigned long) p_slot; add_timer(&p_slot->task_event); } } /***********POWER FAULT********************/ else if (ctrl->event_queue[loop].event_type == INT_POWER_FAULT) { if (POWER_CTRL(ctrl->ctrlcap)) { dbg("power fault\n"); /* Wait for exclusive access to hardware */ down(&ctrl->crit_sect); if (ATTN_LED(ctrl->ctrlcap)) { p_slot->hpc_ops->set_attention_status(p_slot, 1); wait_for_ctrl_irq (ctrl); } if (PWR_LED(ctrl->ctrlcap)) { p_slot->hpc_ops->green_led_off(p_slot); wait_for_ctrl_irq (ctrl); } /* Done with exclusive hardware access */ up(&ctrl->crit_sect); } } /***********SURPRISE REMOVAL********************/ else if ((ctrl->event_queue[loop].event_type == INT_PRESENCE_ON) || (ctrl->event_queue[loop].event_type == INT_PRESENCE_OFF)) { if (HP_SUPR_RM(ctrl->ctrlcap)) { dbg("Surprise Removal\n"); if (p_slot) { surprise_rm_pending = (unsigned long) p_slot; up(&event_semaphore); update_slot_info(p_slot); } } } else { /* refresh notification */ if (p_slot) update_slot_info(p_slot); } ctrl->event_queue[loop].event_type = 0; change = 1; } } /* End of FOR loop */ }}int pciehp_enable_slot(struct slot *p_slot){ u8 getstatus = 0; int rc; /* Check to see if (latch closed, card present, power off) */ down(&p_slot->ctrl->crit_sect); rc = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); if (rc || !getstatus) { info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number); up(&p_slot->ctrl->crit_sect); return 1; } if (MRL_SENS(p_slot->ctrl->ctrlcap)) { rc = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); if (rc || getstatus) { info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number); up(&p_slot->ctrl->crit_sect); return 1; } } if (POWER_CTRL(p_slot->ctrl->ctrlcap)) { rc = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); if (rc || getstatus) { info("%s: already enabled on slot(%x)\n", __FUNCTION__, p_slot->number); up(&p_slot->ctrl->crit_sect); return 1; } } up(&p_slot->ctrl->crit_sect); p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); rc = board_added(p_slot); if (rc) { p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); } if (p_slot) update_slot_info(p_slot); return rc;}int pciehp_disable_slot(struct slot *p_slot){ u8 getstatus = 0; int ret = 0; if (!p_slot->ctrl) return 1; /* Check to see if (latch closed, card present, power on) */ down(&p_slot->ctrl->crit_sect); if (!HP_SUPR_RM(p_slot->ctrl->ctrlcap)) { ret = p_slot->hpc_ops->get_adapter_status(p_slot, &getstatus); if (ret || !getstatus) { info("%s: no adapter on slot(%x)\n", __FUNCTION__, p_slot->number); up(&p_slot->ctrl->crit_sect); return 1; } } if (MRL_SENS(p_slot->ctrl->ctrlcap)) { ret = p_slot->hpc_ops->get_latch_status(p_slot, &getstatus); if (ret || getstatus) { info("%s: latch open on slot(%x)\n", __FUNCTION__, p_slot->number); up(&p_slot->ctrl->crit_sect); return 1; } } if (POWER_CTRL(p_slot->ctrl->ctrlcap)) { ret = p_slot->hpc_ops->get_power_status(p_slot, &getstatus); if (ret || !getstatus) { info("%s: already disabled slot(%x)\n", __FUNCTION__, p_slot->number); up(&p_slot->ctrl->crit_sect); return 1; } } up(&p_slot->ctrl->crit_sect); ret = remove_board(p_slot); update_slot_info(p_slot); return ret;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -