Hi Greg, On Wed, Sep 07, 2011 at 03:44:45PM -0400, Greg KH wrote: > > > > The IOMMUs are usually devices on the bus itself, so they are > > initialized after the bus is set up and the devices on it are > > populated. So the function can not be called on bus initialization > > because the IOMMU is not ready at this point. > > Ok, that makes more sense, please state as much in the documentation. I added the kernel-doc documentation you requested. Here is the updated patch. Please let me know what you think. >From 23757825035f6d9309866dc142133aada0e2c1de Mon Sep 17 00:00:00 2001 From: Joerg Roedel <joerg.roedel@xxxxxxx> Date: Fri, 26 Aug 2011 16:48:26 +0200 Subject: [PATCH 02/10] Driver core: Add iommu_ops to bus_type This is the starting point to make the iommu_ops used for the iommu-api a per-bus-type structure. It is required to easily implement bus-specific setup in the iommu-layer. The first user will be the iommu-group attribute in sysfs. Signed-off-by: Joerg Roedel <joerg.roedel@xxxxxxx> --- drivers/base/bus.c | 29 +++++++++++++++++++++++++++++ drivers/iommu/iommu.c | 4 ++++ include/linux/device.h | 9 +++++++++ include/linux/iommu.h | 2 ++ 4 files changed, 44 insertions(+), 0 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 000e7b2..b3014fe 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -1028,6 +1028,35 @@ void bus_sort_breadthfirst(struct bus_type *bus, } EXPORT_SYMBOL_GPL(bus_sort_breadthfirst); +#ifdef CONFIG_IOMMU_API +/** + * bus_set_iommu - set iommu-callbacks for the bus + * @bus: bus. + * @ops: the callbacks provided by the iommu-driver + * + * This function is called by an iommu driver to set the iommu methods + * used for a particular bus. Drivers for devices on that bus can use + * the iommu-api after these ops are registered. + * This special function is needed because IOMMUs are usually devices on + * the bus itself, so the iommu drivers are not initialized when the bus + * is set up. With this function the iommu-driver can set the iommu-ops + * afterwards. + */ +int bus_set_iommu(struct bus_type *bus, struct iommu_ops *ops) +{ + if (bus->iommu_ops != NULL) + return -EBUSY; + + bus->iommu_ops = ops; + + /* Do IOMMU specific setup for this bus-type */ + iommu_bus_init(bus, ops); + + return 0; +} +EXPORT_SYMBOL_GPL(bus_set_iommu); +#endif + int __init buses_init(void) { bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL); diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 30b0644..3b24a5b 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -34,6 +34,10 @@ void register_iommu(struct iommu_ops *ops) iommu_ops = ops; } +void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops) +{ +} + bool iommu_found(void) { return iommu_ops != NULL; diff --git a/include/linux/device.h b/include/linux/device.h index c20dfbf..8240b2a 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -22,6 +22,7 @@ #include <linux/types.h> #include <linux/module.h> #include <linux/pm.h> +#include <linux/iommu.h> #include <linux/atomic.h> #include <asm/device.h> @@ -67,6 +68,9 @@ extern void bus_remove_file(struct bus_type *, struct bus_attribute *); * @resume: Called to bring a device on this bus out of sleep mode. * @pm: Power management operations of this bus, callback the specific * device driver's pm-ops. + * @iommu_ops IOMMU specific operations for this bus, used to attach IOMMU + * driver implementations to a bus and allow the driver to do + * bus-specific setup * @p: The private data of the driver core, only the driver core can * touch this. * @@ -96,6 +100,8 @@ struct bus_type { const struct dev_pm_ops *pm; + struct iommu_ops *iommu_ops; + struct subsys_private *p; }; @@ -148,6 +154,9 @@ extern int bus_unregister_notifier(struct bus_type *bus, #define BUS_NOTIFY_UNBOUND_DRIVER 0x00000006 /* driver is unbound from the device */ +/* IOMMU related bus functions */ +int bus_set_iommu(struct bus_type *bus, struct iommu_ops *ops); + extern struct kset *bus_get_kset(struct bus_type *bus); extern struct klist *bus_get_device_klist(struct bus_type *bus); diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 6470cd8..4739e36 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -25,6 +25,7 @@ #define IOMMU_WRITE (2) #define IOMMU_CACHE (4) /* DMA cache coherency */ +struct bus_type; struct device; struct iommu_domain { @@ -52,6 +53,7 @@ struct iommu_ops { }; extern void register_iommu(struct iommu_ops *ops); +extern void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops); extern bool iommu_found(void); extern struct iommu_domain *iommu_domain_alloc(void); extern void iommu_domain_free(struct iommu_domain *domain); -- 1.7.4.1 -- AMD Operating System Research Center Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach General Managers: Alberto Bozzo, Andrew Bowd Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html