From: Rob Herring <hidden> Date: 2011-06-08 16:40:01
Mark,
On 06/08/2011 10:54 AM, Mark Rutland wrote:
Hi,
quoted
static int __devinit pmu_device_probe(struct platform_device *pdev)
{
+ enum arm_pmu_type type = pdev->id;
- if (pdev->id< 0 || pdev->id>= ARM_NUM_PMU_DEVICES) {
+ if (pdev->dev.of_node)
+ type = ARM_PMU_DEVICE_CPU;
+
+ if (type< 0 || type>= ARM_NUM_PMU_DEVICES) {
pr_warning("received registration request for unknown "
"device %d\n", pdev->id);
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;
}
I don't think this is the best way to handle the type when we've got an FDT
description:
* release_pmu hasn't been updated to match the type logic here, so it might do
anything when handed a platform_device initialised by FDT code.
* the warning message for an invalid registration still uses pdev->id rather
than type. This can't currently be reached when the PMU was handed to us via
FDT, but it may confuse refactoring later on.
* If we want to add a new PMU type, we'll have to add more logic to
pmu_device_probe. Given that work is going on to add support for system PMUs,
this doesn't seem particularly brilliant.
This all seems fine for handling CPU PMUs.
I think that a better strategy would be to separate the type logic from the
registration. I have a patch for this:
http://lists.infradead.org/pipermail/linux-arm-kernel/2011-June/052455.html
With it, you won't need to change pmu_device_probe, and adding FDT support
should just be a matter of adding the of_match_table.
Okay. I'll rebase mine on top of your changes.
Rob
Hi Rob,
I've Addded Jamie on Cc here as he was interested in the possibility of
adding platform_device_id tables. Hopefully it'll be easy to discuss
{of,platform}_id_tables in one thread.
As Jamie pointed out to me the existence of platform_device_id tables,
I took a look around and noticed that of_device_id tables also seem to
provide support for driver-specific parameters (I saw an example of
usage in arch/sparc/kernel/pci_schizo.c).
I've had a go at getting {of,platform}_device_id tables to provide the
PMU type, so they can be used similarly (the macros make entries look
identical apart from the {plat,of} prefix).
I don't have any entries currently for the platform_device_id table,
but it'd be useful for system pmus, if we were to add an L2 Cache
controller PMU driver, it might have a binding like:
PLAT_MATCH("arm,pl310-pmu", ARM_PMU_TYPE_L2CC),
How does the following series look to you? The first 2 patches are the
ones I mentioned before, unchanged (apart from additional acks).
Mark.
Mark Rutland (4):
ARM: pmu: refactor reservation
ARM: pmu: reject duplicate PMU registrations
ARM: pmu: add OF probing support
ARM: pmu: add platform_device_id table support
Documentation/devicetree/bindings/arm/pmu.txt | 22 ++++++
arch/arm/include/asm/pmu.h | 2 +-
arch/arm/kernel/perf_event.c | 4 +-
arch/arm/kernel/pmu.c | 91 ++++++++++++++++++++-----
4 files changed, 99 insertions(+), 20 deletions(-)
create mode 100644 Documentation/devicetree/bindings/arm/pmu.txt
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 <redacted>
Acked-by: Will Deacon <redacted>
Cc: Rob Herring <redacted>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
---
arch/arm/include/asm/pmu.h | 2 +-
arch/arm/kernel/perf_event.c | 4 ++--
arch/arm/kernel/pmu.c | 33 +++++++++++++++++++--------------
3 files changed, 22 insertions(+), 17 deletions(-)
@@ -25,36 +25,41 @@ static volatile long pmu_lock;staticstructplatform_device*pmu_devices[ARM_NUM_PMU_DEVICES];-staticint__devinitpmu_device_probe(structplatform_device*pdev)+staticint__devinitpmu_register(structplatform_device*pdev,+enumarm_pmu_typetype){--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);elsepr_info("registered new PMU device of type %d\n",-pdev->id);+type);-pmu_devices[pdev->id]=pdev;+pmu_devices[type]=pdev;return0;}-staticstructplatform_driverpmu_driver={+staticint__devinitarmpmu_device_probe(structplatform_device*pdev)+{+returnpmu_register(pdev,ARM_PMU_DEVICE_CPU);+}++staticstructplatform_driverarmpmu_driver={.driver={.name="arm-pmu",},-.probe=pmu_device_probe,+.probe=armpmu_device_probe,};staticint__initregister_pmu_driver(void){-returnplatform_driver_register(&pmu_driver);+returnplatform_driver_register(&armpmu_driver);}device_initcall(register_pmu_driver);
Currently, the PMU reservation framework allows for multiple PMUs of
the same type to register themselves. This can lead to a bug with the
sequence:
register_pmu(pmu1);
reserve_pmu(pmu_type);
register_pmu(pmu2);
release_pmu(pmu1);
Here, pmu1 cannot be released, and pmu2 cannot be reserved.
This patch modifies register_pmu to reject registrations where a PMU is
already present, preventing this problem. PMUs which can have multiple
instances should not use the PMU reservation framework.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Acked-By: Jamie Iles <redacted>
Acked-By: Will Deacon <redacted>
---
arch/arm/kernel/pmu.c | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
@@ -34,13 +34,13 @@ static int __devinit pmu_register(struct platform_device *pdev,return-EINVAL;}-if(pmu_devices[type])-pr_warning("registering new PMU device type %d overwrites "-"previous registration!\n",type);-else-pr_info("registered new PMU device of type %d\n",-type);+if(pmu_devices[type]){+pr_warning("rejecting duplicate registration of PMU device "+"type %d.",type);+return-ENOSPC;+}+pr_info("registered new PMU device of type %d\n",type);pmu_devices[type]=pdev;return0;}
This is based on an earlier patch from Rob Herring [off-list ref]
Add OF match table to enable OF style driver binding. The dts entry is like
this:
pmu {
compatible = "arm,cortex-a9-pmu";
interrupts = <100 101>;
};
The use of pdev->id as an index breaks with OF device binding, so set the type
based on the OF compatible string.
This modification sets the PMU hardware type based on data embedded in the
binding, allowing easy addition of new PMU types in future.
Support for new PMU types not provided by devicetree can be added later using
platform_device_id tables in a similar fashion.
Cc: Jamie Iles <redacted>
Cc: Rob Herring <redacted>
Cc: Will Deacon <redacted>
---
Rob: would you be happy to merge this into your tree? or would you
rather I sent it through Russell?
Documentation/devicetree/bindings/arm/pmu.txt | 22 +++++++++++++++
arch/arm/kernel/pmu.c | 35 ++++++++++++++++++++++++-
2 files changed, 56 insertions(+), 1 deletions(-)
create mode 100644 Documentation/devicetree/bindings/arm/pmu.txt
@@ -0,0 +1,22 @@+* ARM Performance Monitor Units++ARM cores often have a PMU for counting cpu and cache events like cache misses+and hits. The interface to the PMU is part of the ARM ARM. The ARM PMU+representation in the device tree should be done as under:-++Required properties:++- compatible : should be one of+ "arm,cortex-a9-pmu"+ "arm,cortex-a8-pmu"+ "arm,arm1176-pmu"+ "arm,arm1136-pmu"+- interrupts : 1 combined interrupt or 1 per core.++Example:++pmu {+ compatible = "arm,cortex-a9-pmu";+ interrupts = <100 101>;+};+
This patch adds support for platform_device_id tables, allowing new
PMU types to be registered with the correct type, without requiring
new platform_driver shims to provide the type.
Macros matching functionality of the of_device_id table macros are
provided for convenience.
Cc: Jamie Iles <redacted>
Cc: Will Deacon <redacted>
---
arch/arm/kernel/pmu.c | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
From: Sergei Shtylyov <hidden> Date: 2011-06-13 12:33:08
Hello.
On 13-06-2011 13:35, Mark Rutland wrote:
This patch adds support for platform_device_id tables, allowing new
PMU types to be registered with the correct type, without requiring
new platform_driver shims to provide the type.
Macros matching functionality of the of_device_id table macros are
provided for convenience.
-----Original Message-----
From: Sergei Shtylyov [mailto:sshtylyov at mvista.com]
Sent: 13 June 2011 13:33
To: Mark Rutland
Cc: Rob Herring; Jamie Iles; Will Deacon; linux-arm-
kernel at lists.infradead.org
Subject: Re: [PATCH 4/4] ARM: pmu: add platform_device_id table support
Hello.
On 13-06-2011 13:35, Mark Rutland wrote:
quoted
This patch adds support for platform_device_id tables, allowing new
PMU types to be registered with the correct type, without requiring
new platform_driver shims to provide the type.
quoted
Macros matching functionality of the of_device_id table macros are
provided for convenience.
From: Rob Herring <hidden> Date: 2011-06-13 13:40:27
Mark,
On 06/13/2011 04:35 AM, Mark Rutland wrote:
This is based on an earlier patch from Rob Herring [off-list ref]
quoted
Add OF match table to enable OF style driver binding. The dts entry is like
this:
pmu {
compatible = "arm,cortex-a9-pmu";
interrupts = <100 101>;
};
The use of pdev->id as an index breaks with OF device binding, so set the type
based on the OF compatible string.
This modification sets the PMU hardware type based on data embedded in the
binding, allowing easy addition of new PMU types in future.
Support for new PMU types not provided by devicetree can be added later using
platform_device_id tables in a similar fashion.
Cc: Jamie Iles <redacted>
Cc: Rob Herring <redacted>
Cc: Will Deacon <redacted>
---
Rob: would you be happy to merge this into your tree? or would you
rather I sent it through Russell?
Looks good to me. I'm happy for you to take it.
Rob
-----Original Message-----
From: Rob Herring [mailto:robherring2 at gmail.com]
Sent: 13 June 2011 14:40
To: Mark Rutland
Cc: linux-arm-kernel at lists.infradead.org; Jamie Iles; Will Deacon
Subject: Re: [PATCH 3/4] ARM: pmu: add OF probing support
Mark,
On 06/13/2011 04:35 AM, Mark Rutland wrote:
quoted
This is based on an earlier patch from Rob Herring
[off-list ref]
quoted
quoted
Add OF match table to enable OF style driver binding. The dts entry
is like
quoted
quoted
this:
pmu {
compatible = "arm,cortex-a9-pmu";
interrupts = <100 101>;
};
The use of pdev->id as an index breaks with OF device binding, so
set the type
quoted
quoted
based on the OF compatible string.
This modification sets the PMU hardware type based on data embedded
in the
quoted
binding, allowing easy addition of new PMU types in future.
Support for new PMU types not provided by devicetree can be added
later using
quoted
platform_device_id tables in a similar fashion.
Cc: Jamie Iles <redacted>
Cc: Rob Herring <redacted>
Cc: Will Deacon <redacted>
---
Rob: would you be happy to merge this into your tree? or would you
rather I sent it through Russell?
Looks good to me. I'm happy for you to take it.
Rob
Thanks. Mind if I add your Ack?
Mark.
-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
From: Rob Herring <hidden> Date: 2011-06-13 13:55:05
On 06/13/2011 08:48 AM, Mark Rutland wrote:
quoted
-----Original Message-----
From: Rob Herring [mailto:robherring2 at gmail.com]
Sent: 13 June 2011 14:40
To: Mark Rutland
Cc: linux-arm-kernel at lists.infradead.org; Jamie Iles; Will Deacon
Subject: Re: [PATCH 3/4] ARM: pmu: add OF probing support
Mark,
On 06/13/2011 04:35 AM, Mark Rutland wrote:
quoted
This is based on an earlier patch from Rob Herring
[off-list ref]
quoted
quoted
Add OF match table to enable OF style driver binding. The dts entry
is like
quoted
quoted
this:
pmu {
compatible = "arm,cortex-a9-pmu";
interrupts = <100 101>;
};
The use of pdev->id as an index breaks with OF device binding, so
set the type
quoted
quoted
based on the OF compatible string.
This modification sets the PMU hardware type based on data embedded
in the
quoted
binding, allowing easy addition of new PMU types in future.
Support for new PMU types not provided by devicetree can be added
later using
quoted
platform_device_id tables in a similar fashion.
Cc: Jamie Iles <redacted>
Cc: Rob Herring <redacted>
Cc: Will Deacon <redacted>
---
Rob: would you be happy to merge this into your tree? or would you
rather I sent it through Russell?
Looks good to me. I'm happy for you to take it.
Rob
On Mon, Jun 13, 2011 at 10:35:57AM +0100, Mark Rutland wrote:
quoted hunk
This patch adds support for platform_device_id tables, allowing new
PMU types to be registered with the correct type, without requiring
new platform_driver shims to provide the type.
Macros matching functionality of the of_device_id table macros are
provided for convenience.
Cc: Jamie Iles <redacted>
Cc: Will Deacon <redacted>
---
arch/arm/kernel/pmu.c | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
I guess we could put "arm-pmu" in here but I'm not sure it's worth a
respin.
The series looks nice though, feel free to add my Acked-by for them.
Acked-by: Jamie Iles <redacted>
Jamie
From: Grant Likely <hidden> Date: 2011-06-13 16:44:14
On Wed, Jun 08, 2011 at 11:40:01AM -0500, Rob Herring wrote:
Mark,
On 06/08/2011 10:54 AM, Mark Rutland wrote:
quoted
Hi,
quoted
static int __devinit pmu_device_probe(struct platform_device *pdev)
{
+ enum arm_pmu_type type = pdev->id;
- if (pdev->id< 0 || pdev->id>= ARM_NUM_PMU_DEVICES) {
+ if (pdev->dev.of_node)
+ type = ARM_PMU_DEVICE_CPU;
+
+ if (type< 0 || type>= ARM_NUM_PMU_DEVICES) {
pr_warning("received registration request for unknown "
"device %d\n", pdev->id);
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;
}
I don't think this is the best way to handle the type when we've got an FDT
description:
* release_pmu hasn't been updated to match the type logic here, so it might do
anything when handed a platform_device initialised by FDT code.
* the warning message for an invalid registration still uses pdev->id rather
than type. This can't currently be reached when the PMU was handed to us via
FDT, but it may confuse refactoring later on.
* If we want to add a new PMU type, we'll have to add more logic to
pmu_device_probe. Given that work is going on to add support for system PMUs,
this doesn't seem particularly brilliant.
This all seems fine for handling CPU PMUs.
I think that a better strategy would be to separate the type logic from the
registration. I have a patch for this:
http://lists.infradead.org/pipermail/linux-arm-kernel/2011-June/052455.html
With it, you won't need to change pmu_device_probe, and adding FDT support
should just be a matter of adding the of_match_table.