⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shpchp_hpc.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 3 页
字号:
	struct php_ctlr_state_s *php_ctlr;	u8 schedule_flag = 0;	u8 temp_byte;	u32 temp_dword, intr_loc, intr_loc2;	int hp_slot;	if (!dev_id)		return IRQ_NONE;	if (!shpchp_poll_mode) { 		ctrl = (struct controller *)dev_id;		php_ctlr = ctrl->hpc_ctlr_handle;	} else { 		php_ctlr = (struct php_ctlr_state_s *) dev_id;		ctrl = (struct controller *)php_ctlr->callback_instance_id;	}	if (!ctrl)		return IRQ_NONE;		if (!php_ctlr || !php_ctlr->creg)		return IRQ_NONE;	/* Check to see if it was our interrupt */	intr_loc = readl(php_ctlr->creg + INTR_LOC);  	if (!intr_loc)		return IRQ_NONE;	dbg("%s: intr_loc = %x\n",__FUNCTION__, intr_loc); 	if(!shpchp_poll_mode) {		/* Mask Global Interrupt Mask - see implementation note on p. 139 */		/* of SHPC spec rev 1.0*/		temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);		temp_dword |= 0x00000001;		writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);		intr_loc2 = readl(php_ctlr->creg + INTR_LOC);  		dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2); 	}	if (intr_loc & 0x0001) {		/* 		 * Command Complete Interrupt Pending 		 * RO only - clear by writing 0 to the Command Completion		 * Detect bit in Controller SERR-INT register		 */		temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);		temp_dword &= 0xfffeffff;		writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);		wake_up_interruptible(&ctrl->queue);	}	if ((intr_loc = (intr_loc >> 1)) == 0) {		/* Unmask Global Interrupt Mask */		temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);		temp_dword &= 0xfffffffe;		writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);		return IRQ_NONE;	}	for (hp_slot = 0; hp_slot < ctrl->num_slots; hp_slot++) { 	/* To find out which slot has interrupt pending */		if ((intr_loc >> hp_slot) & 0x01) {			temp_dword = readl(php_ctlr->creg + SLOT1 + (4*hp_slot));			dbg("%s: Slot %x with intr, slot register = %x\n",				__FUNCTION__, hp_slot, temp_dword);			temp_byte = (temp_dword >> 16) & 0xFF;			if ((php_ctlr->switch_change_callback) && (temp_byte & 0x08))				schedule_flag += php_ctlr->switch_change_callback(					hp_slot, php_ctlr->callback_instance_id);			if ((php_ctlr->attention_button_callback) && (temp_byte & 0x04))				schedule_flag += php_ctlr->attention_button_callback(					hp_slot, php_ctlr->callback_instance_id);			if ((php_ctlr->presence_change_callback) && (temp_byte & 0x01))				schedule_flag += php_ctlr->presence_change_callback(					hp_slot , php_ctlr->callback_instance_id);			if ((php_ctlr->power_fault_callback) && (temp_byte & 0x12))				schedule_flag += php_ctlr->power_fault_callback(					hp_slot, php_ctlr->callback_instance_id);						/* Clear all slot events */			temp_dword = 0xe01f3fff;			writel(temp_dword, php_ctlr->creg + SLOT1 + (4*hp_slot));			intr_loc2 = readl(php_ctlr->creg + INTR_LOC);  			dbg("%s: intr_loc2 = %x\n",__FUNCTION__, intr_loc2); 		}	}	if (!shpchp_poll_mode) {		/* Unmask Global Interrupt Mask */		temp_dword = readl(php_ctlr->creg + SERR_INTR_ENABLE);		temp_dword &= 0xfffffffe;		writel(temp_dword, php_ctlr->creg + SERR_INTR_ENABLE);	}		return IRQ_HANDLED;}static int hpc_get_max_bus_speed (struct slot *slot, enum pci_bus_speed *value){	struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;	enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;	int retval = 0;	u8 pi;	u32 slot_avail1, slot_avail2;	int slot_num;	DBG_ENTER_ROUTINE 	if (!slot->ctrl->hpc_ctlr_handle) {		err("%s: Invalid HPC controller handle!\n", __FUNCTION__);		return -1;	}	if (slot->hp_slot >= php_ctlr->num_slots) {		err("%s: Invalid HPC slot number!\n", __FUNCTION__);		return -1;	}	pi = readb(php_ctlr->creg + PROG_INTERFACE);	slot_avail1 = readl(php_ctlr->creg + SLOT_AVAIL1);	slot_avail2 = readl(php_ctlr->creg + SLOT_AVAIL2);	if (pi == 2) {		if ((slot_num = ((slot_avail2 & SLOT_133MHZ_PCIX_533) >> 27)  ) != 0 )			bus_speed = PCIX_133MHZ_533;		else if ((slot_num = ((slot_avail2 & SLOT_100MHZ_PCIX_533) >> 23)  ) != 0 )			bus_speed = PCIX_100MHZ_533;		else if ((slot_num = ((slot_avail2 & SLOT_66MHZ_PCIX_533) >> 19)  ) != 0 )			bus_speed = PCIX_66MHZ_533;		else if ((slot_num = ((slot_avail2 & SLOT_133MHZ_PCIX_266) >> 15)  ) != 0 )			bus_speed = PCIX_133MHZ_266;		else if ((slot_num = ((slot_avail2 & SLOT_100MHZ_PCIX_266) >> 11)  ) != 0 )			bus_speed = PCIX_100MHZ_266;		else if ((slot_num = ((slot_avail2 & SLOT_66MHZ_PCIX_266) >> 7)  ) != 0 )			bus_speed = PCIX_66MHZ_266;		else if ((slot_num = ((slot_avail1 & SLOT_133MHZ_PCIX) >> 23)  ) != 0 )			bus_speed = PCIX_133MHZ;		else if ((slot_num = ((slot_avail1 & SLOT_100MHZ_PCIX) >> 15)  ) != 0 )			bus_speed = PCIX_100MHZ;		else if ((slot_num = ((slot_avail1 & SLOT_66MHZ_PCIX) >> 7)  ) != 0 )			bus_speed = PCIX_66MHZ;		else if ((slot_num = (slot_avail2 & SLOT_66MHZ)) != 0 )			bus_speed = PCI_66MHZ;		else if ((slot_num = (slot_avail1 & SLOT_33MHZ)) != 0 )			bus_speed = PCI_33MHZ;		else bus_speed = PCI_SPEED_UNKNOWN;	} else {		if ((slot_num = ((slot_avail1 & SLOT_133MHZ_PCIX) >> 23)  ) != 0 )			bus_speed = PCIX_133MHZ;		else if ((slot_num = ((slot_avail1 & SLOT_100MHZ_PCIX) >> 15)  ) != 0 )			bus_speed = PCIX_100MHZ;		else if ((slot_num = ((slot_avail1 & SLOT_66MHZ_PCIX) >> 7)  ) != 0 )			bus_speed = PCIX_66MHZ;		else if ((slot_num = (slot_avail2 & SLOT_66MHZ)) != 0 )			bus_speed = PCI_66MHZ;		else if ((slot_num = (slot_avail1 & SLOT_33MHZ)) != 0 )			bus_speed = PCI_33MHZ;		else bus_speed = PCI_SPEED_UNKNOWN;	}	*value = bus_speed;	dbg("Max bus speed = %d\n", bus_speed);	DBG_LEAVE_ROUTINE 	return retval;}static int hpc_get_cur_bus_speed (struct slot *slot, enum pci_bus_speed *value){	struct php_ctlr_state_s *php_ctlr = slot->ctrl->hpc_ctlr_handle;	enum pci_bus_speed bus_speed = PCI_SPEED_UNKNOWN;	u16 sec_bus_status;	int retval = 0;	u8 pi;	DBG_ENTER_ROUTINE 	if (!slot->ctrl->hpc_ctlr_handle) {		err("%s: Invalid HPC controller handle!\n", __FUNCTION__);		return -1;	}	if (slot->hp_slot >= php_ctlr->num_slots) {		err("%s: Invalid HPC slot number!\n", __FUNCTION__);		return -1;	}	pi = readb(php_ctlr->creg + PROG_INTERFACE);	sec_bus_status = readw(php_ctlr->creg + SEC_BUS_CONFIG);	if (pi == 2) {		switch (sec_bus_status & 0x000f) {		case 0:			bus_speed = PCI_SPEED_33MHz;			break;		case 1:			bus_speed = PCI_SPEED_66MHz;			break;		case 2:			bus_speed = PCI_SPEED_66MHz_PCIX;			break;		case 3:			bus_speed = PCI_SPEED_100MHz_PCIX;				break;		case 4:			bus_speed = PCI_SPEED_133MHz_PCIX;				break;		case 5:			bus_speed = PCI_SPEED_66MHz_PCIX_ECC;			break;		case 6:			bus_speed = PCI_SPEED_100MHz_PCIX_ECC;			break;		case 7:			bus_speed = PCI_SPEED_133MHz_PCIX_ECC;				break;		case 8:			bus_speed = PCI_SPEED_66MHz_PCIX_266;				break;		case 9:			bus_speed = PCI_SPEED_100MHz_PCIX_266;				break;		case 0xa:			bus_speed = PCI_SPEED_133MHz_PCIX_266;				break;		case 0xb:			bus_speed = PCI_SPEED_66MHz_PCIX_533;				break;		case 0xc:			bus_speed = PCI_SPEED_100MHz_PCIX_533;				break;		case 0xd:			bus_speed = PCI_SPEED_133MHz_PCIX_533;				break;		case 0xe:		case 0xf:		default:			bus_speed = PCI_SPEED_UNKNOWN;			break;		}	} else {		/* In the case where pi is undefined, default it to 1 */ 		switch (sec_bus_status & 0x0007) {		case 0:			bus_speed = PCI_SPEED_33MHz;			break;		case 1:			bus_speed = PCI_SPEED_66MHz;			break;		case 2:			bus_speed = PCI_SPEED_66MHz_PCIX;			break;		case 3:			bus_speed = PCI_SPEED_100MHz_PCIX;				break;		case 4:			bus_speed = PCI_SPEED_133MHz_PCIX;				break;		case 5:			bus_speed = PCI_SPEED_UNKNOWN;		/*	Reserved */			break;		case 6:			bus_speed = PCI_SPEED_UNKNOWN;		/*	Reserved */			break;		case 7:			bus_speed = PCI_SPEED_UNKNOWN;		/*	Reserved */				break;		default:			bus_speed = PCI_SPEED_UNKNOWN;			break;		}	}	*value = bus_speed;	dbg("Current bus speed = %d\n", bus_speed);	DBG_LEAVE_ROUTINE 	return retval;}static struct hpc_ops shpchp_hpc_ops = {	.power_on_slot			= hpc_power_on_slot,	.slot_enable			= hpc_slot_enable,	.slot_disable			= hpc_slot_disable,	.set_bus_speed_mode		= hpc_set_bus_speed_mode,	  	.set_attention_status	= hpc_set_attention_status,	.get_power_status		= hpc_get_power_status,	.get_attention_status	= hpc_get_attention_status,	.get_latch_status		= hpc_get_latch_status,	.get_adapter_status		= hpc_get_adapter_status,	.get_max_bus_speed		= hpc_get_max_bus_speed,	.get_cur_bus_speed		= hpc_get_cur_bus_speed,	.get_adapter_speed		= hpc_get_adapter_speed,	.get_mode1_ECC_cap		= hpc_get_mode1_ECC_cap,	.get_prog_int			= hpc_get_prog_int,	.query_power_fault		= hpc_query_power_fault,	.green_led_on			= hpc_set_green_led_on,	.green_led_off			= hpc_set_green_led_off,	.green_led_blink		= hpc_set_green_led_blink,		.release_ctlr			= hpc_release_ctlr,	.check_cmd_status		= hpc_check_cmd_status,};int shpc_init(struct controller * ctrl, struct pci_dev * pdev){	struct php_ctlr_state_s *php_ctlr, *p;	void *instance_id = ctrl;	int rc;	u8 hp_slot;	static int first = 1;	u32 shpc_cap_offset, shpc_base_offset;	u32 tempdword, slot_reg;	u8 i;	DBG_ENTER_ROUTINE	spin_lock_init(&list_lock);	php_ctlr = (struct php_ctlr_state_s *) kmalloc(sizeof(struct php_ctlr_state_s), GFP_KERNEL);	if (!php_ctlr) {	/* allocate controller state data */		err("%s: HPC controller memory allocation error!\n", __FUNCTION__);		goto abort;	}	memset(php_ctlr, 0, sizeof(struct php_ctlr_state_s));	php_ctlr->pci_dev = pdev;	/* save pci_dev in context */	if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device ==				PCI_DEVICE_ID_AMD_GOLAM_7450)) {		shpc_base_offset = 0;  /* amd shpc driver doesn't use this; assume 0 */	} else {		if ((shpc_cap_offset = pci_find_capability(pdev, PCI_CAP_ID_SHPC)) == 0) {			err("%s : shpc_cap_offset == 0\n", __FUNCTION__);			goto abort_free_ctlr;		}		dbg("%s: shpc_cap_offset = %x\n", __FUNCTION__, shpc_cap_offset);				rc = pci_write_config_byte(pdev, (u8)shpc_cap_offset + DWORD_SELECT , BASE_OFFSET);		if (rc) {			err("%s : pci_word_config_byte failed\n", __FUNCTION__);			goto abort_free_ctlr;		}			rc = pci_read_config_dword(pdev, (u8)shpc_cap_offset + DWORD_DATA, &shpc_base_offset);		if (rc) {			err("%s : pci_read_config_dword failed\n", __FUNCTION__);			goto abort_free_ctlr;		}		for (i = 0; i <= 14; i++) {			rc = pci_write_config_byte(pdev, (u8)shpc_cap_offset +  DWORD_SELECT , i);			if (rc) {				err("%s : pci_word_config_byte failed\n", __FUNCTION__);				goto abort_free_ctlr;			}				rc = pci_read_config_dword(pdev, (u8)shpc_cap_offset + DWORD_DATA, &tempdword);			if (rc) {				err("%s : pci_read_config_dword failed\n", __FUNCTION__);				goto abort_free_ctlr;			}			dbg("%s: offset %d: value %x\n", __FUNCTION__,i,					tempdword);		}	}	if (first) {		spin_lock_init(&hpc_event_lock);		first = 0;	}	info("HPC vendor_id %x device_id %x ss_vid %x ss_did %x\n", pdev->vendor, pdev->device, pdev->subsystem_vendor, 		pdev->subsystem_device);		if (pci_enable_device(pdev))		goto abort_free_ctlr;	if (!request_mem_region(pci_resource_start(pdev, 0) + shpc_base_offset, pci_resource_len(pdev, 0), MY_NAME)) {		err("%s: cannot reserve MMIO region\n", __FUNCTION__);		goto abort_free_ctlr;	}	php_ctlr->creg = ioremap(pci_resource_start(pdev, 0) + shpc_base_offset, pci_resource_len(pdev, 0));	if (!php_ctlr->creg) {		err("%s: cannot remap MMIO region %lx @ %lx\n", __FUNCTION__, pci_resource_len(pdev, 0), 			pci_resource_start(pdev, 0) + shpc_base_offset);		release_mem_region(pci_resource_start(pdev, 0) + shpc_base_offset, pci_resource_len(pdev, 0));		goto abort_free_ctlr;	}	dbg("%s: php_ctlr->creg %p\n", __FUNCTION__, php_ctlr->creg);	init_MUTEX(&ctrl->crit_sect);	/* Setup wait queue */	init_waitqueue_head(&ctrl->queue);	/* Find the IRQ */	php_ctlr->irq = pdev->irq;	php_ctlr->attention_button_callback = shpchp_handle_attention_button,	php_ctlr->switch_change_callback = shpchp_handle_switch_change;	php_ctlr->presence_change_callback = shpchp_handle_presence_change;	php_ctlr->power_fault_callback = shpchp_handle_power_fault;	php_ctlr->callback_instance_id = instance_id;	/* Return PCI Controller Info */	php_ctlr->slot_device_offset = (readl(php_ctlr->creg + SLOT_CONFIG) & FIRST_DEV_NUM ) >> 8;	php_ctlr->num_slots = readl(php_ctlr->creg + SLOT_CONFIG) & SLOT_NUM;	dbg("%s: slot_device_offset %x\n", __FUNCTION__, php_ctlr->slot_device_offset);	dbg("%s: num_slots %x\n", __FUNCTION__, php_ctlr->num_slots);	/* Mask Global Interrupt Mask & Command Complete Interrupt Mask */	tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);	dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);	tempdword = 0x0003000f;   	writel(tempdword, php_ctlr->creg + SERR_INTR_ENABLE);	tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);	dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);	/* Mask the MRL sensor SERR Mask of individual slot in	 * Slot SERR-INT Mask & clear all the existing event if any	 */	for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {		slot_reg = readl(php_ctlr->creg + SLOT1 + 4*hp_slot );		dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,			hp_slot, slot_reg);		tempdword = 0xffff3fff;  		writel(tempdword, php_ctlr->creg + SLOT1 + (4*hp_slot));	}		if (shpchp_poll_mode)  {/* Install interrupt polling code */		/* Install and start the interrupt polling timer */		init_timer(&php_ctlr->int_poll_timer);		start_int_poll_timer( php_ctlr, 10 );   /* start with 10 second delay */	} else {		/* Installs the interrupt handler */		rc = pci_enable_msi(pdev);		if (rc) {			info("Can't get msi for the hotplug controller\n");			info("Use INTx for the hotplug controller\n");		} else			php_ctlr->irq = pdev->irq;				rc = request_irq(php_ctlr->irq, shpc_isr, SA_SHIRQ, MY_NAME, (void *) ctrl);		dbg("%s: request_irq %d for hpc%d (returns %d)\n", __FUNCTION__, php_ctlr->irq, ctlr_seq_num, rc);		if (rc) {			err("Can't get irq %d for the hotplug controller\n", php_ctlr->irq);			goto abort_free_ctlr;		}	}	dbg("%s: HPC at b:d:f:irq=0x%x:%x:%x:%x\n", __FUNCTION__,			pdev->bus->number, PCI_SLOT(pdev->devfn),			PCI_FUNC(pdev->devfn), pdev->irq);	get_hp_hw_control_from_firmware(pdev);	/*  Add this HPC instance into the HPC list */	spin_lock(&list_lock);	if (php_ctlr_list_head == 0) {		php_ctlr_list_head = php_ctlr;		p = php_ctlr_list_head;		p->pnext = NULL;	} else {		p = php_ctlr_list_head;		while (p->pnext)			p = p->pnext;		p->pnext = php_ctlr;	}	spin_unlock(&list_lock);	ctlr_seq_num++;	ctrl->hpc_ctlr_handle = php_ctlr;	ctrl->hpc_ops = &shpchp_hpc_ops;	for (hp_slot = 0; hp_slot < php_ctlr->num_slots; hp_slot++) {		slot_reg = readl(php_ctlr->creg + SLOT1 + 4*hp_slot );		dbg("%s: Default Logical Slot Register %d value %x\n", __FUNCTION__,			hp_slot, slot_reg);		tempdword = 0xe01f3fff;  		writel(tempdword, php_ctlr->creg + SLOT1 + (4*hp_slot));	}	if (!shpchp_poll_mode) {		/* Unmask all general input interrupts and SERR */		tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);		tempdword = 0x0000000a;		writel(tempdword, php_ctlr->creg + SERR_INTR_ENABLE);		tempdword = readl(php_ctlr->creg + SERR_INTR_ENABLE);		dbg("%s: SERR_INTR_ENABLE = %x\n", __FUNCTION__, tempdword);	}	DBG_LEAVE_ROUTINE	return 0;	/* We end up here for the many possible ways to fail this API.  */abort_free_ctlr:	kfree(php_ctlr);abort:	DBG_LEAVE_ROUTINE	return -1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -