ARM: 6974/1: pmu: refactor reservation
authorMark Rutland <mark.rutland@arm.com>
Wed, 22 Jun 2011 14:30:51 +0000 (15:30 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Wed, 29 Jun 2011 09:27:08 +0000 (10:27 +0100)
Currently, PMU platform_device reservation relies on some minor abuse
of the platform_device::id field for determining the type of PMU. This
is problematic for device tree based probing, where the ID cannot be
controlled.

This patch removes reliance on the id field, and depends on each PMU's
platform driver to figure out which type it is. As all PMUs handled by
the current platform_driver name "arm-pmu" are CPU PMUs, this
convention is hardcoded. New PMU types can be supported through the use
of {of,platform}_device_id tables

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Jamie Iles <jamie@jamieiles.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Cc: Rob Herring <rob.herring@calxeda.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/include/asm/pmu.h
arch/arm/kernel/perf_event.c
arch/arm/kernel/pmu.c

index 7544ce6b481ac4ba4a369e0b2445cbc638a15078..67c70a31a1be33c34ecdd271c343767342a83dfe 100644 (file)
@@ -52,7 +52,7 @@ reserve_pmu(enum arm_pmu_type device);
  * a cookie.
  */
 extern int
-release_pmu(struct platform_device *pdev);
+release_pmu(enum arm_pmu_type type);
 
 /**
  * init_pmu() - Initialise the PMU.
index d53c0abc4dd3aaa375595fcd4d54527f013b41f8..a6c643f2d2ca24bd5ffb4a332e58dba84283fa6e 100644 (file)
@@ -435,7 +435,7 @@ armpmu_reserve_hardware(void)
                        if (irq >= 0)
                                free_irq(irq, NULL);
                }
-               release_pmu(pmu_device);
+               release_pmu(ARM_PMU_DEVICE_CPU);
                pmu_device = NULL;
        }
 
@@ -454,7 +454,7 @@ armpmu_release_hardware(void)
        }
        armpmu->stop();
 
-       release_pmu(pmu_device);
+       release_pmu(ARM_PMU_DEVICE_CPU);
        pmu_device = NULL;
 }
 
index 2c79eec192629b9b3e2a91914adcfbf3f8312723..87942b931c62ef9c22e82db66ddf35b0b3db6191 100644 (file)
@@ -25,36 +25,41 @@ static volatile long pmu_lock;
 
 static struct platform_device *pmu_devices[ARM_NUM_PMU_DEVICES];
 
-static int __devinit pmu_device_probe(struct platform_device *pdev)
+static int __devinit pmu_register(struct platform_device *pdev,
+                                       enum arm_pmu_type type)
 {
-
-       if (pdev->id < 0 || pdev->id >= ARM_NUM_PMU_DEVICES) {
+       if (type < 0 || type >= ARM_NUM_PMU_DEVICES) {
                pr_warning("received registration request for unknown "
-                               "device %d\n", pdev->id);
+                               "device %d\n", type);
                return -EINVAL;
        }
 
-       if (pmu_devices[pdev->id])
+       if (pmu_devices[type])
                pr_warning("registering new PMU device type %d overwrites "
-                               "previous registration!\n", pdev->id);
+                               "previous registration!\n", type);
        else
                pr_info("registered new PMU device of type %d\n",
-                               pdev->id);
+                               type);
 
-       pmu_devices[pdev->id] = pdev;
+       pmu_devices[type] = pdev;
        return 0;
 }
 
-static struct platform_driver pmu_driver = {
+static int __devinit armpmu_device_probe(struct platform_device *pdev)
+{
+       return pmu_register(pdev, ARM_PMU_DEVICE_CPU);
+}
+
+static struct platform_driver armpmu_driver = {
        .driver         = {
                .name   = "arm-pmu",
        },
-       .probe          = pmu_device_probe,
+       .probe          = armpmu_device_probe,
 };
 
 static int __init register_pmu_driver(void)
 {
-       return platform_driver_register(&pmu_driver);
+       return platform_driver_register(&armpmu_driver);
 }
 device_initcall(register_pmu_driver);
 
@@ -77,11 +82,11 @@ reserve_pmu(enum arm_pmu_type device)
 EXPORT_SYMBOL_GPL(reserve_pmu);
 
 int
-release_pmu(struct platform_device *pdev)
+release_pmu(enum arm_pmu_type device)
 {
-       if (WARN_ON(pdev != pmu_devices[pdev->id]))
+       if (WARN_ON(!pmu_devices[device]))
                return -EINVAL;
-       clear_bit_unlock(pdev->id, &pmu_lock);
+       clear_bit_unlock(device, &pmu_lock);
        return 0;
 }
 EXPORT_SYMBOL_GPL(release_pmu);