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

📄 vio.c

📁 优龙2410linux2.6.8内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * IBM PowerPC Virtual I/O Infrastructure Support. * *    Copyright (c) 2003 IBM Corp. *     Dave Engebretsen engebret@us.ibm.com *     Santiago Leon santil@us.ibm.com *     Hollis Blanchard <hollisb@us.ibm.com> * *      This program is free software; you can redistribute it and/or *      modify it under the terms of the GNU General Public License *      as published by the Free Software Foundation; either version *      2 of the License, or (at your option) any later version. */#include <linux/init.h>#include <linux/console.h>#include <linux/version.h>#include <linux/module.h>#include <linux/kobject.h>#include <linux/mm.h>#include <linux/dma-mapping.h>#include <asm/rtas.h>#include <asm/iommu.h>#include <asm/dma.h>#include <asm/ppcdebug.h>#include <asm/vio.h>#include <asm/hvcall.h>#include <asm/iSeries/vio.h>#include <asm/iSeries/HvTypes.h>#include <asm/iSeries/HvCallXm.h>#include <asm/iSeries/HvLpConfig.h>#define DBGENTER() pr_debug("%s entered\n", __FUNCTION__)extern struct subsystem devices_subsys; /* needed for vio_find_name() */static const struct vio_device_id *vio_match_device(		const struct vio_device_id *, const struct vio_dev *);#ifdef CONFIG_PPC_PSERIESstatic struct iommu_table *vio_build_iommu_table(struct vio_dev *);static int vio_num_address_cells;#endifstatic struct vio_dev *vio_bus_device; /* fake "parent" device */#ifdef CONFIG_PPC_ISERIESstatic struct vio_dev *__init vio_register_device_iseries(char *type,		uint32_t unit_num);static struct iommu_table veth_iommu_table;static struct iommu_table vio_iommu_table;static struct vio_dev _vio_dev  = {	.iommu_table = &vio_iommu_table,	.dev.bus = &vio_bus_type};struct device *iSeries_vio_dev = &_vio_dev.dev;EXPORT_SYMBOL(iSeries_vio_dev);#define device_is_compatible(a, b)	1#endif/* convert from struct device to struct vio_dev and pass to driver. * dev->driver has already been set by generic code because vio_bus_match * succeeded. */static int vio_bus_probe(struct device *dev){	struct vio_dev *viodev = to_vio_dev(dev);	struct vio_driver *viodrv = to_vio_driver(dev->driver);	const struct vio_device_id *id;	int error = -ENODEV;	DBGENTER();	if (!viodrv->probe)		return error;	id = vio_match_device(viodrv->id_table, viodev);	if (id) {		error = viodrv->probe(viodev, id);	}	return error;}/* convert from struct device to struct vio_dev and pass to driver. */static int vio_bus_remove(struct device *dev){	struct vio_dev *viodev = to_vio_dev(dev);	struct vio_driver *viodrv = to_vio_driver(dev->driver);	DBGENTER();	if (viodrv->remove) {		return viodrv->remove(viodev);	}	/* driver can't remove */	return 1;}/** * vio_register_driver: - Register a new vio driver * @drv:	The vio_driver structure to be registered. */int vio_register_driver(struct vio_driver *viodrv){	printk(KERN_DEBUG "%s: driver %s registering\n", __FUNCTION__,		viodrv->name);	/* fill in 'struct driver' fields */	viodrv->driver.name = viodrv->name;	viodrv->driver.bus = &vio_bus_type;	viodrv->driver.probe = vio_bus_probe;	viodrv->driver.remove = vio_bus_remove;	return driver_register(&viodrv->driver);}EXPORT_SYMBOL(vio_register_driver);/** * vio_unregister_driver - Remove registration of vio driver. * @driver:	The vio_driver struct to be removed form registration */void vio_unregister_driver(struct vio_driver *viodrv){	driver_unregister(&viodrv->driver);}EXPORT_SYMBOL(vio_unregister_driver);/** * vio_match_device: - Tell if a VIO device has a matching VIO device id structure. * @ids: 	array of VIO device id structures to search in * @dev: 	the VIO device structure to match against * * Used by a driver to check whether a VIO device present in the * system is in its list of supported devices. Returns the matching * vio_device_id structure or NULL if there is no match. */static const struct vio_device_id * vio_match_device(const struct vio_device_id *ids,	const struct vio_dev *dev){	DBGENTER();	while (ids->type) {		if ((strncmp(dev->type, ids->type, strlen(ids->type)) == 0) &&			device_is_compatible(dev->dev.platform_data, ids->compat))			return ids;		ids++;	}	return NULL;}#ifdef CONFIG_PPC_ISERIESvoid __init iommu_vio_init(void){	struct iommu_table *t;	struct iommu_table_cb cb;	unsigned long cbp;	cb.itc_busno = 255;    /* Bus 255 is the virtual bus */	cb.itc_virtbus = 0xff; /* Ask for virtual bus */	cbp = virt_to_abs(&cb);	HvCallXm_getTceTableParms(cbp);	veth_iommu_table.it_size        = cb.itc_size / 2;	veth_iommu_table.it_busno       = cb.itc_busno;	veth_iommu_table.it_offset      = cb.itc_offset;	veth_iommu_table.it_index       = cb.itc_index;	veth_iommu_table.it_type        = TCE_VB;	veth_iommu_table.it_entrysize	= sizeof(union tce_entry);	veth_iommu_table.it_blocksize	= 1;	t = iommu_init_table(&veth_iommu_table);	if (!t)		printk("Virtual Bus VETH TCE table failed.\n");	vio_iommu_table.it_size         = cb.itc_size - veth_iommu_table.it_size;	vio_iommu_table.it_busno        = cb.itc_busno;	vio_iommu_table.it_offset       = cb.itc_offset +		veth_iommu_table.it_size * (PAGE_SIZE/sizeof(union tce_entry));	vio_iommu_table.it_index        = cb.itc_index;	vio_iommu_table.it_type         = TCE_VB;	vio_iommu_table.it_entrysize	= sizeof(union tce_entry);	vio_iommu_table.it_blocksize	= 1;	t = iommu_init_table(&vio_iommu_table);	if (!t)		printk("Virtual Bus VIO TCE table failed.\n");}#endif#ifdef CONFIG_PPC_PSERIESstatic void probe_bus_pseries(void){	struct device_node *node_vroot, *of_node;	node_vroot = find_devices("vdevice");	if ((node_vroot == NULL) || (node_vroot->child == NULL))		/* this machine doesn't do virtual IO, and that's ok */		return;	vio_num_address_cells = prom_n_addr_cells(node_vroot->child);	/*	 * Create struct vio_devices for each virtual device in the device tree.	 * Drivers will associate with them later.	 */	for (of_node = node_vroot->child; of_node != NULL;			of_node = of_node->sibling) {		printk(KERN_DEBUG "%s: processing %p\n", __FUNCTION__, of_node);		vio_register_device_node(of_node);	}}#endif#ifdef CONFIG_PPC_ISERIESstatic void probe_bus_iseries(void){	HvLpIndexMap vlan_map = HvLpConfig_getVirtualLanIndexMap();	struct vio_dev *viodev;	int i;	vlan_map = HvLpConfig_getVirtualLanIndexMap();	for (i = 0; i < HVMAXARCHITECTEDVIRTUALLANS; i++) {		if ((vlan_map & (0x8000 >> i)) == 0)			continue;		viodev = vio_register_device_iseries("vlan", i);		/* veth is special and has it own iommu_table */		viodev->iommu_table = &veth_iommu_table;	}	for (i = 0; i < HVMAXARCHITECTEDVIRTUALDISKS; i++)		vio_register_device_iseries("viodasd", i);	for (i = 0; i < HVMAXARCHITECTEDVIRTUALCDROMS; i++)		vio_register_device_iseries("viocd", i);	for (i = 0; i < HVMAXARCHITECTEDVIRTUALTAPES; i++)		vio_register_device_iseries("viotape", i);}#endif/** * vio_bus_init: - Initialize the virtual IO bus */static int __init vio_bus_init(void){	int err;	err = bus_register(&vio_bus_type);	if (err) {		printk(KERN_ERR "failed to register VIO bus\n");		return err;	}	/* the fake parent of all vio devices, just to give us a nice directory */	vio_bus_device = kmalloc(sizeof(struct vio_dev), GFP_KERNEL);	if (!vio_bus_device) {		return 1;	}	memset(vio_bus_device, 0, sizeof(struct vio_dev));	strcpy(vio_bus_device->dev.bus_id, "vio");	err = device_register(&vio_bus_device->dev);	if (err) {		printk(KERN_WARNING "%s: device_register returned %i\n", __FUNCTION__,			err);		kfree(vio_bus_device);		return err;	}#ifdef CONFIG_PPC_PSERIES	probe_bus_pseries();#endif#ifdef CONFIG_PPC_ISERIES	probe_bus_iseries();#endif	return 0;}__initcall(vio_bus_init);/* vio_dev refcount hit 0 */static void __devinit vio_dev_release(struct device *dev){	DBGENTER();#ifdef CONFIG_PPC_PSERIES	/* XXX free TCE table */	of_node_put(dev->platform_data);#endif	kfree(to_vio_dev(dev));}#ifdef CONFIG_PPC_PSERIESstatic ssize_t viodev_show_devspec(struct device *dev, char *buf){	struct device_node *of_node = dev->platform_data;	return sprintf(buf, "%s\n", of_node->full_name);}DEVICE_ATTR(devspec, S_IRUSR | S_IRGRP | S_IROTH, viodev_show_devspec, NULL);#endifstatic ssize_t viodev_show_name(struct device *dev, char *buf){	return sprintf(buf, "%s\n", to_vio_dev(dev)->name);}DEVICE_ATTR(name, S_IRUSR | S_IRGRP | S_IROTH, viodev_show_name, NULL);static struct vio_dev * __devinit vio_register_device_common(		struct vio_dev *viodev, char *name, char *type,		uint32_t unit_address, struct iommu_table *iommu_table){	DBGENTER();	viodev->name = name;	viodev->type = type;	viodev->unit_address = unit_address;	viodev->iommu_table = iommu_table;

⌨️ 快捷键说明

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