rc = pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor_id); dbg("%s: Vendor ID: %x\n",__FUNCTION__, vendor_id); if (rc) { err("%s: unable to read PCI configuration data\n", __FUNCTION__); goto abort_free_ctlr; }  rc = pci_read_config_word(pdev, PCI_DEVICE_ID, &device_id); dbg("%s: Device ID: %x\n",__FUNCTION__, device_id); if (rc) { err("%s: unable to read PCI configuration data\n", __FUNCTION__); goto abort_free_ctlr; }  if ((vendor_id == PCI_VENDOR_ID_AMD) || (device_id == PCI_DEVICE_ID_AMD_GOLAM_7450)) { 
if ((pdev->vendor == PCI_VENDOR_ID_AMD) || (pdev->device == PCI_DEVICE_ID_AMD_GOLAM_7450)) { 
int shpc_init(struct controller * ctrl,		struct pci_dev * pdev,		php_intr_callback_t attention_button_callback,		php_intr_callback_t switch_change_callback,		php_intr_callback_t presence_change_callback,		php_intr_callback_t power_fault_callback){	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;	u16 vendor_id, device_id;	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 */	rc = pci_read_config_word(pdev, PCI_VENDOR_ID, &vendor_id);	dbg("%s: Vendor ID: %x\n",__FUNCTION__, vendor_id);	if (rc) {		err("%s: unable to read PCI configuration data\n", __FUNCTION__);		goto abort_free_ctlr;	}	rc = pci_read_config_word(pdev, PCI_DEVICE_ID, &device_id);	dbg("%s: Device ID: %x\n",__FUNCTION__, device_id);	if (rc) {		err("%s: unable to read PCI configuration data\n", __FUNCTION__);		goto abort_free_ctlr;	}	if ((vendor_id == PCI_VENDOR_ID_AMD) || (device_id == 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: tempdword %x\n", __FUNCTION__,i, tempdword);		}	}	if (first) {		spin_lock_init(&hpc_event_lock);		first = 0;	}	dbg("pdev = %p: b:d:f:irq=0x%x:%x:%x:%x\n", pdev, pdev->bus->number, PCI_SLOT(pdev->devfn), 		PCI_FUNC(pdev->devfn), pdev->irq);	for ( rc = 0; rc < DEVICE_COUNT_RESOURCE; rc++)		if (pci_resource_len(pdev, rc) > 0)			dbg("pci resource[%d] start=0x%lx(len=0x%lx), shpc_base_offset %x\n", rc,				pci_resource_start(pdev, rc), pci_resource_len(pdev, rc), shpc_base_offset);	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);	dbg("%s: physical addr %p\n", __FUNCTION__, (void*)pci_resource_start(pdev, 0));	init_MUTEX(&ctrl->crit_sect);	/* Setup wait queue */	init_waitqueue_head(&ctrl->queue);	/* Find the IRQ */	php_ctlr->irq = pdev->irq;	dbg("HPC interrupt = %d\n", php_ctlr->irq);	/* Save interrupt callback info */	php_ctlr->attention_button_callback = attention_button_callback;	php_ctlr->switch_change_callback = switch_change_callback;	php_ctlr->presence_change_callback = presence_change_callback;	php_ctlr->power_fault_callback = power_fault_callback;	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");			dbg("%s: rc = %x\n", __FUNCTION__, rc);		} 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;		}	}	get_hp_hw_control_from_firmware(pdev);	dbg("%s: Before adding HPC to HPC list\n", __FUNCTION__);	/*  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("%s: Leaving shpc_init\n", __FUNCTION__);	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;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/ee138334d5eb5ca662b2d69228420c1ccc051e0e/shpchp_hpc.c/clean/drivers/pci/hotplug/shpchp_hpc.c