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

📄 acpiphp_glue.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 3 页
字号:
	if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {		pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER,				bridge->hpp.latency_timer);		pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &pci_bctl);		if (bridge->hpp.enable_SERR)			pci_bctl |= PCI_BRIDGE_CTL_SERR;		else			pci_bctl &= ~PCI_BRIDGE_CTL_SERR;		if (bridge->hpp.enable_PERR)			pci_bctl |= PCI_BRIDGE_CTL_PARITY;		else			pci_bctl &= ~PCI_BRIDGE_CTL_PARITY;		pci_write_config_word(dev, PCI_BRIDGE_CONTROL, pci_bctl);		if (dev->subordinate) {			list_for_each_entry(cdev, &dev->subordinate->devices,					bus_list)				program_hpp(cdev, bridge);		}	}}static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus){	struct acpiphp_bridge bridge;	struct pci_dev *dev;	memset(&bridge, 0, sizeof(bridge));	bridge.handle = handle;	decode_hpp(&bridge);	list_for_each_entry(dev, &bus->devices, bus_list)		program_hpp(dev, &bridge);}/* * Remove devices for which we could not assign resources, call * arch specific code to fix-up the bus */static void acpiphp_sanitize_bus(struct pci_bus *bus){	struct pci_dev *dev;	int i;	unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;	list_for_each_entry(dev, &bus->devices, bus_list) {		for (i=0; i<PCI_BRIDGE_RESOURCES; i++) {			struct resource *res = &dev->resource[i];			if ((res->flags & type_mask) && !res->start &&					res->end) {				/* Could not assign a required resources				 * for this device, remove it */				pci_remove_bus_device(dev);				break;			}		}	}}/* Program resources in newly inserted bridge */static int acpiphp_configure_bridge (acpi_handle handle){	struct acpi_pci_id pci_id;	struct pci_bus *bus;	if (ACPI_FAILURE(acpi_get_pci_id(handle, &pci_id))) {		err("cannot get PCI domain and bus number for bridge\n");		return -EINVAL;	}	bus = pci_find_bus(pci_id.segment, pci_id.bus);	if (!bus) {		err("cannot find bus %d:%d\n",				pci_id.segment, pci_id.bus);		return -EINVAL;	}	pci_bus_size_bridges(bus);	pci_bus_assign_resources(bus);	acpiphp_sanitize_bus(bus);	acpiphp_set_hpp_values(handle, bus);	pci_enable_bridges(bus);	acpiphp_configure_ioapics(handle);	return 0;}static void handle_bridge_insertion(acpi_handle handle, u32 type){	struct acpi_device *device, *pdevice;	acpi_handle phandle;	if ((type != ACPI_NOTIFY_BUS_CHECK) &&			(type != ACPI_NOTIFY_DEVICE_CHECK)) {		err("unexpected notification type %d\n", type);		return;	}	acpi_get_parent(handle, &phandle);	if (acpi_bus_get_device(phandle, &pdevice)) {		dbg("no parent device, assuming NULL\n");		pdevice = NULL;	}	if (acpi_bus_add(&device, pdevice, handle, ACPI_BUS_TYPE_DEVICE)) {		err("cannot add bridge to acpi list\n");		return;	}	if (!acpiphp_configure_bridge(handle) &&		!acpi_bus_start(device))		add_bridge(handle);	else		err("cannot configure and start bridge\n");}/* * ACPI event handlers *//** * handle_hotplug_event_bridge - handle ACPI event on bridges * * @handle: Notify()'ed acpi_handle * @type: Notify code * @context: pointer to acpiphp_bridge structure * * handles ACPI event notification on {host,p2p} bridges * */static void handle_hotplug_event_bridge(acpi_handle handle, u32 type, void *context){	struct acpiphp_bridge *bridge;	char objname[64];	struct acpi_buffer buffer = { .length = sizeof(objname),				      .pointer = objname };	struct acpi_device *device;	if (acpi_bus_get_device(handle, &device)) {		/* This bridge must have just been physically inserted */		handle_bridge_insertion(handle, type);		return;	}	bridge = acpiphp_handle_to_bridge(handle);	if (!bridge) {		err("cannot get bridge info\n");		return;	}	acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);	switch (type) {	case ACPI_NOTIFY_BUS_CHECK:		/* bus re-enumerate */		dbg("%s: Bus check notify on %s\n", __FUNCTION__, objname);		acpiphp_check_bridge(bridge);		break;	case ACPI_NOTIFY_DEVICE_CHECK:		/* device check */		dbg("%s: Device check notify on %s\n", __FUNCTION__, objname);		acpiphp_check_bridge(bridge);		break;	case ACPI_NOTIFY_DEVICE_WAKE:		/* wake event */		dbg("%s: Device wake notify on %s\n", __FUNCTION__, objname);		break;	case ACPI_NOTIFY_EJECT_REQUEST:		/* request device eject */		dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname);		break;	case ACPI_NOTIFY_FREQUENCY_MISMATCH:		printk(KERN_ERR "Device %s cannot be configured due"				" to a frequency mismatch\n", objname);		break;	case ACPI_NOTIFY_BUS_MODE_MISMATCH:		printk(KERN_ERR "Device %s cannot be configured due"				" to a bus mode mismatch\n", objname);		break;	case ACPI_NOTIFY_POWER_FAULT:		printk(KERN_ERR "Device %s has suffered a power fault\n",				objname);		break;	default:		warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);		break;	}}/** * handle_hotplug_event_func - handle ACPI event on functions (i.e. slots) * * @handle: Notify()'ed acpi_handle * @type: Notify code * @context: pointer to acpiphp_func structure * * handles ACPI event notification on slots * */static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context){	struct acpiphp_func *func;	char objname[64];	struct acpi_buffer buffer = { .length = sizeof(objname),				      .pointer = objname };	acpi_get_name(handle, ACPI_FULL_PATHNAME, &buffer);	func = (struct acpiphp_func *)context;	switch (type) {	case ACPI_NOTIFY_BUS_CHECK:		/* bus re-enumerate */		dbg("%s: Bus check notify on %s\n", __FUNCTION__, objname);		acpiphp_enable_slot(func->slot);		break;	case ACPI_NOTIFY_DEVICE_CHECK:		/* device check : re-enumerate from parent bus */		dbg("%s: Device check notify on %s\n", __FUNCTION__, objname);		acpiphp_check_bridge(func->slot->bridge);		break;	case ACPI_NOTIFY_DEVICE_WAKE:		/* wake event */		dbg("%s: Device wake notify on %s\n", __FUNCTION__, objname);		break;	case ACPI_NOTIFY_EJECT_REQUEST:		/* request device eject */		dbg("%s: Device eject notify on %s\n", __FUNCTION__, objname);		if (!(acpiphp_disable_slot(func->slot)))			acpiphp_eject_slot(func->slot);		break;	default:		warn("notify_handler: unknown event type 0x%x for %s\n", type, objname);		break;	}}static int is_root_bridge(acpi_handle handle){	acpi_status status;	struct acpi_device_info *info;	struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};	int i;	status = acpi_get_object_info(handle, &buffer);	if (ACPI_SUCCESS(status)) {		info = buffer.pointer;		if ((info->valid & ACPI_VALID_HID) &&			!strcmp(PCI_ROOT_HID_STRING,					info->hardware_id.value)) {			acpi_os_free(buffer.pointer);			return 1;		}		if (info->valid & ACPI_VALID_CID) {			for (i=0; i < info->compatibility_id.count; i++) {				if (!strcmp(PCI_ROOT_HID_STRING,					info->compatibility_id.id[i].value)) {					acpi_os_free(buffer.pointer);					return 1;				}			}		}	}	return 0;}static acpi_statusfind_root_bridges(acpi_handle handle, u32 lvl, void *context, void **rv){	int *count = (int *)context;	if (is_root_bridge(handle)) {		acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,				handle_hotplug_event_bridge, NULL);			(*count)++;	}	return AE_OK ;}static struct acpi_pci_driver acpi_pci_hp_driver = {	.add =		add_bridge,	.remove =	remove_bridge,};/** * acpiphp_glue_init - initializes all PCI hotplug - ACPI glue data structures * */int __init acpiphp_glue_init(void){	int num = 0;	acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,			ACPI_UINT32_MAX, find_root_bridges, &num, NULL);	if (num <= 0)		return -1;	else		acpi_pci_register_driver(&acpi_pci_hp_driver);	return 0;}/** * acpiphp_glue_exit - terminates all PCI hotplug - ACPI glue data structures * * This function frees all data allocated in acpiphp_glue_init() */void __exit acpiphp_glue_exit(void){	acpi_pci_unregister_driver(&acpi_pci_hp_driver);}/** * acpiphp_get_num_slots - count number of slots in a system */int __init acpiphp_get_num_slots(void){	struct list_head *node;	struct acpiphp_bridge *bridge;	int num_slots;	num_slots = 0;	list_for_each (node, &bridge_list) {		bridge = (struct acpiphp_bridge *)node;		dbg("Bus %04x:%02x has %d slot%s\n",				pci_domain_nr(bridge->pci_bus),				bridge->pci_bus->number, bridge->nr_slots,				bridge->nr_slots == 1 ? "" : "s");		num_slots += bridge->nr_slots;	}	dbg("Total %d slots\n", num_slots);	return num_slots;}#if 0/** * acpiphp_for_each_slot - call function for each slot * @fn: callback function * @data: context to be passed to callback function * */static int acpiphp_for_each_slot(acpiphp_callback fn, void *data){	struct list_head *node;	struct acpiphp_bridge *bridge;	struct acpiphp_slot *slot;	int retval = 0;	list_for_each (node, &bridge_list) {		bridge = (struct acpiphp_bridge *)node;		for (slot = bridge->slots; slot; slot = slot->next) {			retval = fn(slot, data);			if (!retval)				goto err_exit;		}	} err_exit:	return retval;}#endif/* search matching slot from id  */struct acpiphp_slot *get_slot_from_id(int id){	struct list_head *node;	struct acpiphp_bridge *bridge;	struct acpiphp_slot *slot;	list_for_each (node, &bridge_list) {		bridge = (struct acpiphp_bridge *)node;		for (slot = bridge->slots; slot; slot = slot->next)			if (slot->id == id)				return slot;	}	/* should never happen! */	err("%s: no object for id %d\n", __FUNCTION__, id);	WARN_ON(1);	return NULL;}/** * acpiphp_enable_slot - power on slot */int acpiphp_enable_slot(struct acpiphp_slot *slot){	int retval;	down(&slot->crit_sect);	/* wake up all functions */	retval = power_on_slot(slot);	if (retval)		goto err_exit;	if (get_slot_status(slot) == ACPI_STA_ALL)		/* configure all functions */		retval = enable_device(slot); err_exit:	up(&slot->crit_sect);	return retval;}/** * acpiphp_disable_slot - power off slot */int acpiphp_disable_slot(struct acpiphp_slot *slot){	int retval = 0;	down(&slot->crit_sect);	/* unconfigure all functions */	retval = disable_device(slot);	if (retval)		goto err_exit;	/* power off all functions */	retval = power_off_slot(slot);	if (retval)		goto err_exit; err_exit:	up(&slot->crit_sect);	return retval;}/* * slot enabled:  1 * slot disabled: 0 */u8 acpiphp_get_power_status(struct acpiphp_slot *slot){	return (slot->flags & SLOT_POWEREDON);}/* * latch closed:  1 * latch   open:  0 */u8 acpiphp_get_latch_status(struct acpiphp_slot *slot){	unsigned int sta;	sta = get_slot_status(slot);	return (sta & ACPI_STA_SHOW_IN_UI) ? 1 : 0;}/* * adapter presence : 1 *          absence : 0 */u8 acpiphp_get_adapter_status(struct acpiphp_slot *slot){	unsigned int sta;	sta = get_slot_status(slot);	return (sta == 0) ? 0 : 1;}/* * pci address (seg/bus/dev) */u32 acpiphp_get_address(struct acpiphp_slot *slot){	u32 address;	struct pci_bus *pci_bus = slot->bridge->pci_bus;	address = (pci_domain_nr(pci_bus) << 16) |		  (pci_bus->number << 8) |		  slot->device;	return address;}

⌨️ 快捷键说明

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