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

📄 acpiphp_glue.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 3 页
字号:
	struct acpiphp_slot *slot;	acpi_status status;	acpi_handle handle = bridge->handle;	status = acpi_remove_notify_handler(handle, ACPI_SYSTEM_NOTIFY,					    handle_hotplug_event_bridge);	if (ACPI_FAILURE(status))		err("failed to remove notify handler\n");	slot = bridge->slots;	while (slot) {		struct acpiphp_slot *next = slot->next;		list_for_each_safe (list, tmp, &slot->funcs) {			struct acpiphp_func *func;			func = list_entry(list, struct acpiphp_func, sibling);			status = acpi_remove_notify_handler(func->handle,						ACPI_SYSTEM_NOTIFY,						handle_hotplug_event_func);			if (ACPI_FAILURE(status))				err("failed to remove notify handler\n");			pci_dev_put(func->pci_dev);			list_del(list);			kfree(func);		}		kfree(slot);		slot = next;	}	pci_dev_put(bridge->pci_dev);	list_del(&bridge->list);	kfree(bridge);}static acpi_statuscleanup_p2p_bridge(acpi_handle handle, u32 lvl, void *context, void **rv){	struct acpiphp_bridge *bridge;	if (!(bridge = acpiphp_handle_to_bridge(handle)))		return AE_OK;	cleanup_bridge(bridge);	return AE_OK;}static void remove_bridge(acpi_handle handle){	struct acpiphp_bridge *bridge;	bridge = acpiphp_handle_to_bridge(handle);	if (bridge) {		cleanup_bridge(bridge);	} else {		/* clean-up p2p bridges under this host bridge */		acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,				(u32)1, cleanup_p2p_bridge, NULL, NULL);	}}static struct pci_dev * get_apic_pci_info(acpi_handle handle){	struct acpi_pci_id id;	struct pci_bus *bus;	struct pci_dev *dev;	if (ACPI_FAILURE(acpi_get_pci_id(handle, &id)))		return NULL;	bus = pci_find_bus(id.segment, id.bus);	if (!bus)		return NULL;	dev = pci_get_slot(bus, PCI_DEVFN(id.device, id.function));	if (!dev)		return NULL;	if ((dev->class != PCI_CLASS_SYSTEM_PIC_IOAPIC) &&	    (dev->class != PCI_CLASS_SYSTEM_PIC_IOXAPIC))	{		pci_dev_put(dev);		return NULL;	}	return dev;}static int get_gsi_base(acpi_handle handle, u32 *gsi_base){	acpi_status status;	int result = -1;	unsigned long gsb;	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};	union acpi_object *obj;	void *table;	status = acpi_evaluate_integer(handle, "_GSB", NULL, &gsb);	if (ACPI_SUCCESS(status)) {		*gsi_base = (u32)gsb;		return 0;	}	status = acpi_evaluate_object(handle, "_MAT", NULL, &buffer);	if (ACPI_FAILURE(status) || !buffer.length || !buffer.pointer)		return -1;	obj = buffer.pointer;	if (obj->type != ACPI_TYPE_BUFFER)		goto out;	table = obj->buffer.pointer;	switch (((acpi_table_entry_header *)table)->type) {	case ACPI_MADT_IOSAPIC:		*gsi_base = ((struct acpi_table_iosapic *)table)->global_irq_base;		result = 0;		break;	case ACPI_MADT_IOAPIC:		*gsi_base = ((struct acpi_table_ioapic *)table)->global_irq_base;		result = 0;		break;	default:		break;	} out:	acpi_os_free(buffer.pointer);	return result;}static acpi_statusioapic_add(acpi_handle handle, u32 lvl, void *context, void **rv){	acpi_status status;	unsigned long sta;	acpi_handle tmp;	struct pci_dev *pdev;	u32 gsi_base;	u64 phys_addr;	/* Evaluate _STA if present */	status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);	if (ACPI_SUCCESS(status) && sta != ACPI_STA_ALL)		return AE_CTRL_DEPTH;	/* Scan only PCI bus scope */	status = acpi_get_handle(handle, "_HID", &tmp);	if (ACPI_SUCCESS(status))		return AE_CTRL_DEPTH;	if (get_gsi_base(handle, &gsi_base))		return AE_OK;	pdev = get_apic_pci_info(handle);	if (!pdev)		return AE_OK;	if (pci_enable_device(pdev)) {		pci_dev_put(pdev);		return AE_OK;	}	pci_set_master(pdev);	if (pci_request_region(pdev, 0, "I/O APIC(acpiphp)")) {		pci_disable_device(pdev);		pci_dev_put(pdev);		return AE_OK;	}	phys_addr = pci_resource_start(pdev, 0);	if (acpi_register_ioapic(handle, phys_addr, gsi_base)) {		pci_release_region(pdev, 0);		pci_disable_device(pdev);		pci_dev_put(pdev);		return AE_OK;	}	return AE_OK;}static int acpiphp_configure_ioapics(acpi_handle handle){	acpi_walk_namespace(ACPI_TYPE_DEVICE, handle,			    ACPI_UINT32_MAX, ioapic_add, NULL, NULL);	return 0;}static int power_on_slot(struct acpiphp_slot *slot){	acpi_status status;	struct acpiphp_func *func;	struct list_head *l;	int retval = 0;	/* if already enabled, just skip */	if (slot->flags & SLOT_POWEREDON)		goto err_exit;	list_for_each (l, &slot->funcs) {		func = list_entry(l, struct acpiphp_func, sibling);		if (func->flags & FUNC_HAS_PS0) {			dbg("%s: executing _PS0\n", __FUNCTION__);			status = acpi_evaluate_object(func->handle, "_PS0", NULL, NULL);			if (ACPI_FAILURE(status)) {				warn("%s: _PS0 failed\n", __FUNCTION__);				retval = -1;				goto err_exit;			} else				break;		}	}	/* TBD: evaluate _STA to check if the slot is enabled */	slot->flags |= SLOT_POWEREDON; err_exit:	return retval;}static int power_off_slot(struct acpiphp_slot *slot){	acpi_status status;	struct acpiphp_func *func;	struct list_head *l;	int retval = 0;	/* if already disabled, just skip */	if ((slot->flags & SLOT_POWEREDON) == 0)		goto err_exit;	list_for_each (l, &slot->funcs) {		func = list_entry(l, struct acpiphp_func, sibling);		if (func->flags & FUNC_HAS_PS3) {			status = acpi_evaluate_object(func->handle, "_PS3", NULL, NULL);			if (ACPI_FAILURE(status)) {				warn("%s: _PS3 failed\n", __FUNCTION__);				retval = -1;				goto err_exit;			} else				break;		}	}	/* TBD: evaluate _STA to check if the slot is disabled */	slot->flags &= (~SLOT_POWEREDON); err_exit:	return retval;}/** * enable_device - enable, configure a slot * @slot: slot to be enabled * * This function should be called per *physical slot*, * not per each slot object in ACPI namespace. * */static int enable_device(struct acpiphp_slot *slot){	struct pci_dev *dev;	struct pci_bus *bus = slot->bridge->pci_bus;	struct list_head *l;	struct acpiphp_func *func;	int retval = 0;	int num, max, pass;	if (slot->flags & SLOT_ENABLED)		goto err_exit;	/* sanity check: dev should be NULL when hot-plugged in */	dev = pci_get_slot(bus, PCI_DEVFN(slot->device, 0));	if (dev) {		/* This case shouldn't happen */		err("pci_dev structure already exists.\n");		pci_dev_put(dev);		retval = -1;		goto err_exit;	}	num = pci_scan_slot(bus, PCI_DEVFN(slot->device, 0));	if (num == 0) {		err("No new device found\n");		retval = -1;		goto err_exit;	}	max = bus->secondary;	for (pass = 0; pass < 2; pass++) {		list_for_each_entry(dev, &bus->devices, bus_list) {			if (PCI_SLOT(dev->devfn) != slot->device)				continue;			if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||			    dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)				max = pci_scan_bridge(bus, dev, max, pass);		}	}	pci_bus_size_bridges(bus);	pci_bus_assign_resources(bus);	acpiphp_sanitize_bus(bus);	pci_enable_bridges(bus);	pci_bus_add_devices(bus);	acpiphp_set_hpp_values(DEVICE_ACPI_HANDLE(&bus->self->dev), bus);	acpiphp_configure_ioapics(DEVICE_ACPI_HANDLE(&bus->self->dev));	/* associate pci_dev to our representation */	list_for_each (l, &slot->funcs) {		func = list_entry(l, struct acpiphp_func, sibling);		func->pci_dev = pci_get_slot(bus, PCI_DEVFN(slot->device,							func->function));	}	slot->flags |= SLOT_ENABLED; err_exit:	return retval;}/** * disable_device - disable a slot */static int disable_device(struct acpiphp_slot *slot){	int retval = 0;	struct acpiphp_func *func;	struct list_head *l;	/* is this slot already disabled? */	if (!(slot->flags & SLOT_ENABLED))		goto err_exit;	list_for_each (l, &slot->funcs) {		func = list_entry(l, struct acpiphp_func, sibling);		if (!func->pci_dev)			continue;		pci_remove_bus_device(func->pci_dev);		pci_dev_put(func->pci_dev);		func->pci_dev = NULL;	}	slot->flags &= (~SLOT_ENABLED); err_exit:	return retval;}/** * get_slot_status - get ACPI slot status * * if a slot has _STA for each function and if any one of them * returned non-zero status, return it * * if a slot doesn't have _STA and if any one of its functions' * configuration space is configured, return 0x0f as a _STA * * otherwise return 0 */static unsigned int get_slot_status(struct acpiphp_slot *slot){	acpi_status status;	unsigned long sta = 0;	u32 dvid;	struct list_head *l;	struct acpiphp_func *func;	list_for_each (l, &slot->funcs) {		func = list_entry(l, struct acpiphp_func, sibling);		if (func->flags & FUNC_HAS_STA) {			status = acpi_evaluate_integer(func->handle, "_STA", NULL, &sta);			if (ACPI_SUCCESS(status) && sta)				break;		} else {			pci_bus_read_config_dword(slot->bridge->pci_bus,						  PCI_DEVFN(slot->device,							    func->function),						  PCI_VENDOR_ID, &dvid);			if (dvid != 0xffffffff) {				sta = ACPI_STA_ALL;				break;			}		}	}	return (unsigned int)sta;}/** * acpiphp_eject_slot - physically eject the slot */static int acpiphp_eject_slot(struct acpiphp_slot *slot){	acpi_status status;	struct acpiphp_func *func;	struct list_head *l;	struct acpi_object_list arg_list;	union acpi_object arg;	list_for_each (l, &slot->funcs) {		func = list_entry(l, struct acpiphp_func, sibling);		/* We don't want to call _EJ0 on non-existing functions. */		if ((func->flags & FUNC_HAS_EJ0)) {			/* _EJ0 method take one argument */			arg_list.count = 1;			arg_list.pointer = &arg;			arg.type = ACPI_TYPE_INTEGER;			arg.integer.value = 1;			status = acpi_evaluate_object(func->handle, "_EJ0", &arg_list, NULL);			if (ACPI_FAILURE(status)) {				warn("%s: _EJ0 failed\n", __FUNCTION__);				return -1;			} else				break;		}	}	return 0;}/** * acpiphp_check_bridge - re-enumerate devices * * Iterate over all slots under this bridge and make sure that if a * card is present they are enabled, and if not they are disabled. */static int acpiphp_check_bridge(struct acpiphp_bridge *bridge){	struct acpiphp_slot *slot;	int retval = 0;	int enabled, disabled;	enabled = disabled = 0;	for (slot = bridge->slots; slot; slot = slot->next) {		unsigned int status = get_slot_status(slot);		if (slot->flags & SLOT_ENABLED) {			if (status == ACPI_STA_ALL)				continue;			retval = acpiphp_disable_slot(slot);			if (retval) {				err("Error occurred in disabling\n");				goto err_exit;			} else {				acpiphp_eject_slot(slot);			}			disabled++;		} else {			if (status != ACPI_STA_ALL)				continue;			retval = acpiphp_enable_slot(slot);			if (retval) {				err("Error occurred in enabling\n");				goto err_exit;			}			enabled++;		}	}	dbg("%s: %d enabled, %d disabled\n", __FUNCTION__, enabled, disabled); err_exit:	return retval;}static void program_hpp(struct pci_dev *dev, struct acpiphp_bridge *bridge){	u16 pci_cmd, pci_bctl;	struct pci_dev *cdev;	/* Program hpp values for this device */	if (!(dev->hdr_type == PCI_HEADER_TYPE_NORMAL ||			(dev->hdr_type == PCI_HEADER_TYPE_BRIDGE &&			(dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)))		return;	pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,			bridge->hpp.cache_line_size);	pci_write_config_byte(dev, PCI_LATENCY_TIMER,			bridge->hpp.latency_timer);	pci_read_config_word(dev, PCI_COMMAND, &pci_cmd);	if (bridge->hpp.enable_SERR)		pci_cmd |= PCI_COMMAND_SERR;	else		pci_cmd &= ~PCI_COMMAND_SERR;	if (bridge->hpp.enable_PERR)		pci_cmd |= PCI_COMMAND_PARITY;	else		pci_cmd &= ~PCI_COMMAND_PARITY;	pci_write_config_word(dev, PCI_COMMAND, pci_cmd);	/* Program bridge control value and child devices */

⌨️ 快捷键说明

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