* [PATCH] ARM: dts: aspeed: cmm: enable ehci host controllers
From: Tao Ren @ 2019-05-09 3:43 UTC (permalink / raw)
To: linux-aspeed
Enable ehci0 and ehci1 USB host controllers on Facebook Backpack CMM BMC.
Signed-off-by: Tao Ren <taoren@fb.com>
---
arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts b/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts
index 43aba4071a5c..d519d307aa2a 100644
--- a/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-cmm.dts
@@ -372,3 +372,11 @@
&adc {
status = "okay";
};
+
+&ehci0 {
+ status = "okay";
+};
+
+&ehci1 {
+ status = "okay";
+};
--
2.17.1
^ permalink raw reply related
* [PATCH] ARM: dts: aspeed: Add Facebook YAMP BMC
From: Tao Ren @ 2019-05-09 3:55 UTC (permalink / raw)
To: linux-aspeed
Add initial version of device tree for Facebook YAMP ast2500 BMC.
Signed-off-by: Tao Ren <taoren@fb.com>
---
arch/arm/boot/dts/Makefile | 1 +
.../arm/boot/dts/aspeed-bmc-facebook-yamp.dts | 160 ++++++++++++++++++
2 files changed, 161 insertions(+)
create mode 100644 arch/arm/boot/dts/aspeed-bmc-facebook-yamp.dts
diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
index f4f5aeaf3298..710616dcb62e 100644
--- a/arch/arm/boot/dts/Makefile
+++ b/arch/arm/boot/dts/Makefile
@@ -1254,6 +1254,7 @@ dtb-$(CONFIG_ARCH_ASPEED) += \
aspeed-bmc-arm-stardragon4800-rep2.dtb \
aspeed-bmc-facebook-cmm.dtb \
aspeed-bmc-facebook-tiogapass.dtb \
+ aspeed-bmc-facebook-yamp.dtb \
aspeed-bmc-intel-s2600wf.dtb \
aspeed-bmc-opp-lanyang.dtb \
aspeed-bmc-opp-palmetto.dtb \
diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-yamp.dts b/arch/arm/boot/dts/aspeed-bmc-facebook-yamp.dts
new file mode 100644
index 000000000000..4e09a9cf32b7
--- /dev/null
+++ b/arch/arm/boot/dts/aspeed-bmc-facebook-yamp.dts
@@ -0,0 +1,160 @@
+// SPDX-License-Identifier: GPL-2.0+
+// Copyright (c) 2018 Facebook Inc.
+/dts-v1/;
+
+#include "aspeed-g5.dtsi"
+
+/ {
+ model = "Facebook YAMP 100 BMC";
+ compatible = "facebook,yamp-bmc", "aspeed,ast2500";
+
+ aliases {
+ /*
+ * Override the default uart aliases to avoid breaking
+ * the legacy applications.
+ */
+ serial0 = &uart5;
+ serial1 = &uart1;
+ serial2 = &uart2;
+ serial3 = &uart3;
+ };
+
+ chosen {
+ stdout-path = &uart5;
+ bootargs = "console=ttyS0,9600n8 root=/dev/ram rw";
+ };
+
+ memory at 80000000 {
+ reg = <0x80000000 0x20000000>;
+ };
+};
+
+&pinctrl {
+ aspeed,external-nodes = <&gfx &lhc>;
+};
+
+/*
+ * Update reset type to "system" (full chip) to fix warm reboot hang issue
+ * when reset type is set to default ("soc", gated by reset mask registers).
+ */
+&wdt1 {
+ status = "okay";
+ aspeed,reset-type = "system";
+};
+
+/*
+ * wdt2 is not used by Yamp.
+ */
+&wdt2 {
+ status = "disabled";
+};
+
+&fmc {
+ status = "okay";
+ flash at 0 {
+ status = "okay";
+ m25p,fast-read;
+ label = "bmc";
+#include "facebook-bmc-flash-layout.dtsi"
+ };
+};
+
+&uart1 {
+ status = "okay";
+ pinctrl-names = "default";
+ pinctrl-0 = <&pinctrl_txd1_default
+ &pinctrl_rxd1_default>;
+};
+
+&uart2 {
+ status = "okay";
+ pinctrl-names = "default";
+ pinctrl-0 = <&pinctrl_txd2_default
+ &pinctrl_rxd2_default>;
+};
+
+&uart3 {
+ status = "okay";
+ pinctrl-names = "default";
+ pinctrl-0 = <&pinctrl_txd3_default
+ &pinctrl_rxd3_default>;
+};
+
+&uart5 {
+ status = "okay";
+};
+
+&mac0 {
+ status = "okay";
+ use-ncsi;
+ no-hw-checksum;
+ pinctrl-names = "default";
+ pinctrl-0 = <&pinctrl_rmii1_default>;
+};
+
+&i2c0 {
+ status = "okay";
+};
+
+&i2c1 {
+ status = "okay";
+};
+
+&i2c2 {
+ status = "okay";
+
+ i2c-switch at 75 {
+ compatible = "nxp,pca9548";
+ #address-cells = <1>;
+ #size-cells = <0>;
+ reg = <0x75>;
+ };
+};
+
+&i2c3 {
+ status = "okay";
+};
+
+&i2c4 {
+ status = "okay";
+};
+
+&i2c5 {
+ status = "okay";
+};
+
+&i2c6 {
+ status = "okay";
+};
+
+&i2c7 {
+ status = "okay";
+};
+
+&i2c8 {
+ status = "okay";
+};
+
+&i2c9 {
+ status = "okay";
+};
+
+&i2c10 {
+ status = "okay";
+};
+
+&i2c11 {
+ status = "okay";
+};
+
+&i2c12 {
+ status = "okay";
+};
+
+&i2c13 {
+ status = "okay";
+};
+
+&vhub {
+ status = "okay";
+};
--
2.17.1
^ permalink raw reply related
* [PATCH] ARM: dts: aspeed: Add Facebook YAMP BMC
From: Andrew Jeffery @ 2019-05-09 6:06 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <20190509035549.2203169-1-taoren@fb.com>
On Thu, 9 May 2019, at 13:26, Tao Ren wrote:
> Add initial version of device tree for Facebook YAMP ast2500 BMC.
>
> Signed-off-by: Tao Ren <taoren@fb.com>
Acked-by: Andrew Jeffery <andrew@aj.id.au>
> ---
> arch/arm/boot/dts/Makefile | 1 +
> .../arm/boot/dts/aspeed-bmc-facebook-yamp.dts | 160 ++++++++++++++++++
> 2 files changed, 161 insertions(+)
> create mode 100644 arch/arm/boot/dts/aspeed-bmc-facebook-yamp.dts
>
> diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
> index f4f5aeaf3298..710616dcb62e 100644
> --- a/arch/arm/boot/dts/Makefile
> +++ b/arch/arm/boot/dts/Makefile
> @@ -1254,6 +1254,7 @@ dtb-$(CONFIG_ARCH_ASPEED) += \
> aspeed-bmc-arm-stardragon4800-rep2.dtb \
> aspeed-bmc-facebook-cmm.dtb \
> aspeed-bmc-facebook-tiogapass.dtb \
> + aspeed-bmc-facebook-yamp.dtb \
> aspeed-bmc-intel-s2600wf.dtb \
> aspeed-bmc-opp-lanyang.dtb \
> aspeed-bmc-opp-palmetto.dtb \
> diff --git a/arch/arm/boot/dts/aspeed-bmc-facebook-yamp.dts
> b/arch/arm/boot/dts/aspeed-bmc-facebook-yamp.dts
> new file mode 100644
> index 000000000000..4e09a9cf32b7
> --- /dev/null
> +++ b/arch/arm/boot/dts/aspeed-bmc-facebook-yamp.dts
> @@ -0,0 +1,160 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +// Copyright (c) 2018 Facebook Inc.
> +/dts-v1/;
> +
> +#include "aspeed-g5.dtsi"
> +
> +/ {
> + model = "Facebook YAMP 100 BMC";
> + compatible = "facebook,yamp-bmc", "aspeed,ast2500";
> +
> + aliases {
> + /*
> + * Override the default uart aliases to avoid breaking
> + * the legacy applications.
> + */
> + serial0 = &uart5;
> + serial1 = &uart1;
> + serial2 = &uart2;
> + serial3 = &uart3;
> + };
> +
> + chosen {
> + stdout-path = &uart5;
> + bootargs = "console=ttyS0,9600n8 root=/dev/ram rw";
> + };
> +
> + memory at 80000000 {
> + reg = <0x80000000 0x20000000>;
> + };
> +};
> +
> +&pinctrl {
> + aspeed,external-nodes = <&gfx &lhc>;
> +};
> +
> +/*
> + * Update reset type to "system" (full chip) to fix warm reboot hang
> issue
> + * when reset type is set to default ("soc", gated by reset mask
> registers).
> + */
> +&wdt1 {
> + status = "okay";
> + aspeed,reset-type = "system";
> +};
> +
> +/*
> + * wdt2 is not used by Yamp.
> + */
> +&wdt2 {
> + status = "disabled";
> +};
> +
> +&fmc {
> + status = "okay";
> + flash at 0 {
> + status = "okay";
> + m25p,fast-read;
> + label = "bmc";
> +#include "facebook-bmc-flash-layout.dtsi"
> + };
> +};
> +
> +&uart1 {
> + status = "okay";
> + pinctrl-names = "default";
> + pinctrl-0 = <&pinctrl_txd1_default
> + &pinctrl_rxd1_default>;
> +};
> +
> +&uart2 {
> + status = "okay";
> + pinctrl-names = "default";
> + pinctrl-0 = <&pinctrl_txd2_default
> + &pinctrl_rxd2_default>;
> +};
> +
> +&uart3 {
> + status = "okay";
> + pinctrl-names = "default";
> + pinctrl-0 = <&pinctrl_txd3_default
> + &pinctrl_rxd3_default>;
> +};
> +
> +&uart5 {
> + status = "okay";
> +};
> +
> +&mac0 {
> + status = "okay";
> + use-ncsi;
> + no-hw-checksum;
> + pinctrl-names = "default";
> + pinctrl-0 = <&pinctrl_rmii1_default>;
> +};
> +
> +&i2c0 {
> + status = "okay";
> +};
> +
> +&i2c1 {
> + status = "okay";
> +};
> +
> +&i2c2 {
> + status = "okay";
> +
> + i2c-switch at 75 {
> + compatible = "nxp,pca9548";
> + #address-cells = <1>;
> + #size-cells = <0>;
> + reg = <0x75>;
> + };
> +};
> +
> +&i2c3 {
> + status = "okay";
> +};
> +
> +&i2c4 {
> + status = "okay";
> +};
> +
> +&i2c5 {
> + status = "okay";
> +};
> +
> +&i2c6 {
> + status = "okay";
> +};
> +
> +&i2c7 {
> + status = "okay";
> +};
> +
> +&i2c8 {
> + status = "okay";
> +};
> +
> +&i2c9 {
> + status = "okay";
> +};
> +
> +&i2c10 {
> + status = "okay";
> +};
> +
> +&i2c11 {
> + status = "okay";
> +};
> +
> +&i2c12 {
> + status = "okay";
> +};
> +
> +&i2c13 {
> + status = "okay";
> +};
> +
> +&vhub {
> + status = "okay";
> +};
> --
> 2.17.1
>
>
^ permalink raw reply
* [PATCH 1/7] media: aspeed: fix a kernel warning on clk control
From: Eddie James @ 2019-05-09 15:19 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <b682cc6a480f2b8a5e14c5c001fa1927467d4e18.camel@kernel.crashing.org>
On 5/8/19 9:16 PM, Benjamin Herrenschmidt wrote:
> On Wed, 2019-05-08 at 18:19 -0700, Jae Hyun Yoo wrote:
>> I changed that from a bool because the maintainer of this code, Eddie
>> doesn't like adding of an additional flag. I'll change it back with
>> codes in the first submit:
>> https://www.spinics.net/lists/linux-media/msg148955.html
>>
>> Eddie,
>> Please let me know if you have any objection on that.
Thats fine with me. I merely thought it was more conventional to use
flags rather than bools, but I may be mistaken.
Thanks!
Eddie
> Ok, so random flags ... ugh.
>
> Well, you can approach it either way. Have them all be bitops or all be
> bool.
>
> The tricky thing however is that if they are bitops you need to ensure
> that they are *all* manipulated under the same lock. If not you have to
> use the atomic bitops variants.
>
> The reason I don't like that is that experience shows that most uses of
> such atomic variants in drivers usually are failed attempts at papering
> over broken locking.
>
> If everything is covered by a lock, then using the non-atomic versions
> is more efficient, but so is using bool (optionally with :1 bitfield
> qualifiers to avoid wasting memory), which from a pure C language
> perspective I think is more expressive of what you are doing and more
> readable.
>
> Cheers,
> Ben.
>
^ permalink raw reply
* [PATCH 1/7] media: aspeed: fix a kernel warning on clk control
From: Jae Hyun Yoo @ 2019-05-09 17:19 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <b682cc6a480f2b8a5e14c5c001fa1927467d4e18.camel@kernel.crashing.org>
On 5/8/2019 7:16 PM, Benjamin Herrenschmidt wrote:
> On Wed, 2019-05-08 at 18:19 -0700, Jae Hyun Yoo wrote:
>> I changed that from a bool because the maintainer of this code, Eddie
>> doesn't like adding of an additional flag. I'll change it back with
>> codes in the first submit:
>> https://www.spinics.net/lists/linux-media/msg148955.html
>>
>> Eddie,
>> Please let me know if you have any objection on that.
>
> Ok, so random flags ... ugh.
>
> Well, you can approach it either way. Have them all be bitops or all be
> bool.
>
> The tricky thing however is that if they are bitops you need to ensure
> that they are *all* manipulated under the same lock. If not you have to
> use the atomic bitops variants.
>
> The reason I don't like that is that experience shows that most uses of
> such atomic variants in drivers usually are failed attempts at papering
> over broken locking.
>
> If everything is covered by a lock, then using the non-atomic versions
> is more efficient, but so is using bool (optionally with :1 bitfield
> qualifiers to avoid wasting memory), which from a pure C language
> perspective I think is more expressive of what you are doing and more
> readable.
Okay. Probably I need to add one another patch in this series to address
what you pointed out.
I have one question. I reviewed again all bitops in this driver and
checked that some bitops are protected by a spinlock and some others
are not. In this case, can I mix use atomic and non-atomic bitops
depend on each bitop's protection state by the spinlock? Or, would it be
better to change all of them to bool in this case?
Thanks,
Jae
>
> Cheers,
> Ben.
>
^ permalink raw reply
* [PATCH 1/7] media: aspeed: fix a kernel warning on clk control
From: Benjamin Herrenschmidt @ 2019-05-09 23:19 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <bd909078-323e-93a6-143f-0bb0f0d2229c@linux.intel.com>
On Thu, 2019-05-09 at 10:19 -0700, Jae Hyun Yoo wrote:
>
> Okay. Probably I need to add one another patch in this series to address
> what you pointed out.
>
> I have one question. I reviewed again all bitops in this driver and
> checked that some bitops are protected by a spinlock and some others
> are not. In this case, can I mix use atomic and non-atomic bitops
> depend on each bitop's protection state by the spinlock? Or, would it be
> better to change all of them to bool in this case?
No, if some aren't protected by a lock and some are, then they need to
remain atomic.
The question then becomes whether the unprotected ones are actually
correct or just exposing more races.
Cheers,
Ben.
^ permalink raw reply
* [PATCH 1/7] media: aspeed: fix a kernel warning on clk control
From: Jae Hyun Yoo @ 2019-05-09 23:51 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <9b9f9e0d8fdeef0749fa5fcef1647216e9a74f8c.camel@kernel.crashing.org>
On 5/9/2019 4:19 PM, Benjamin Herrenschmidt wrote:
> On Thu, 2019-05-09 at 10:19 -0700, Jae Hyun Yoo wrote:
>>
>> Okay. Probably I need to add one another patch in this series to address
>> what you pointed out.
>>
>> I have one question. I reviewed again all bitops in this driver and
>> checked that some bitops are protected by a spinlock and some others
>> are not. In this case, can I mix use atomic and non-atomic bitops
>> depend on each bitop's protection state by the spinlock? Or, would it be
>> better to change all of them to bool in this case?
>
> No, if some aren't protected by a lock and some are, then they need to
> remain atomic.
>
> The question then becomes whether the unprotected ones are actually
> correct or just exposing more races.
Got it. Not sure yet but I think the protected bitops could be moved out
from the spinlock scope then all bitops could be kept as atomic. I'll
look at and test this driver code more deeply again, and will submit v2
soon.
Again, thanks a lot for your review.
Regards,
Jae
^ permalink raw reply
* [PATCH 1/7] media: aspeed: fix a kernel warning on clk control
From: Benjamin Herrenschmidt @ 2019-05-10 3:01 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <2f21bac3-7095-a535-e964-ae24ae6e021d@linux.intel.com>
On Thu, 2019-05-09 at 16:51 -0700, Jae Hyun Yoo wrote:
> On 5/9/2019 4:19 PM, Benjamin Herrenschmidt wrote:
> > On Thu, 2019-05-09 at 10:19 -0700, Jae Hyun Yoo wrote:
> > >
> > > Okay. Probably I need to add one another patch in this series to
> > > address
> > > what you pointed out.
> > >
> > > I have one question. I reviewed again all bitops in this driver
> > > and
> > > checked that some bitops are protected by a spinlock and some
> > > others
> > > are not. In this case, can I mix use atomic and non-atomic bitops
> > > depend on each bitop's protection state by the spinlock? Or,
> > > would it be
> > > better to change all of them to bool in this case?
> >
> > No, if some aren't protected by a lock and some are, then they need
> > to
> > remain atomic.
> >
> > The question then becomes whether the unprotected ones are actually
> > correct or just exposing more races.
>
> Got it. Not sure yet but I think the protected bitops could be moved
> out
> from the spinlock scope then all bitops could be kept as atomic.
Which is very likely to be extremely racy... (and gratuitously more
costly) :-)
> I'll
> look at and test this driver code more deeply again, and will submit
> v2
> soon.
>
> Again, thanks a lot for your review.
>
> Regards,
> Jae
^ permalink raw reply
* [PATCH 1/7] media: aspeed: fix a kernel warning on clk control
From: Jae Hyun Yoo @ 2019-05-10 4:28 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <1b208c6b78107aeca7b68fb496466e92957b935a.camel@kernel.crashing.org>
On 5/9/2019 8:01 PM, Benjamin Herrenschmidt wrote:
> On Thu, 2019-05-09 at 16:51 -0700, Jae Hyun Yoo wrote:
>> On 5/9/2019 4:19 PM, Benjamin Herrenschmidt wrote:
>>> On Thu, 2019-05-09 at 10:19 -0700, Jae Hyun Yoo wrote:
>>>>
>>>> Okay. Probably I need to add one another patch in this series to
>>>> address
>>>> what you pointed out.
>>>>
>>>> I have one question. I reviewed again all bitops in this driver
>>>> and
>>>> checked that some bitops are protected by a spinlock and some
>>>> others
>>>> are not. In this case, can I mix use atomic and non-atomic bitops
>>>> depend on each bitop's protection state by the spinlock? Or,
>>>> would it be
>>>> better to change all of them to bool in this case?
>>>
>>> No, if some aren't protected by a lock and some are, then they need
>>> to
>>> remain atomic.
>>>
>>> The question then becomes whether the unprotected ones are actually
>>> correct or just exposing more races.
>>
>> Got it. Not sure yet but I think the protected bitops could be moved
>> out
>> from the spinlock scope then all bitops could be kept as atomic.
>
> Which is very likely to be extremely racy... (and gratuitously more
> costly) :-)
Okay then, will try to wrap all bitops using a single spinlock and
change all of them to non-atomic bitops. Is it right approach?
Thanks,
Jae
>> I'll
>> look at and test this driver code more deeply again, and will submit
>> v2
>> soon.
>>
>> Again, thanks a lot for your review.
>>
>> Regards,
>> Jae
>
^ permalink raw reply
* [PATCH 1/6] thermal: Introduce devm_thermal_of_cooling_device_register
From: Eduardo Valentin @ 2019-05-11 19:04 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <1555617500-10862-2-git-send-email-linux@roeck-us.net>
Hello Guenter,
On Thu, Apr 18, 2019 at 12:58:15PM -0700, Guenter Roeck wrote:
> thermal_of_cooling_device_register() and thermal_cooling_device_register()
> are typically called from driver probe functions, and
> thermal_cooling_device_unregister() is called from remove functions. This
> makes both a perfect candidate for device managed functions.
>
> Introduce devm_thermal_of_cooling_device_register(). This function can
> also be used to replace thermal_cooling_device_register() by passing a NULL
> pointer as device node. The new function requires both struct device *
> and struct device_node * as parameters since the struct device_node *
> parameter is not always identical to dev->of_node.
>
> Don't introduce a device managed remove function since it is not needed
> at this point.
I don't have any objection on adding this API. Only a minor thing below:
>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> drivers/thermal/thermal_core.c | 49 ++++++++++++++++++++++++++++++++++++++++++
> include/linux/thermal.h | 5 +++++
> 2 files changed, 54 insertions(+)
>
> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
> index 6590bb5cb688..e0b530603db6 100644
> --- a/drivers/thermal/thermal_core.c
> +++ b/drivers/thermal/thermal_core.c
> @@ -1046,6 +1046,55 @@ thermal_of_cooling_device_register(struct device_node *np,
> }
> EXPORT_SYMBOL_GPL(thermal_of_cooling_device_register);
>
> +static void thermal_cooling_device_release(struct device *dev, void *res)
> +{
> + thermal_cooling_device_unregister(
> + *(struct thermal_cooling_device **)res);
> +}
> +
> +/**
> + * devm_thermal_of_cooling_device_register() - register an OF thermal cooling
> + * device
> + * @dev: a valid struct device pointer of a sensor device.
> + * @np: a pointer to a device tree node.
> + * @type: the thermal cooling device type.
> + * @devdata: device private data.
> + * @ops: standard thermal cooling devices callbacks.
> + *
> + * This function will register a cooling device with device tree node reference.
> + * This interface function adds a new thermal cooling device (fan/processor/...)
> + * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
> + * to all the thermal zone devices registered at the same time.
> + *
> + * Return: a pointer to the created struct thermal_cooling_device or an
> + * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
> + */
> +struct thermal_cooling_device *
> +devm_thermal_of_cooling_device_register(struct device *dev,
> + struct device_node *np,
> + char *type, void *devdata,
> + const struct thermal_cooling_device_ops *ops)
> +{
> + struct thermal_cooling_device **ptr, *tcd;
> +
> + ptr = devres_alloc(thermal_cooling_device_release, sizeof(*ptr),
> + GFP_KERNEL);
> + if (!ptr)
> + return ERR_PTR(-ENOMEM);
> +
> + tcd = __thermal_cooling_device_register(np, type, devdata, ops);
> + if (IS_ERR(tcd)) {
> + devres_free(ptr);
> + return tcd;
> + }
> +
> + *ptr = tcd;
> + devres_add(dev, ptr);
> +
> + return tcd;
> +}
> +EXPORT_SYMBOL_GPL(devm_thermal_of_cooling_device_register);
> +
> static void __unbind(struct thermal_zone_device *tz, int mask,
> struct thermal_cooling_device *cdev)
> {
> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index 5f4705f46c2f..43cf4fdd71d4 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -447,6 +447,11 @@ struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
> struct thermal_cooling_device *
> thermal_of_cooling_device_register(struct device_node *np, char *, void *,
> const struct thermal_cooling_device_ops *);
> +struct thermal_cooling_device *
> +devm_thermal_of_cooling_device_register(struct device *dev,
> + struct device_node *np,
> + char *type, void *devdata,
> + const struct thermal_cooling_device_ops *ops);
We need to stub this in case thermal is not selected.
> void thermal_cooling_device_unregister(struct thermal_cooling_device *);
> struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
> int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
Something like:
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 43cf4fd..9b1b365 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -508,6 +508,14 @@ static inline struct thermal_cooling_device *
thermal_of_cooling_device_register(struct device_node *np,
char *type, void *devdata, const struct thermal_cooling_device_ops *ops)
{ return ERR_PTR(-ENODEV); }
+struct thermal_cooling_device *
+devm_thermal_of_cooling_device_register(struct device *dev,
+ struct device_node *np,
+ char *type, void *devdata,
+ const struct thermal_cooling_device_ops *ops)
+{
+ return ERR_PTR(-ENODEV);
+}
static inline void thermal_cooling_device_unregister(
struct thermal_cooling_device *cdev)
{ }
~
If you want I can amend this to your patch and apply it.
Also, do you prefer me to collect only this patch and you would collect hwmon changes,
or are you ok if I collect all the series?
^ permalink raw reply related
* [PATCH 1/6] thermal: Introduce devm_thermal_of_cooling_device_register
From: Guenter Roeck @ 2019-05-11 20:22 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <20190511190415.GA22816@localhost.localdomain>
Hi Eduardo,
On 5/11/19 12:04 PM, Eduardo Valentin wrote:
> Hello Guenter,
>
> On Thu, Apr 18, 2019 at 12:58:15PM -0700, Guenter Roeck wrote:
>> thermal_of_cooling_device_register() and thermal_cooling_device_register()
>> are typically called from driver probe functions, and
>> thermal_cooling_device_unregister() is called from remove functions. This
>> makes both a perfect candidate for device managed functions.
>>
>> Introduce devm_thermal_of_cooling_device_register(). This function can
>> also be used to replace thermal_cooling_device_register() by passing a NULL
>> pointer as device node. The new function requires both struct device *
>> and struct device_node * as parameters since the struct device_node *
>> parameter is not always identical to dev->of_node.
>>
>> Don't introduce a device managed remove function since it is not needed
>> at this point.
>
> I don't have any objection on adding this API. Only a minor thing below:
>
>
>>
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>> drivers/thermal/thermal_core.c | 49 ++++++++++++++++++++++++++++++++++++++++++
>> include/linux/thermal.h | 5 +++++
>> 2 files changed, 54 insertions(+)
>>
>> diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
>> index 6590bb5cb688..e0b530603db6 100644
>> --- a/drivers/thermal/thermal_core.c
>> +++ b/drivers/thermal/thermal_core.c
>> @@ -1046,6 +1046,55 @@ thermal_of_cooling_device_register(struct device_node *np,
>> }
>> EXPORT_SYMBOL_GPL(thermal_of_cooling_device_register);
>>
>> +static void thermal_cooling_device_release(struct device *dev, void *res)
>> +{
>> + thermal_cooling_device_unregister(
>> + *(struct thermal_cooling_device **)res);
>> +}
>> +
>> +/**
>> + * devm_thermal_of_cooling_device_register() - register an OF thermal cooling
>> + * device
>> + * @dev: a valid struct device pointer of a sensor device.
>> + * @np: a pointer to a device tree node.
>> + * @type: the thermal cooling device type.
>> + * @devdata: device private data.
>> + * @ops: standard thermal cooling devices callbacks.
>> + *
>> + * This function will register a cooling device with device tree node reference.
>> + * This interface function adds a new thermal cooling device (fan/processor/...)
>> + * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
>> + * to all the thermal zone devices registered at the same time.
>> + *
>> + * Return: a pointer to the created struct thermal_cooling_device or an
>> + * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
>> + */
>> +struct thermal_cooling_device *
>> +devm_thermal_of_cooling_device_register(struct device *dev,
>> + struct device_node *np,
>> + char *type, void *devdata,
>> + const struct thermal_cooling_device_ops *ops)
>> +{
>> + struct thermal_cooling_device **ptr, *tcd;
>> +
>> + ptr = devres_alloc(thermal_cooling_device_release, sizeof(*ptr),
>> + GFP_KERNEL);
>> + if (!ptr)
>> + return ERR_PTR(-ENOMEM);
>> +
>> + tcd = __thermal_cooling_device_register(np, type, devdata, ops);
>> + if (IS_ERR(tcd)) {
>> + devres_free(ptr);
>> + return tcd;
>> + }
>> +
>> + *ptr = tcd;
>> + devres_add(dev, ptr);
>> +
>> + return tcd;
>> +}
>> +EXPORT_SYMBOL_GPL(devm_thermal_of_cooling_device_register);
>> +
>> static void __unbind(struct thermal_zone_device *tz, int mask,
>> struct thermal_cooling_device *cdev)
>> {
>> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
>> index 5f4705f46c2f..43cf4fdd71d4 100644
>> --- a/include/linux/thermal.h
>> +++ b/include/linux/thermal.h
>> @@ -447,6 +447,11 @@ struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
>> struct thermal_cooling_device *
>> thermal_of_cooling_device_register(struct device_node *np, char *, void *,
>> const struct thermal_cooling_device_ops *);
>> +struct thermal_cooling_device *
>> +devm_thermal_of_cooling_device_register(struct device *dev,
>> + struct device_node *np,
>> + char *type, void *devdata,
>> + const struct thermal_cooling_device_ops *ops);
>
> We need to stub this in case thermal is not selected.
>
Yes. Sorry, that completely slipped my mind.
>> void thermal_cooling_device_unregister(struct thermal_cooling_device *);
>> struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
>> int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
>
> Something like:
>
>
> diff --git a/include/linux/thermal.h b/include/linux/thermal.h
> index 43cf4fd..9b1b365 100644
> --- a/include/linux/thermal.h
> +++ b/include/linux/thermal.h
> @@ -508,6 +508,14 @@ static inline struct thermal_cooling_device *
> thermal_of_cooling_device_register(struct device_node *np,
> char *type, void *devdata, const struct thermal_cooling_device_ops *ops)
> { return ERR_PTR(-ENODEV); }
> +struct thermal_cooling_device *
> +devm_thermal_of_cooling_device_register(struct device *dev,
> + struct device_node *np,
> + char *type, void *devdata,
> + const struct thermal_cooling_device_ops *ops)
> +{
> + return ERR_PTR(-ENODEV);
> +}
> static inline void thermal_cooling_device_unregister(
> struct thermal_cooling_device *cdev)
> { }
> ~
>
>
> If you want I can amend this to your patch and apply it.
>
Please do.
> Also, do you prefer me to collect only this patch and you would collect hwmon changes,
> or are you ok if I collect all the series?
>
Please go ahead and collect the entire series.
Thanks,
Guenter
^ permalink raw reply
* [PATCH 6/6] hwmon: (pwm-fan) Use devm_thermal_of_cooling_device_register
From: Marek Szyprowski @ 2019-05-20 15:21 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <1555617500-10862-7-git-send-email-linux@roeck-us.net>
Dear All,
On 2019-04-18 21:58, Guenter Roeck wrote:
> Use devm_thermal_of_cooling_device_register() to register the cooling
> device. Also use devm_add_action_or_reset() to stop the fan on device
> removal, and to disable the pwm. Introduce a local 'dev' variable in
> the probe function to make the code easier to read.
>
> As a side effect, this fixes a bug seen if pwm_fan_of_get_cooling_data()
> returned an error. In that situation, the pwm was not disabled, and
> the fan was not stopped. Using devm functions also ensures that the
> pwm is disabled and that the fan is stopped only after the hwmon device
> has been unregistered.
>
> Cc: Lukasz Majewski <l.majewski@samsung.com>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
I've noticed the following lockdep warning after this commit during CPU
hotplug tests on TM2e board (ARM64 Exynos5433). It looks like a false
positive, but it would be nice to annotate it somehow in the code to
make lockdep happy:
--->8---
IRQ 8: no longer affine to CPU5
CPU5: shutdown
IRQ 9: no longer affine to CPU6
CPU6: shutdown
======================================================
WARNING: possible circular locking dependency detected
5.2.0-rc1+ #6093 Not tainted
------------------------------------------------------
cpuhp/7/43 is trying to acquire lock:
00000000d1a60be3 (thermal_list_lock){+.+.}, at:
thermal_cooling_device_unregister+0x34/0x1c0
but task is already holding lock:
00000000a6a56c92 (&policy->rwsem){++++}, at: cpufreq_offline+0x68/0x228
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #3 (&policy->rwsem){++++}:
?????? down_write+0x48/0x98
?????? cpufreq_cpu_acquire+0x20/0x58
?????? cpufreq_update_policy+0x28/0xc0
?????? cpufreq_set_cur_state+0x44/0x70
?????? thermal_cdev_update+0x7c/0x240
?????? step_wise_throttle+0x4c/0x88
?????? handle_thermal_trip+0xc0/0x348
?????? thermal_zone_device_update.part.7+0x6c/0x250
?????? thermal_zone_device_update+0x28/0x38
?????? exynos_tmu_work+0x28/0x70
?????? process_one_work+0x298/0x6c0
?????? worker_thread+0x48/0x430
?????? kthread+0x100/0x130
?????? ret_from_fork+0x10/0x18
-> #2 (&cdev->lock){+.+.}:
?????? __mutex_lock+0x90/0x890
?????? mutex_lock_nested+0x1c/0x28
?????? thermal_zone_bind_cooling_device+0x2cc/0x3e0
?????? of_thermal_bind+0x9c/0xf8
?????? __thermal_cooling_device_register+0x1a4/0x388
?????? thermal_of_cooling_device_register+0xc/0x18
?????? __cpufreq_cooling_register+0x360/0x410
?????? of_cpufreq_cooling_register+0x84/0xf8
?????? cpufreq_online+0x414/0x720
?????? cpufreq_add_dev+0x78/0x88
?????? subsys_interface_register+0xa4/0xf8
?????? cpufreq_register_driver+0x140/0x1e0
?????? dt_cpufreq_probe+0xb0/0x130
?????? platform_drv_probe+0x50/0xa8
?????? really_probe+0x1b0/0x2a0
?????? driver_probe_device+0x58/0x100
?????? __device_attach_driver+0x90/0xc0
?????? bus_for_each_drv+0x70/0xc8
?????? __device_attach+0xdc/0x140
?????? device_initial_probe+0x10/0x18
?????? bus_probe_device+0x94/0xa0
?????? device_add+0x39c/0x5c8
?????? platform_device_add+0x110/0x248
?????? platform_device_register_full+0x134/0x178
?????? cpufreq_dt_platdev_init+0x114/0x14c
?????? do_one_initcall+0x84/0x430
?????? kernel_init_freeable+0x440/0x534
?????? kernel_init+0x10/0x108
?????? ret_from_fork+0x10/0x18
-> #1 (&tz->lock){+.+.}:
?????? __mutex_lock+0x90/0x890
?????? mutex_lock_nested+0x1c/0x28
?????? thermal_zone_bind_cooling_device+0x2b8/0x3e0
?????? of_thermal_bind+0x9c/0xf8
?????? __thermal_cooling_device_register+0x1a4/0x388
?????? thermal_of_cooling_device_register+0xc/0x18
?????? __cpufreq_cooling_register+0x360/0x410
?????? of_cpufreq_cooling_register+0x84/0xf8
?????? cpufreq_online+0x414/0x720
?????? cpufreq_add_dev+0x78/0x88
?????? subsys_interface_register+0xa4/0xf8
?????? cpufreq_register_driver+0x140/0x1e0
?????? dt_cpufreq_probe+0xb0/0x130
?????? platform_drv_probe+0x50/0xa8
?????? really_probe+0x1b0/0x2a0
?????? driver_probe_device+0x58/0x100
?????? __device_attach_driver+0x90/0xc0
?????? bus_for_each_drv+0x70/0xc8
?????? __device_attach+0xdc/0x140
?????? device_initial_probe+0x10/0x18
?????? bus_probe_device+0x94/0xa0
?????? device_add+0x39c/0x5c8
?????? platform_device_add+0x110/0x248
?????? platform_device_register_full+0x134/0x178
?????? cpufreq_dt_platdev_init+0x114/0x14c
?????? do_one_initcall+0x84/0x430
?????? kernel_init_freeable+0x440/0x534
?????? kernel_init+0x10/0x108
?????? ret_from_fork+0x10/0x18
-> #0 (thermal_list_lock){+.+.}:
?????? lock_acquire+0xdc/0x260
?????? __mutex_lock+0x90/0x890
?????? mutex_lock_nested+0x1c/0x28
?????? thermal_cooling_device_unregister+0x34/0x1c0
?????? cpufreq_cooling_unregister+0x78/0xd0
?????? cpufreq_offline+0x200/0x228
?????? cpuhp_cpufreq_offline+0xc/0x18
?????? cpuhp_invoke_callback+0xd0/0xcb0
?????? cpuhp_thread_fun+0x1e8/0x258
?????? smpboot_thread_fn+0x1b4/0x2d0
?????? kthread+0x100/0x130
?????? ret_from_fork+0x10/0x18
other info that might help us debug this:
Chain exists of:
? thermal_list_lock --> &cdev->lock --> &policy->rwsem
?Possible unsafe locking scenario:
?????? CPU0??????????????????? CPU1
?????? ----??????????????????? ----
? lock(&policy->rwsem);
?????????????????????????????? lock(&cdev->lock);
?????????????????????????????? lock(&policy->rwsem);
? lock(thermal_list_lock);
?*** DEADLOCK ***
3 locks held by cpuhp/7/43:
?#0: 00000000ae30cc2b (cpu_hotplug_lock.rw_sem){++++}, at:
cpuhp_thread_fun+0x34/0x258
?#1: 00000000a0e2460a (cpuhp_state-down){+.+.}, at:
cpuhp_thread_fun+0x178/0x258
?#2: 00000000a6a56c92 (&policy->rwsem){++++}, at:
cpufreq_offline+0x68/0x228
stack backtrace:
CPU: 7 PID: 43 Comm: cpuhp/7 Not tainted 5.2.0-rc1+ #6093
Hardware name: Samsung TM2E board (DT)
Call trace:
?dump_backtrace+0x0/0x158
?show_stack+0x14/0x20
?dump_stack+0xc8/0x114
?print_circular_bug+0x1cc/0x2d8
?__lock_acquire+0x18f4/0x20f8
?lock_acquire+0xdc/0x260
?__mutex_lock+0x90/0x890
?mutex_lock_nested+0x1c/0x28
?thermal_cooling_device_unregister+0x34/0x1c0
?cpufreq_cooling_unregister+0x78/0xd0
?cpufreq_offline+0x200/0x228
?cpuhp_cpufreq_offline+0xc/0x18
?cpuhp_invoke_callback+0xd0/0xcb0
?cpuhp_thread_fun+0x1e8/0x258
?smpboot_thread_fn+0x1b4/0x2d0
?kthread+0x100/0x130
?ret_from_fork+0x10/0x18
IRQ 10: no longer affine to CPU7
--->8---
> ---
> drivers/hwmon/pwm-fan.c | 73 ++++++++++++++++++++-----------------------------
> 1 file changed, 29 insertions(+), 44 deletions(-)
>
> diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
> index 167221c7628a..0243ba70107e 100644
> --- a/drivers/hwmon/pwm-fan.c
> +++ b/drivers/hwmon/pwm-fan.c
> @@ -207,33 +207,44 @@ static int pwm_fan_of_get_cooling_data(struct device *dev,
> return 0;
> }
>
> +static void pwm_fan_regulator_disable(void *data)
> +{
> + regulator_disable(data);
> +}
> +
> +static void pwm_fan_pwm_disable(void *data)
> +{
> + pwm_disable(data);
> +}
> +
> static int pwm_fan_probe(struct platform_device *pdev)
> {
> struct thermal_cooling_device *cdev;
> + struct device *dev = &pdev->dev;
> struct pwm_fan_ctx *ctx;
> struct device *hwmon;
> int ret;
> struct pwm_state state = { };
>
> - ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
> + ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
> if (!ctx)
> return -ENOMEM;
>
> mutex_init(&ctx->lock);
>
> - ctx->pwm = devm_of_pwm_get(&pdev->dev, pdev->dev.of_node, NULL);
> + ctx->pwm = devm_of_pwm_get(dev, dev->of_node, NULL);
> if (IS_ERR(ctx->pwm)) {
> ret = PTR_ERR(ctx->pwm);
>
> if (ret != -EPROBE_DEFER)
> - dev_err(&pdev->dev, "Could not get PWM: %d\n", ret);
> + dev_err(dev, "Could not get PWM: %d\n", ret);
>
> return ret;
> }
>
> platform_set_drvdata(pdev, ctx);
>
> - ctx->reg_en = devm_regulator_get_optional(&pdev->dev, "fan");
> + ctx->reg_en = devm_regulator_get_optional(dev, "fan");
> if (IS_ERR(ctx->reg_en)) {
> if (PTR_ERR(ctx->reg_en) != -ENODEV)
> return PTR_ERR(ctx->reg_en);
> @@ -242,10 +253,11 @@ static int pwm_fan_probe(struct platform_device *pdev)
> } else {
> ret = regulator_enable(ctx->reg_en);
> if (ret) {
> - dev_err(&pdev->dev,
> - "Failed to enable fan supply: %d\n", ret);
> + dev_err(dev, "Failed to enable fan supply: %d\n", ret);
> return ret;
> }
> + devm_add_action_or_reset(dev, pwm_fan_regulator_disable,
> + ctx->reg_en);
> }
>
> ctx->pwm_value = MAX_PWM;
> @@ -257,62 +269,36 @@ static int pwm_fan_probe(struct platform_device *pdev)
>
> ret = pwm_apply_state(ctx->pwm, &state);
> if (ret) {
> - dev_err(&pdev->dev, "Failed to configure PWM\n");
> - goto err_reg_disable;
> + dev_err(dev, "Failed to configure PWM\n");
> + return ret;
> }
> + devm_add_action_or_reset(dev, pwm_fan_pwm_disable, ctx->pwm);
>
> - hwmon = devm_hwmon_device_register_with_groups(&pdev->dev, "pwmfan",
> + hwmon = devm_hwmon_device_register_with_groups(dev, "pwmfan",
> ctx, pwm_fan_groups);
> if (IS_ERR(hwmon)) {
> - dev_err(&pdev->dev, "Failed to register hwmon device\n");
> - ret = PTR_ERR(hwmon);
> - goto err_pwm_disable;
> + dev_err(dev, "Failed to register hwmon device\n");
> + return PTR_ERR(hwmon);
> }
>
> - ret = pwm_fan_of_get_cooling_data(&pdev->dev, ctx);
> + ret = pwm_fan_of_get_cooling_data(dev, ctx);
> if (ret)
> return ret;
>
> ctx->pwm_fan_state = ctx->pwm_fan_max_state;
> if (IS_ENABLED(CONFIG_THERMAL)) {
> - cdev = thermal_of_cooling_device_register(pdev->dev.of_node,
> - "pwm-fan", ctx,
> - &pwm_fan_cooling_ops);
> + cdev = devm_thermal_of_cooling_device_register(dev,
> + dev->of_node, "pwm-fan", ctx, &pwm_fan_cooling_ops);
> if (IS_ERR(cdev)) {
> - dev_err(&pdev->dev,
> + dev_err(dev,
> "Failed to register pwm-fan as cooling device");
> - ret = PTR_ERR(cdev);
> - goto err_pwm_disable;
> + return PTR_ERR(cdev);
> }
> ctx->cdev = cdev;
> thermal_cdev_update(cdev);
> }
>
> return 0;
> -
> -err_pwm_disable:
> - state.enabled = false;
> - pwm_apply_state(ctx->pwm, &state);
> -
> -err_reg_disable:
> - if (ctx->reg_en)
> - regulator_disable(ctx->reg_en);
> -
> - return ret;
> -}
> -
> -static int pwm_fan_remove(struct platform_device *pdev)
> -{
> - struct pwm_fan_ctx *ctx = platform_get_drvdata(pdev);
> -
> - thermal_cooling_device_unregister(ctx->cdev);
> - if (ctx->pwm_value)
> - pwm_disable(ctx->pwm);
> -
> - if (ctx->reg_en)
> - regulator_disable(ctx->reg_en);
> -
> - return 0;
> }
>
> #ifdef CONFIG_PM_SLEEP
> @@ -380,7 +366,6 @@ MODULE_DEVICE_TABLE(of, of_pwm_fan_match);
>
> static struct platform_driver pwm_fan_driver = {
> .probe = pwm_fan_probe,
> - .remove = pwm_fan_remove,
> .driver = {
> .name = "pwm-fan",
> .pm = &pwm_fan_pm,
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
^ permalink raw reply
* [PATCH dev-5.1] ARM: dts: aspeed: swift: Add pca9539 devices
From: Adriana Kobylak @ 2019-05-20 20:17 UTC (permalink / raw)
To: linux-aspeed
From: Adriana Kobylak <anoo@us.ibm.com>
Add the pca9539 devices to the Swift device tree.
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
---
arch/arm/boot/dts/aspeed-bmc-opp-swift.dts | 146 +++++++++++++++++++++++++++++
1 file changed, 146 insertions(+)
diff --git a/arch/arm/boot/dts/aspeed-bmc-opp-swift.dts b/arch/arm/boot/dts/aspeed-bmc-opp-swift.dts
index 9610637..270c923 100644
--- a/arch/arm/boot/dts/aspeed-bmc-opp-swift.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-opp-swift.dts
@@ -732,6 +732,79 @@
compatible = "infineon,ir35221";
reg = <0x72>;
};
+
+ pca2: pca9539 at 74 {
+ compatible = "nxp,pca9539";
+ reg = <0x74>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+ gpio-controller;
+ #gpio-cells = <2>;
+
+ gpio at 0 {
+ reg = <0>;
+ };
+
+ gpio at 1 {
+ reg = <1>;
+ };
+
+ gpio at 2 {
+ reg = <2>;
+ };
+
+ gpio at 3 {
+ reg = <3>;
+ };
+
+ gpio at 4 {
+ reg = <4>;
+ };
+
+ gpio at 5 {
+ reg = <5>;
+ };
+
+ gpio at 6 {
+ reg = <6>;
+ };
+
+ gpio at 7 {
+ reg = <7>;
+ };
+
+ gpio at 8 {
+ reg = <8>;
+ };
+
+ gpio at 9 {
+ reg = <9>;
+ };
+
+ gpio at 10 {
+ reg = <10>;
+ };
+
+ gpio at 11 {
+ reg = <11>;
+ };
+
+ gpio at 12 {
+ reg = <12>;
+ };
+
+ gpio at 13 {
+ reg = <13>;
+ };
+
+ gpio at 14 {
+ reg = <14>;
+ };
+
+ gpio at 15 {
+ reg = <15>;
+ };
+ };
};
&i2c10 {
@@ -756,6 +829,79 @@
compatible = "infineon,ir35221";
reg = <0x72>;
};
+
+ pca3: pca9539 at 74 {
+ compatible = "nxp,pca9539";
+ reg = <0x74>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+ gpio-controller;
+ #gpio-cells = <2>;
+
+ gpio at 0 {
+ reg = <0>;
+ };
+
+ gpio at 1 {
+ reg = <1>;
+ };
+
+ gpio at 2 {
+ reg = <2>;
+ };
+
+ gpio at 3 {
+ reg = <3>;
+ };
+
+ gpio at 4 {
+ reg = <4>;
+ };
+
+ gpio at 5 {
+ reg = <5>;
+ };
+
+ gpio at 6 {
+ reg = <6>;
+ };
+
+ gpio at 7 {
+ reg = <7>;
+ };
+
+ gpio at 8 {
+ reg = <8>;
+ };
+
+ gpio at 9 {
+ reg = <9>;
+ };
+
+ gpio at 10 {
+ reg = <10>;
+ };
+
+ gpio at 11 {
+ reg = <11>;
+ };
+
+ gpio at 12 {
+ reg = <12>;
+ };
+
+ gpio at 13 {
+ reg = <13>;
+ };
+
+ gpio at 14 {
+ reg = <14>;
+ };
+
+ gpio at 15 {
+ reg = <15>;
+ };
+ };
};
&i2c11 {
--
1.8.3.1
^ permalink raw reply related
* [PATCH v2 0/7] drivers/soc: Add Aspeed XDMA Engine Driver
From: Eddie James @ 2019-05-20 20:19 UTC (permalink / raw)
To: linux-aspeed
The XDMA engine embedded in the AST2500 SOC performs PCI DMA operations
between the SOC (acting as a BMC) and a host processor in a server.
This series adds a driver to control the XDMA engine in order to easily
perform DMA operations to and from the host processor.
I previously sent this series v1 to drivers/misc, but I'm now fairly certain
it belongs in drivers/soc, especially since the other Aspeed drivers have been
moved to soc.
Changes since v1:
- Correct the XDMA command pitch
- Don't use packed for the aspeed_xdma_op structure
- Correct the SCU PCI config change
Eddie James (7):
dt-bindings: soc: Add Aspeed XDMA engine binding documentation
drivers/soc: Add Aspeed XDMA Engine Driver
drivers/soc: xdma: Add user interface
drivers/soc: xdma: Add PCI device configuration sysfs
drivers/soc: xdma: Add debugfs entries
ARM: dts: aspeed: Add XDMA Engine
ARM: dts: aspeed: witherspoon: Enable XDMA Engine
.../devicetree/bindings/soc/aspeed/xdma.txt | 23 +
MAINTAINERS | 9 +
arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 4 +
arch/arm/boot/dts/aspeed-g5.dtsi | 8 +
drivers/soc/aspeed/Kconfig | 8 +
drivers/soc/aspeed/Makefile | 1 +
drivers/soc/aspeed/aspeed-xdma.c | 944 +++++++++++++++++++++
include/uapi/linux/aspeed-xdma.h | 26 +
8 files changed, 1023 insertions(+)
create mode 100644 Documentation/devicetree/bindings/soc/aspeed/xdma.txt
create mode 100644 drivers/soc/aspeed/aspeed-xdma.c
create mode 100644 include/uapi/linux/aspeed-xdma.h
--
1.8.3.1
^ permalink raw reply
* [PATCH v2 1/7] dt-bindings: soc: Add Aspeed XDMA engine binding documentation
From: Eddie James @ 2019-05-20 20:19 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <1558383565-11821-1-git-send-email-eajames@linux.ibm.com>
Document the bindings.
Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
.../devicetree/bindings/soc/aspeed/xdma.txt | 23 ++++++++++++++++++++++
1 file changed, 23 insertions(+)
create mode 100644 Documentation/devicetree/bindings/soc/aspeed/xdma.txt
diff --git a/Documentation/devicetree/bindings/soc/aspeed/xdma.txt b/Documentation/devicetree/bindings/soc/aspeed/xdma.txt
new file mode 100644
index 0000000..85e82ea
--- /dev/null
+++ b/Documentation/devicetree/bindings/soc/aspeed/xdma.txt
@@ -0,0 +1,23 @@
+* Device tree bindings for the Aspeed XDMA Engine
+
+The XDMA Engine embedded in the AST2500 SOC can perform automatic DMA
+operations over PCI between the AST2500 (acting as a BMC) and a host processor.
+
+Required properties:
+
+ - compatible "aspeed,ast2500-xdma"
+ - reg contains the offset and length of the memory region
+ assigned to the XDMA registers
+ - resets reset specifier for the syscon reset associated with
+ the XDMA engine
+ - interrupts the interrupt associated with the XDMA engine on this
+ platform
+
+Example:
+
+ xdma at 1e6e7000 {
+ compatible = "aspeed,ast2500-xdma";
+ reg = <0x1e6e7000 0x100>;
+ resets = <&syscon ASPEED_RESET_XDMA>;
+ interrupts = <6>;
+ };
--
1.8.3.1
^ permalink raw reply related
* [PATCH v2 2/7] drivers/soc: Add Aspeed XDMA Engine Driver
From: Eddie James @ 2019-05-20 20:19 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <1558383565-11821-1-git-send-email-eajames@linux.ibm.com>
The XDMA engine embedded in the AST2500 SOC performs PCI DMA operations
between the SOC (acting as a BMC) and a host processor in a server.
This commit adds a driver to control the XDMA engine and adds functions
to initialize the hardware and memory and start DMA operations.
Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
MAINTAINERS | 9 +
drivers/soc/aspeed/Kconfig | 8 +
drivers/soc/aspeed/Makefile | 1 +
drivers/soc/aspeed/aspeed-xdma.c | 483 +++++++++++++++++++++++++++++++++++++++
include/uapi/linux/aspeed-xdma.h | 26 +++
5 files changed, 527 insertions(+)
create mode 100644 drivers/soc/aspeed/aspeed-xdma.c
create mode 100644 include/uapi/linux/aspeed-xdma.h
diff --git a/MAINTAINERS b/MAINTAINERS
index a2cd369..bfa6df2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2583,6 +2583,15 @@ S: Maintained
F: drivers/media/platform/aspeed-video.c
F: Documentation/devicetree/bindings/media/aspeed-video.txt
+ASPEED XDMA ENGINE DRIVER
+M: Eddie James <eajames@linux.ibm.com>
+L: linux-aspeed at lists.ozlabs.org (moderated for non-subscribers)
+L: linux-kernel at vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/misc/aspeed,xdma.txt
+F: drivers/soc/aspeed/aspeed-xdma.c
+F: include/uapi/linux/aspeed-xdma.h
+
ASUS NOTEBOOKS AND EEEPC ACPI/WMI EXTRAS DRIVERS
M: Corentin Chary <corentin.chary@gmail.com>
L: acpi4asus-user at lists.sourceforge.net
diff --git a/drivers/soc/aspeed/Kconfig b/drivers/soc/aspeed/Kconfig
index 765d101..5a379e8 100644
--- a/drivers/soc/aspeed/Kconfig
+++ b/drivers/soc/aspeed/Kconfig
@@ -28,4 +28,12 @@ config ASPEED_P2A_CTRL
ioctl()s, the driver also provides an interface for userspace mappings to
a pre-defined region.
+config ASPEED_XDMA
+ tristate "Aspeed XDMA Engine Driver"
+ depends on SOC_ASPEED && REGMAP && MFD_SYSCON && HAS_DMA
+ help
+ Enable support for the Aspeed XDMA Engine found on the Aspeed AST2500
+ SOC. The XDMA engine can perform automatic PCI DMA operations between
+ the AST2500 (acting as a BMC) and a host processor.
+
endmenu
diff --git a/drivers/soc/aspeed/Makefile b/drivers/soc/aspeed/Makefile
index 2f7b6da..bae65af 100644
--- a/drivers/soc/aspeed/Makefile
+++ b/drivers/soc/aspeed/Makefile
@@ -1,3 +1,4 @@
obj-$(CONFIG_ASPEED_LPC_CTRL) += aspeed-lpc-ctrl.o
obj-$(CONFIG_ASPEED_LPC_SNOOP) += aspeed-lpc-snoop.o
obj-$(CONFIG_ASPEED_P2A_CTRL) += aspeed-p2a-ctrl.o
+obj-$(CONFIG_ASPEED_XDMA) += aspeed-xdma.o
diff --git a/drivers/soc/aspeed/aspeed-xdma.c b/drivers/soc/aspeed/aspeed-xdma.c
new file mode 100644
index 0000000..0992d2a
--- /dev/null
+++ b/drivers/soc/aspeed/aspeed-xdma.c
@@ -0,0 +1,483 @@
+// SPDX-License-Identifier: GPL-2.0+
+// Copyright IBM Corp 2019
+
+#include <linux/aspeed-xdma.h>
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/debugfs.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
+#include <linux/fs.h>
+#include <linux/interrupt.h>
+#include <linux/jiffies.h>
+#include <linux/list.h>
+#include <linux/mfd/syscon.h>
+#include <linux/miscdevice.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_irq.h>
+#include <linux/of_reserved_mem.h>
+#include <linux/platform_device.h>
+#include <linux/poll.h>
+#include <linux/regmap.h>
+#include <linux/reset.h>
+#include <linux/string.h>
+#include <linux/uaccess.h>
+#include <linux/wait.h>
+
+#define DEVICE_NAME "aspeed-xdma"
+
+#define SCU_STRAP 0x070
+#define SCU_STRAP_VGA_MEM GENMASK(3, 2)
+
+#define SCU_PCIE_CONF 0x180
+#define SCU_PCIE_CONF_VGA_EN BIT(0)
+#define SCU_PCIE_CONF_VGA_EN_MMIO BIT(1)
+#define SCU_PCIE_CONF_VGA_EN_LPC BIT(2)
+#define SCU_PCIE_CONF_VGA_EN_MSI BIT(3)
+#define SCU_PCIE_CONF_VGA_EN_MCTP BIT(4)
+#define SCU_PCIE_CONF_VGA_EN_IRQ BIT(5)
+#define SCU_PCIE_CONF_VGA_EN_DMA BIT(6)
+#define SCU_PCIE_CONF_BMC_EN BIT(8)
+#define SCU_PCIE_CONF_BMC_EN_MMIO BIT(9)
+#define SCU_PCIE_CONF_BMC_EN_MSI BIT(11)
+#define SCU_PCIE_CONF_BMC_EN_MCTP BIT(12)
+#define SCU_PCIE_CONF_BMC_EN_IRQ BIT(13)
+#define SCU_PCIE_CONF_BMC_EN_DMA BIT(14)
+#define SCU_PCIE_CONF_RSVD GENMASK(19, 18)
+
+#define SDMC_CONF 0x004
+#define SDMC_CONF_MEM GENMASK(1, 0)
+#define SDMC_REMAP 0x008
+#define SDMC_REMAP_MAGIC GENMASK(17, 16)
+
+#define XDMA_CMD_SIZE 4
+#define XDMA_CMDQ_SIZE PAGE_SIZE
+#define XDMA_BYTE_ALIGN 16
+#define XDMA_MAX_LINE_SIZE BIT(10)
+#define XDMA_NUM_CMDS \
+ (XDMA_CMDQ_SIZE / sizeof(struct aspeed_xdma_cmd))
+#define XDMA_NUM_DEBUGFS_REGS 6
+
+#define XDMA_CMD_BMC_CHECK BIT(0)
+#define XDMA_CMD_BMC_ADDR GENMASK(29, 4)
+#define XDMA_CMD_BMC_DIR_US BIT(31)
+
+#define XDMA_CMD_COMM1_HI_HOST_PITCH GENMASK(14, 3)
+#define XDMA_CMD_COMM1_HI_BMC_PITCH GENMASK(30, 19)
+
+#define XDMA_CMD_CONF_CHECK BIT(1)
+#define XDMA_CMD_CONF_LINE_SIZE GENMASK(14, 4)
+#define XDMA_CMD_CONF_IRQ_BMC BIT(15)
+#define XDMA_CMD_CONF_NUM_LINES GENMASK(27, 16)
+#define XDMA_CMD_CONF_IRQ BIT(31)
+
+#define XDMA_CMD_ID_UPDIR GENMASK(17, 16)
+#define XDMA_CMD_ID_UPDIR_BMC 0
+#define XDMA_CMD_ID_UPDIR_HOST 1
+#define XDMA_CMD_ID_UPDIR_VGA 2
+
+#define XDMA_DS_PCIE_REQ_SIZE_128 0
+#define XDMA_DS_PCIE_REQ_SIZE_256 1
+#define XDMA_DS_PCIE_REQ_SIZE_512 2
+#define XDMA_DS_PCIE_REQ_SIZE_1K 3
+#define XDMA_DS_PCIE_REQ_SIZE_2K 4
+#define XDMA_DS_PCIE_REQ_SIZE_4K 5
+
+#define XDMA_BMC_CMD_QUEUE_ADDR 0x10
+#define XDMA_BMC_CMD_QUEUE_ENDP 0x14
+#define XDMA_BMC_CMD_QUEUE_WRITEP 0x18
+#define XDMA_BMC_CMD_QUEUE_READP 0x1c
+#define XDMA_BMC_CMD_QUEUE_READP_MAGIC 0xee882266
+#define XDMA_CTRL 0x20
+#define XDMA_CTRL_US_COMP BIT(4)
+#define XDMA_CTRL_DS_COMP BIT(5)
+#define XDMA_CTRL_DS_DIRTY BIT(6)
+#define XDMA_CTRL_DS_PCIE_REQ_SIZE GENMASK(19, 17)
+#define XDMA_CTRL_DS_DATA_TIMEOUT BIT(28)
+#define XDMA_CTRL_DS_CHECK_ID BIT(29)
+#define XDMA_STATUS 0x24
+#define XDMA_STATUS_US_COMP BIT(4)
+#define XDMA_STATUS_DS_COMP BIT(5)
+
+enum {
+ XDMA_IN_PRG,
+ XDMA_UPSTREAM,
+};
+
+struct aspeed_xdma_cmd {
+ u32 host_addr_lo;
+ u32 host_addr_hi;
+ u32 bmc_addr;
+ u32 comm1_hi;
+ u32 conf;
+ u32 id;
+ u32 resv0;
+ u32 resv1;
+};
+
+struct aspeed_xdma_client;
+
+struct aspeed_xdma {
+ struct device *dev;
+ void __iomem *base;
+ struct regmap *scu;
+ struct reset_control *reset;
+
+ unsigned long flags;
+ unsigned int cmd_idx;
+ wait_queue_head_t wait;
+ struct aspeed_xdma_client *current_client;
+
+ u32 vga_phys;
+ u32 vga_size;
+ dma_addr_t vga_dma;
+ void *cmdq;
+ void *vga_virt;
+};
+
+struct aspeed_xdma_client {
+ struct aspeed_xdma *ctx;
+
+ unsigned long flags;
+ u32 phys;
+ u32 size;
+};
+
+static const u32 aspeed_xdma_bmc_pcie_conf = SCU_PCIE_CONF_BMC_EN |
+ SCU_PCIE_CONF_BMC_EN_MSI | SCU_PCIE_CONF_BMC_EN_MCTP |
+ SCU_PCIE_CONF_BMC_EN_IRQ | SCU_PCIE_CONF_BMC_EN_DMA |
+ SCU_PCIE_CONF_RSVD;
+
+static const u32 aspeed_xdma_vga_pcie_conf = SCU_PCIE_CONF_VGA_EN |
+ SCU_PCIE_CONF_VGA_EN_MSI | SCU_PCIE_CONF_VGA_EN_MCTP |
+ SCU_PCIE_CONF_VGA_EN_IRQ | SCU_PCIE_CONF_VGA_EN_DMA |
+ SCU_PCIE_CONF_RSVD;
+
+static void aspeed_scu_pcie_write(struct aspeed_xdma *ctx, u32 conf)
+{
+ u32 v = 0;
+
+ regmap_write(ctx->scu, SCU_PCIE_CONF, conf);
+ regmap_read(ctx->scu, SCU_PCIE_CONF, &v);
+
+ dev_dbg(ctx->dev, "write scu pcie_conf[%08x]\n", v);
+}
+
+static u32 aspeed_xdma_reg_read(struct aspeed_xdma *ctx, u32 reg)
+{
+ u32 v = readl(ctx->base + reg);
+
+ dev_dbg(ctx->dev, "read %02x[%08x]\n", reg, v);
+ return v;
+}
+
+static void aspeed_xdma_reg_write(struct aspeed_xdma *ctx, u32 reg, u32 val)
+{
+ writel(val, ctx->base + reg);
+ dev_dbg(ctx->dev, "write %02x[%08x]\n", reg, readl(ctx->base + reg));
+}
+
+static void aspeed_xdma_init_eng(struct aspeed_xdma *ctx)
+{
+ const u32 ctrl = XDMA_CTRL_US_COMP | XDMA_CTRL_DS_COMP |
+ XDMA_CTRL_DS_DIRTY | FIELD_PREP(XDMA_CTRL_DS_PCIE_REQ_SIZE,
+ XDMA_DS_PCIE_REQ_SIZE_256) |
+ XDMA_CTRL_DS_DATA_TIMEOUT | XDMA_CTRL_DS_CHECK_ID;
+
+ aspeed_xdma_reg_write(ctx, XDMA_BMC_CMD_QUEUE_ENDP,
+ XDMA_CMD_SIZE * XDMA_NUM_CMDS);
+ aspeed_xdma_reg_write(ctx, XDMA_BMC_CMD_QUEUE_READP,
+ XDMA_BMC_CMD_QUEUE_READP_MAGIC);
+ aspeed_xdma_reg_write(ctx, XDMA_BMC_CMD_QUEUE_WRITEP, 0);
+ aspeed_xdma_reg_write(ctx, XDMA_CTRL, ctrl);
+
+ aspeed_xdma_reg_write(ctx, XDMA_BMC_CMD_QUEUE_ADDR, ctx->vga_phys);
+
+ ctx->cmd_idx = 0;
+ ctx->flags = 0;
+}
+
+static void aspeed_xdma_reset(struct aspeed_xdma *ctx)
+{
+ reset_control_assert(ctx->reset);
+
+ msleep(10);
+
+ reset_control_deassert(ctx->reset);
+
+ msleep(10);
+
+ aspeed_xdma_init_eng(ctx);
+}
+
+static void aspeed_xdma_start(struct aspeed_xdma *ctx,
+ struct aspeed_xdma_op *op, u32 bmc_addr)
+{
+ u32 conf = XDMA_CMD_CONF_CHECK | XDMA_CMD_CONF_IRQ_BMC |
+ XDMA_CMD_CONF_IRQ;
+ unsigned int line_size = op->len / XDMA_BYTE_ALIGN;
+ unsigned int num_lines = 1;
+ unsigned int nidx = (ctx->cmd_idx + 1) % XDMA_NUM_CMDS;
+ unsigned int pitch = 1;
+ struct aspeed_xdma_cmd *cmd =
+ &(((struct aspeed_xdma_cmd *)ctx->cmdq)[ctx->cmd_idx]);
+
+ if (line_size > XDMA_MAX_LINE_SIZE) {
+ unsigned int rem;
+ unsigned int total;
+
+ num_lines = line_size / XDMA_MAX_LINE_SIZE;
+ total = XDMA_MAX_LINE_SIZE * num_lines;
+ rem = line_size - total;
+ line_size = XDMA_MAX_LINE_SIZE;
+ pitch = line_size;
+
+ if (rem) {
+ unsigned int offs = total * XDMA_BYTE_ALIGN;
+ u32 r_bmc_addr = bmc_addr + offs;
+ u64 r_host_addr = op->host_addr + (u64)offs;
+ struct aspeed_xdma_cmd *r_cmd =
+ &(((struct aspeed_xdma_cmd *)ctx->cmdq)[nidx]);
+
+ r_cmd->host_addr_lo =
+ (u32)(r_host_addr & 0xFFFFFFFFULL);
+ r_cmd->host_addr_hi = (u32)(r_host_addr >> 32ULL);
+ r_cmd->bmc_addr = (r_bmc_addr & XDMA_CMD_BMC_ADDR) |
+ XDMA_CMD_BMC_CHECK |
+ (op->upstream ? XDMA_CMD_BMC_DIR_US : 0);
+ r_cmd->conf = conf |
+ FIELD_PREP(XDMA_CMD_CONF_LINE_SIZE, rem) |
+ FIELD_PREP(XDMA_CMD_CONF_NUM_LINES, 1);
+ r_cmd->comm1_hi =
+ FIELD_PREP(XDMA_CMD_COMM1_HI_HOST_PITCH, 1) |
+ FIELD_PREP(XDMA_CMD_COMM1_HI_BMC_PITCH, 1);
+
+ /* do not trigger IRQ for first command */
+ conf = XDMA_CMD_CONF_CHECK;
+
+ nidx = (nidx + 1) % XDMA_NUM_CMDS;
+ }
+
+ /* undocumented formula to get required number of lines */
+ num_lines = (num_lines * 2) - 1;
+ }
+
+ /* ctrl == 0 indicates engine hasn't started properly; restart it */
+ if (!aspeed_xdma_reg_read(ctx, XDMA_CTRL))
+ aspeed_xdma_reset(ctx);
+
+ cmd->host_addr_lo = (u32)(op->host_addr & 0xFFFFFFFFULL);
+ cmd->host_addr_hi = (u32)(op->host_addr >> 32ULL);
+ cmd->bmc_addr = (bmc_addr & XDMA_CMD_BMC_ADDR) | XDMA_CMD_BMC_CHECK |
+ (op->upstream ? XDMA_CMD_BMC_DIR_US : 0);
+ cmd->conf = conf |
+ FIELD_PREP(XDMA_CMD_CONF_LINE_SIZE, line_size) |
+ FIELD_PREP(XDMA_CMD_CONF_NUM_LINES, num_lines);
+ cmd->comm1_hi = FIELD_PREP(XDMA_CMD_COMM1_HI_HOST_PITCH, pitch) |
+ FIELD_PREP(XDMA_CMD_COMM1_HI_BMC_PITCH, pitch);
+
+ memcpy(ctx->vga_virt, ctx->cmdq, XDMA_CMDQ_SIZE);
+
+ if (op->upstream)
+ set_bit(XDMA_UPSTREAM, &ctx->flags);
+ else
+ clear_bit(XDMA_UPSTREAM, &ctx->flags);
+
+ set_bit(XDMA_IN_PRG, &ctx->flags);
+
+ aspeed_xdma_reg_write(ctx, XDMA_BMC_CMD_QUEUE_WRITEP,
+ nidx * XDMA_CMD_SIZE);
+ ctx->cmd_idx = nidx;
+}
+
+static void aspeed_xdma_done(struct aspeed_xdma *ctx)
+{
+ if (ctx->current_client) {
+ clear_bit(XDMA_IN_PRG, &ctx->current_client->flags);
+
+ ctx->current_client = NULL;
+ }
+
+ clear_bit(XDMA_IN_PRG, &ctx->flags);
+ wake_up_interruptible_all(&ctx->wait);
+}
+
+static irqreturn_t aspeed_xdma_irq(int irq, void *arg)
+{
+ struct aspeed_xdma *ctx = arg;
+ u32 status = aspeed_xdma_reg_read(ctx, XDMA_STATUS);
+
+ if (status & XDMA_STATUS_US_COMP) {
+ if (test_bit(XDMA_UPSTREAM, &ctx->flags))
+ aspeed_xdma_done(ctx);
+ }
+
+ if (status & XDMA_STATUS_DS_COMP) {
+ if (!test_bit(XDMA_UPSTREAM, &ctx->flags))
+ aspeed_xdma_done(ctx);
+ }
+
+ aspeed_xdma_reg_write(ctx, XDMA_STATUS, status);
+
+ return IRQ_HANDLED;
+}
+
+static int aspeed_xdma_init_mem(struct aspeed_xdma *ctx)
+{
+ int rc;
+ u32 scu_conf = 0;
+ u32 mem_size = 0x20000000;
+ const u32 mem_sizes[4] = { 0x8000000, 0x10000000, 0x20000000,
+ 0x40000000 };
+ const u32 vga_sizes[4] = { 0x800000, 0x1000000, 0x2000000, 0x4000000 };
+ void __iomem *sdmc_base = ioremap(0x1e6e0000, 0x100);
+
+ aspeed_scu_pcie_write(ctx, aspeed_xdma_vga_pcie_conf);
+
+ regmap_read(ctx->scu, SCU_STRAP, &scu_conf);
+ ctx->vga_size = vga_sizes[FIELD_GET(SCU_STRAP_VGA_MEM, scu_conf)];
+
+ if (sdmc_base) {
+ u32 sdmc = readl(sdmc_base + SDMC_CONF);
+ u32 remap = readl(sdmc_base + SDMC_REMAP);
+
+ remap |= SDMC_REMAP_MAGIC;
+ writel(remap, sdmc_base + SDMC_REMAP);
+ remap = readl(sdmc_base + SDMC_REMAP);
+
+ mem_size = mem_sizes[sdmc & SDMC_CONF_MEM];
+ iounmap(sdmc_base);
+ }
+
+ ctx->vga_phys = (mem_size - ctx->vga_size) + 0x80000000;
+
+ ctx->cmdq = devm_kzalloc(ctx->dev, XDMA_CMDQ_SIZE, GFP_KERNEL);
+ if (!ctx->cmdq) {
+ dev_err(ctx->dev, "Failed to allocate command queue.\n");
+ return -ENOMEM;
+ }
+
+ rc = dma_set_mask_and_coherent(ctx->dev, DMA_BIT_MASK(32));
+ if (rc) {
+ dev_err(ctx->dev, "Failed to set DMA mask: %d.\n", rc);
+ return rc;
+ }
+
+ rc = dma_declare_coherent_memory(ctx->dev, ctx->vga_phys,
+ ctx->vga_phys, ctx->vga_size);
+ if (rc) {
+ dev_err(ctx->dev, "Failed to declare coherent memory: %d.\n",
+ rc);
+ return rc;
+ }
+
+ ctx->vga_virt = dma_alloc_coherent(ctx->dev, ctx->vga_size,
+ &ctx->vga_dma, GFP_KERNEL);
+ if (!ctx->vga_virt) {
+ dev_err(ctx->dev, "Failed to allocate DMA.\n");
+ dma_release_declared_memory(ctx->dev);
+ return -ENOMEM;
+ }
+
+ dev_dbg(ctx->dev, "VGA mapped at phys[%08x], size[%08x].\n",
+ ctx->vga_phys, ctx->vga_size);
+
+ return 0;
+}
+
+static int aspeed_xdma_probe(struct platform_device *pdev)
+{
+ int irq;
+ int rc;
+ struct resource *res;
+ struct device *dev = &pdev->dev;
+ struct aspeed_xdma *ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+
+ if (!ctx)
+ return -ENOMEM;
+
+ ctx->dev = dev;
+ platform_set_drvdata(pdev, ctx);
+ init_waitqueue_head(&ctx->wait);
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ ctx->base = devm_ioremap_resource(dev, res);
+ if (IS_ERR(ctx->base)) {
+ dev_err(dev, "Unable to ioremap registers\n");
+ return PTR_ERR(ctx->base);
+ }
+
+ irq = irq_of_parse_and_map(dev->of_node, 0);
+ if (!irq) {
+ dev_err(dev, "Unable to find IRQ\n");
+ return -ENODEV;
+ }
+
+ rc = devm_request_irq(dev, irq, aspeed_xdma_irq, IRQF_SHARED,
+ DEVICE_NAME, ctx);
+ if (rc < 0) {
+ dev_err(dev, "Unable to request IRQ %d\n", irq);
+ return rc;
+ }
+
+ ctx->scu = syscon_regmap_lookup_by_compatible("aspeed,ast2500-scu");
+ if (IS_ERR(ctx->scu)) {
+ dev_err(ctx->dev, "Unable to grab SCU regs\n");
+ return PTR_ERR(ctx->scu);
+ }
+
+ ctx->reset = devm_reset_control_get_exclusive(dev, NULL);
+ if (IS_ERR(ctx->reset)) {
+ dev_err(dev, "Unable to request reset control\n");
+ return PTR_ERR(ctx->reset);
+ }
+
+ reset_control_deassert(ctx->reset);
+
+ msleep(10);
+
+ rc = aspeed_xdma_init_mem(ctx);
+ if (rc) {
+ reset_control_assert(ctx->reset);
+ return rc;
+ }
+
+ aspeed_xdma_init_eng(ctx);
+
+ return 0;
+}
+
+static int aspeed_xdma_remove(struct platform_device *pdev)
+{
+ struct aspeed_xdma *ctx = platform_get_drvdata(pdev);
+
+ dma_free_coherent(ctx->dev, ctx->vga_size, ctx->vga_virt,
+ ctx->vga_dma);
+ dma_release_declared_memory(ctx->dev);
+ reset_control_assert(ctx->reset);
+
+ return 0;
+}
+
+static const struct of_device_id aspeed_xdma_match[] = {
+ { .compatible = "aspeed,ast2500-xdma" },
+ { },
+};
+
+static struct platform_driver aspeed_xdma_driver = {
+ .probe = aspeed_xdma_probe,
+ .remove = aspeed_xdma_remove,
+ .driver = {
+ .name = DEVICE_NAME,
+ .of_match_table = aspeed_xdma_match,
+ },
+};
+
+module_platform_driver(aspeed_xdma_driver);
+
+MODULE_AUTHOR("Eddie James");
+MODULE_DESCRIPTION("Aspeed XDMA Engine Driver");
+MODULE_LICENSE("GPL v2");
diff --git a/include/uapi/linux/aspeed-xdma.h b/include/uapi/linux/aspeed-xdma.h
new file mode 100644
index 0000000..2a4bd13
--- /dev/null
+++ b/include/uapi/linux/aspeed-xdma.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/* Copyright IBM Corp 2019 */
+
+#ifndef _UAPI_LINUX_ASPEED_XDMA_H_
+#define _UAPI_LINUX_ASPEED_XDMA_H_
+
+#include <linux/types.h>
+
+/*
+ * aspeed_xdma_op
+ *
+ * upstream: boolean indicating the direction of the DMA operation; upstream
+ * means a transfer from the BMC to the host
+ *
+ * host_addr: the DMA address on the host side, typically configured by PCI
+ * subsystem
+ *
+ * len: the size of the transfer in bytes; it should be a multiple of 16 bytes
+ */
+struct aspeed_xdma_op {
+ __u32 upstream;
+ __u64 host_addr;
+ __u32 len;
+};
+
+#endif /* _UAPI_LINUX_ASPEED_XDMA_H_ */
--
1.8.3.1
^ permalink raw reply related
* [PATCH v2 3/7] drivers/soc: xdma: Add user interface
From: Eddie James @ 2019-05-20 20:19 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <1558383565-11821-1-git-send-email-eajames@linux.ibm.com>
This commits adds a miscdevice to provide a user interface to the XDMA
engine. The interface provides the write operation to start DMA
operations. The DMA parameters are passed as the data to the write call.
The actual data to transfer is NOT passed through write. Note that both
directions of DMA operation are accomplished through the write command;
BMC to host and host to BMC.
The XDMA engine is restricted to only accessing the reserved memory
space on the AST2500, typically used by the VGA. For this reason, this
commit also adds a simple memory manager for this reserved memory space
which can then be allocated in pages by users calling mmap. The space
allocated by a client will be the space used in the DMA operation. For
an "upstream" (BMC to host) operation, the data in the client's area
will be transferred to the host. For a "downstream" (host to BMC)
operation, the host data will be placed in the client's memory area.
Poll is also provided in order to determine when the DMA operation is
complete for non-blocking IO.
Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
drivers/soc/aspeed/aspeed-xdma.c | 301 +++++++++++++++++++++++++++++++++++++++
1 file changed, 301 insertions(+)
diff --git a/drivers/soc/aspeed/aspeed-xdma.c b/drivers/soc/aspeed/aspeed-xdma.c
index 0992d2a..2162ca0 100644
--- a/drivers/soc/aspeed/aspeed-xdma.c
+++ b/drivers/soc/aspeed/aspeed-xdma.c
@@ -118,6 +118,12 @@ struct aspeed_xdma_cmd {
u32 resv1;
};
+struct aspeed_xdma_vga_blk {
+ u32 phys;
+ u32 size;
+ struct list_head list;
+};
+
struct aspeed_xdma_client;
struct aspeed_xdma {
@@ -128,6 +134,8 @@ struct aspeed_xdma {
unsigned long flags;
unsigned int cmd_idx;
+ struct mutex list_lock;
+ struct mutex start_lock;
wait_queue_head_t wait;
struct aspeed_xdma_client *current_client;
@@ -136,6 +144,9 @@ struct aspeed_xdma {
dma_addr_t vga_dma;
void *cmdq;
void *vga_virt;
+ struct list_head vga_blks_free;
+
+ struct miscdevice misc;
};
struct aspeed_xdma_client {
@@ -325,6 +336,260 @@ static irqreturn_t aspeed_xdma_irq(int irq, void *arg)
return IRQ_HANDLED;
}
+static u32 aspeed_xdma_alloc_vga_blk(struct aspeed_xdma *ctx, u32 req_size)
+{
+ u32 phys = 0;
+ u32 size = PAGE_ALIGN(req_size);
+ struct aspeed_xdma_vga_blk *free;
+
+ mutex_lock(&ctx->list_lock);
+
+ list_for_each_entry(free, &ctx->vga_blks_free, list) {
+ if (free->size >= size) {
+ phys = free->phys;
+
+ if (size == free->size) {
+ dev_dbg(ctx->dev,
+ "Allocd %08x[%08x r(%08x)], del.\n",
+ phys, size, req_size);
+ list_del(&free->list);
+ kfree(free);
+ } else {
+ free->phys += size;
+ free->size -= size;
+ dev_dbg(ctx->dev, "Allocd %08x[%08x r(%08x)], "
+ "shrunk %08x[%08x].\n", phys, size,
+ req_size, free->phys, free->size);
+ }
+
+ break;
+ }
+ }
+
+ mutex_unlock(&ctx->list_lock);
+
+ return phys;
+}
+
+static void aspeed_xdma_free_vga_blk(struct aspeed_xdma *ctx, u32 phys,
+ u32 req_size)
+{
+ u32 min_free = UINT_MAX;
+ u32 size = PAGE_ALIGN(req_size);
+ const u32 end = phys + size;
+ struct aspeed_xdma_vga_blk *free;
+
+ mutex_lock(&ctx->list_lock);
+
+ list_for_each_entry(free, &ctx->vga_blks_free, list) {
+ if (end == free->phys) {
+ u32 fend = free->phys + free->size;
+
+ dev_dbg(ctx->dev,
+ "Freed %08x[%08x r(%08x)], exp %08x[%08x].\n",
+ phys, size, req_size, free->phys, free->size);
+
+ free->phys = phys;
+ free->size = fend - free->phys;
+
+ mutex_unlock(&ctx->list_lock);
+ return;
+ }
+
+ if (free->phys < min_free)
+ min_free = free->phys;
+ }
+
+ free = kzalloc(sizeof(*free), GFP_KERNEL);
+ if (free) {
+ free->phys = phys;
+ free->size = size;
+
+ dev_dbg(ctx->dev, "Freed %08x[%08x r(%08x)], new.\n", phys,
+ size, req_size);
+
+ if (phys < min_free)
+ list_add(&free->list, &ctx->vga_blks_free);
+ else
+ list_add_tail(&free->list, &ctx->vga_blks_free);
+ } else {
+ dev_err(ctx->dev, "Failed to register freed block.\n");
+ }
+
+ mutex_unlock(&ctx->list_lock);
+}
+
+static ssize_t aspeed_xdma_write(struct file *file, const char __user *buf,
+ size_t len, loff_t *offset)
+{
+ int rc;
+ struct aspeed_xdma_op op;
+ struct aspeed_xdma_client *client = file->private_data;
+ struct aspeed_xdma *ctx = client->ctx;
+ u32 offs = client->phys ? (client->phys - ctx->vga_phys) :
+ XDMA_CMDQ_SIZE;
+
+ if (len != sizeof(struct aspeed_xdma_op))
+ return -EINVAL;
+
+ rc = copy_from_user(&op, buf, len);
+ if (rc)
+ return rc;
+
+ if (op.len > (ctx->vga_size - offs) || op.len < XDMA_BYTE_ALIGN)
+ return -EINVAL;
+
+ if (file->f_flags & O_NONBLOCK) {
+ if (!mutex_trylock(&ctx->start_lock))
+ return -EAGAIN;
+
+ if (test_bit(XDMA_IN_PRG, &ctx->flags)) {
+ mutex_unlock(&ctx->start_lock);
+ return -EAGAIN;
+ }
+ } else {
+ mutex_lock(&ctx->start_lock);
+
+ rc = wait_event_interruptible(ctx->wait,
+ !test_bit(XDMA_IN_PRG,
+ &ctx->flags));
+ if (rc) {
+ mutex_unlock(&ctx->start_lock);
+ return -EINTR;
+ }
+ }
+
+ ctx->current_client = client;
+ set_bit(XDMA_IN_PRG, &client->flags);
+
+ aspeed_xdma_start(ctx, &op, ctx->vga_phys + offs);
+
+ mutex_unlock(&ctx->start_lock);
+
+ if (!(file->f_flags & O_NONBLOCK)) {
+ rc = wait_event_interruptible(ctx->wait,
+ !test_bit(XDMA_IN_PRG,
+ &ctx->flags));
+ if (rc)
+ return -EINTR;
+ }
+
+ return len;
+}
+
+static __poll_t aspeed_xdma_poll(struct file *file,
+ struct poll_table_struct *wait)
+{
+ __poll_t mask = 0;
+ __poll_t req = poll_requested_events(wait);
+ struct aspeed_xdma_client *client = file->private_data;
+ struct aspeed_xdma *ctx = client->ctx;
+
+ if (req & (EPOLLIN | EPOLLRDNORM)) {
+ if (test_bit(XDMA_IN_PRG, &client->flags))
+ poll_wait(file, &ctx->wait, wait);
+
+ if (!test_bit(XDMA_IN_PRG, &client->flags))
+ mask |= EPOLLIN | EPOLLRDNORM;
+ }
+
+ if (req & (EPOLLOUT | EPOLLWRNORM)) {
+ if (test_bit(XDMA_IN_PRG, &ctx->flags))
+ poll_wait(file, &ctx->wait, wait);
+
+ if (!test_bit(XDMA_IN_PRG, &ctx->flags))
+ mask |= EPOLLOUT | EPOLLWRNORM;
+ }
+
+ return mask;
+}
+
+static void aspeed_xdma_vma_close(struct vm_area_struct *vma)
+{
+ struct aspeed_xdma_client *client = vma->vm_private_data;
+
+ aspeed_xdma_free_vga_blk(client->ctx, client->phys, client->size);
+
+ client->phys = 0;
+ client->size = 0;
+}
+
+static const struct vm_operations_struct aspeed_xdma_vm_ops = {
+ .close = aspeed_xdma_vma_close,
+};
+
+static int aspeed_xdma_mmap(struct file *file, struct vm_area_struct *vma)
+{
+ int rc;
+ struct aspeed_xdma_client *client = file->private_data;
+ struct aspeed_xdma *ctx = client->ctx;
+
+ /* restrict file to one mapping */
+ if (client->size)
+ return -ENOMEM;
+
+ client->size = vma->vm_end - vma->vm_start;
+ client->phys = aspeed_xdma_alloc_vga_blk(ctx, client->size);
+ if (!client->phys) {
+ client->size = 0;
+ return -ENOMEM;
+ }
+
+ vma->vm_pgoff = (client->phys - ctx->vga_phys) >> PAGE_SHIFT;
+ vma->vm_ops = &aspeed_xdma_vm_ops;
+ vma->vm_private_data = client;
+
+ rc = dma_mmap_coherent(ctx->dev, vma, ctx->vga_virt, ctx->vga_dma,
+ ctx->vga_size);
+ if (rc) {
+ aspeed_xdma_free_vga_blk(ctx, client->phys, client->size);
+
+ client->phys = 0;
+ client->size = 0;
+ return rc;
+ }
+
+ dev_dbg(ctx->dev, "mmap: v[%08lx] to p[%08x], s[%08x]\n",
+ vma->vm_start, client->phys, client->size);
+
+ return 0;
+}
+
+static int aspeed_xdma_open(struct inode *inode, struct file *file)
+{
+ struct miscdevice *misc = file->private_data;
+ struct aspeed_xdma *ctx = container_of(misc, struct aspeed_xdma, misc);
+ struct aspeed_xdma_client *client = kzalloc(sizeof(*client),
+ GFP_KERNEL);
+
+ if (!client)
+ return -ENOMEM;
+
+ client->ctx = ctx;
+ file->private_data = client;
+ return 0;
+}
+
+static int aspeed_xdma_release(struct inode *inode, struct file *file)
+{
+ struct aspeed_xdma_client *client = file->private_data;
+
+ if (client->ctx->current_client == client)
+ client->ctx->current_client = NULL;
+
+ kfree(client);
+ return 0;
+}
+
+static const struct file_operations aspeed_xdma_fops = {
+ .owner = THIS_MODULE,
+ .write = aspeed_xdma_write,
+ .poll = aspeed_xdma_poll,
+ .mmap = aspeed_xdma_mmap,
+ .open = aspeed_xdma_open,
+ .release = aspeed_xdma_release,
+};
+
static int aspeed_xdma_init_mem(struct aspeed_xdma *ctx)
{
int rc;
@@ -382,12 +647,26 @@ static int aspeed_xdma_init_mem(struct aspeed_xdma *ctx)
return -ENOMEM;
}
+ aspeed_xdma_free_vga_blk(ctx, ctx->vga_phys, ctx->vga_size);
+ aspeed_xdma_alloc_vga_blk(ctx, XDMA_CMDQ_SIZE);
+
dev_dbg(ctx->dev, "VGA mapped at phys[%08x], size[%08x].\n",
ctx->vga_phys, ctx->vga_size);
return 0;
}
+static void aspeed_xdma_free_vga_blks(struct aspeed_xdma *ctx)
+{
+ struct aspeed_xdma_vga_blk *free;
+ struct aspeed_xdma_vga_blk *tmp;
+
+ list_for_each_entry_safe(free, tmp, &ctx->vga_blks_free, list) {
+ list_del(&free->list);
+ kfree(free);
+ }
+}
+
static int aspeed_xdma_probe(struct platform_device *pdev)
{
int irq;
@@ -402,6 +681,9 @@ static int aspeed_xdma_probe(struct platform_device *pdev)
ctx->dev = dev;
platform_set_drvdata(pdev, ctx);
init_waitqueue_head(&ctx->wait);
+ mutex_init(&ctx->list_lock);
+ mutex_init(&ctx->start_lock);
+ INIT_LIST_HEAD(&ctx->vga_blks_free);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
ctx->base = devm_ioremap_resource(dev, res);
@@ -447,6 +729,22 @@ static int aspeed_xdma_probe(struct platform_device *pdev)
aspeed_xdma_init_eng(ctx);
+ ctx->misc.minor = MISC_DYNAMIC_MINOR;
+ ctx->misc.fops = &aspeed_xdma_fops;
+ ctx->misc.name = "xdma";
+ ctx->misc.parent = dev;
+ rc = misc_register(&ctx->misc);
+ if (rc) {
+ dev_err(dev, "Unable to register xdma miscdevice\n");
+
+ aspeed_xdma_free_vga_blks(ctx);
+ dma_free_coherent(dev, ctx->vga_size, ctx->vga_virt,
+ ctx->vga_dma);
+ dma_release_declared_memory(dev);
+ reset_control_assert(ctx->reset);
+ return rc;
+ }
+
return 0;
}
@@ -454,6 +752,9 @@ static int aspeed_xdma_remove(struct platform_device *pdev)
{
struct aspeed_xdma *ctx = platform_get_drvdata(pdev);
+ misc_deregister(&ctx->misc);
+
+ aspeed_xdma_free_vga_blks(ctx);
dma_free_coherent(ctx->dev, ctx->vga_size, ctx->vga_virt,
ctx->vga_dma);
dma_release_declared_memory(ctx->dev);
--
1.8.3.1
^ permalink raw reply related
* [PATCH v2 4/7] drivers/soc: xdma: Add PCI device configuration sysfs
From: Eddie James @ 2019-05-20 20:19 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <1558383565-11821-1-git-send-email-eajames@linux.ibm.com>
The AST2500 has two PCI devices embedded. The XDMA engine can use either
device to perform DMA transfers. Users need the capability to choose
which device to use. This commit therefore adds two sysfs files that
toggle the AST2500 and XDMA engine between the two PCI devices.
Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
drivers/soc/aspeed/aspeed-xdma.c | 64 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/drivers/soc/aspeed/aspeed-xdma.c b/drivers/soc/aspeed/aspeed-xdma.c
index 2162ca0..002b571 100644
--- a/drivers/soc/aspeed/aspeed-xdma.c
+++ b/drivers/soc/aspeed/aspeed-xdma.c
@@ -667,6 +667,64 @@ static void aspeed_xdma_free_vga_blks(struct aspeed_xdma *ctx)
}
}
+static int aspeed_xdma_change_pcie_conf(struct aspeed_xdma *ctx, u32 conf)
+{
+ int rc;
+
+ mutex_lock(&ctx->start_lock);
+ rc = wait_event_interruptible_timeout(ctx->wait,
+ !test_bit(XDMA_IN_PRG,
+ &ctx->flags),
+ msecs_to_jiffies(1000));
+ if (rc < 0) {
+ mutex_unlock(&ctx->start_lock);
+ return -EINTR;
+ }
+
+ /* previous op didn't complete, wake up waiters anyway */
+ if (!rc)
+ wake_up_interruptible_all(&ctx->wait);
+
+ reset_control_assert(ctx->reset);
+ msleep(10);
+
+ aspeed_scu_pcie_write(ctx, conf);
+ msleep(10);
+
+ reset_control_deassert(ctx->reset);
+ msleep(10);
+
+ aspeed_xdma_init_eng(ctx);
+
+ mutex_unlock(&ctx->start_lock);
+
+ return 0;
+}
+
+static ssize_t aspeed_xdma_use_bmc(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ int rc;
+ struct aspeed_xdma *ctx = dev_get_drvdata(dev);
+
+ rc = aspeed_xdma_change_pcie_conf(ctx, aspeed_xdma_bmc_pcie_conf);
+ return rc ?: count;
+}
+static DEVICE_ATTR(use_bmc, 0200, NULL, aspeed_xdma_use_bmc);
+
+static ssize_t aspeed_xdma_use_vga(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ int rc;
+ struct aspeed_xdma *ctx = dev_get_drvdata(dev);
+
+ rc = aspeed_xdma_change_pcie_conf(ctx, aspeed_xdma_vga_pcie_conf);
+ return rc ?: count;
+}
+static DEVICE_ATTR(use_vga, 0200, NULL, aspeed_xdma_use_vga);
+
static int aspeed_xdma_probe(struct platform_device *pdev)
{
int irq;
@@ -745,6 +803,9 @@ static int aspeed_xdma_probe(struct platform_device *pdev)
return rc;
}
+ device_create_file(dev, &dev_attr_use_bmc);
+ device_create_file(dev, &dev_attr_use_vga);
+
return 0;
}
@@ -752,6 +813,9 @@ static int aspeed_xdma_remove(struct platform_device *pdev)
{
struct aspeed_xdma *ctx = platform_get_drvdata(pdev);
+ device_remove_file(ctx->dev, &dev_attr_use_vga);
+ device_remove_file(ctx->dev, &dev_attr_use_bmc);
+
misc_deregister(&ctx->misc);
aspeed_xdma_free_vga_blks(ctx);
--
1.8.3.1
^ permalink raw reply related
* [PATCH v2 5/7] drivers/soc: xdma: Add debugfs entries
From: Eddie James @ 2019-05-20 20:19 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <1558383565-11821-1-git-send-email-eajames@linux.ibm.com>
Add debugfs entries for the relevant XDMA engine registers and for
dumping the AST2500 reserved memory space.
Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
drivers/soc/aspeed/aspeed-xdma.c | 96 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 96 insertions(+)
diff --git a/drivers/soc/aspeed/aspeed-xdma.c b/drivers/soc/aspeed/aspeed-xdma.c
index 002b571..c083173 100644
--- a/drivers/soc/aspeed/aspeed-xdma.c
+++ b/drivers/soc/aspeed/aspeed-xdma.c
@@ -147,6 +147,12 @@ struct aspeed_xdma {
struct list_head vga_blks_free;
struct miscdevice misc;
+ struct dentry *debugfs_dir;
+
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+ struct debugfs_regset32 regset;
+ struct debugfs_reg32 regs[XDMA_NUM_DEBUGFS_REGS];
+#endif /* IS_ENABLED(CONFIG_DEBUG_FS) */
};
struct aspeed_xdma_client {
@@ -656,6 +662,92 @@ static int aspeed_xdma_init_mem(struct aspeed_xdma *ctx)
return 0;
}
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+static ssize_t aspeed_xdma_debugfs_vga_read(struct file *file,
+ char __user *buf, size_t len,
+ loff_t *offset)
+{
+ int rc;
+ struct inode *inode = file_inode(file);
+ struct aspeed_xdma *ctx = inode->i_private;
+ void __iomem *vga = ioremap(ctx->vga_phys, ctx->vga_size);
+ loff_t offs = *offset;
+ void *tmp;
+
+ if (!vga)
+ return -ENOMEM;
+
+ if (len + offs > ctx->vga_size) {
+ iounmap(vga);
+ return -EINVAL;
+ }
+
+ tmp = kzalloc(len, GFP_KERNEL);
+ if (!tmp) {
+ iounmap(vga);
+ return -ENOMEM;
+ }
+
+ memcpy_fromio(tmp, vga + offs, len);
+
+ rc = copy_to_user(buf, tmp, len);
+ if (rc) {
+ iounmap(vga);
+ kfree(tmp);
+ return rc;
+ }
+
+ *offset = offs + len;
+
+ kfree(tmp);
+ iounmap(vga);
+
+ return len;
+}
+
+static const struct file_operations aspeed_xdma_debugfs_vga_fops = {
+ .owner = THIS_MODULE,
+ .llseek = generic_file_llseek,
+ .read = aspeed_xdma_debugfs_vga_read,
+};
+
+static void aspeed_xdma_init_debugfs(struct aspeed_xdma *ctx)
+{
+ ctx->debugfs_dir = debugfs_create_dir(DEVICE_NAME, NULL);
+ if (IS_ERR_OR_NULL(ctx->debugfs_dir)) {
+ dev_warn(ctx->dev, "Failed to create debugfs directory.\n");
+ return;
+ }
+
+ debugfs_create_file("vga", 0444, ctx->debugfs_dir, ctx,
+ &aspeed_xdma_debugfs_vga_fops);
+
+ ctx->regs[0].name = "addr";
+ ctx->regs[0].offset = XDMA_BMC_CMD_QUEUE_ADDR;
+ ctx->regs[1].name = "endp";
+ ctx->regs[1].offset = XDMA_BMC_CMD_QUEUE_ENDP;
+ ctx->regs[2].name = "writep";
+ ctx->regs[2].offset = XDMA_BMC_CMD_QUEUE_WRITEP;
+ ctx->regs[3].name = "readp";
+ ctx->regs[3].offset = XDMA_BMC_CMD_QUEUE_READP;
+ ctx->regs[4].name = "control";
+ ctx->regs[4].offset = XDMA_CTRL;
+ ctx->regs[5].name = "status";
+ ctx->regs[5].offset = XDMA_STATUS;
+
+ ctx->regset.regs = ctx->regs;
+ ctx->regset.nregs = XDMA_NUM_DEBUGFS_REGS;
+ ctx->regset.base = ctx->base;
+
+ debugfs_create_regset32("regs", 0444, ctx->debugfs_dir, &ctx->regset);
+}
+#else
+static void aspeed_xdma_init_debugfs(struct aspeed_xdma *ctx)
+{
+}
+
+#endif /* IS_ENABLED(CONFIG_DEBUG_FS) */
+
static void aspeed_xdma_free_vga_blks(struct aspeed_xdma *ctx)
{
struct aspeed_xdma_vga_blk *free;
@@ -806,6 +898,8 @@ static int aspeed_xdma_probe(struct platform_device *pdev)
device_create_file(dev, &dev_attr_use_bmc);
device_create_file(dev, &dev_attr_use_vga);
+ aspeed_xdma_init_debugfs(ctx);
+
return 0;
}
@@ -813,6 +907,8 @@ static int aspeed_xdma_remove(struct platform_device *pdev)
{
struct aspeed_xdma *ctx = platform_get_drvdata(pdev);
+ debugfs_remove_recursive(ctx->debugfs_dir);
+
device_remove_file(ctx->dev, &dev_attr_use_vga);
device_remove_file(ctx->dev, &dev_attr_use_bmc);
--
1.8.3.1
^ permalink raw reply related
* [PATCH v2 6/7] ARM: dts: aspeed: Add XDMA Engine
From: Eddie James @ 2019-05-20 20:19 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <1558383565-11821-1-git-send-email-eajames@linux.ibm.com>
Add a node for the XDMA engine with all the necessary information.
Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
arch/arm/boot/dts/aspeed-g5.dtsi | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/arm/boot/dts/aspeed-g5.dtsi b/arch/arm/boot/dts/aspeed-g5.dtsi
index 4345c31..f9e9730 100644
--- a/arch/arm/boot/dts/aspeed-g5.dtsi
+++ b/arch/arm/boot/dts/aspeed-g5.dtsi
@@ -238,6 +238,14 @@
interrupts = <0x19>;
};
+ xdma: xdma at 1e6e7000 {
+ compatible = "aspeed,ast2500-xdma";
+ reg = <0x1e6e7000 0x100>;
+ resets = <&syscon ASPEED_RESET_XDMA>;
+ interrupts = <6>;
+ status = "disabled";
+ };
+
adc: adc at 1e6e9000 {
compatible = "aspeed,ast2500-adc";
reg = <0x1e6e9000 0xb0>;
--
1.8.3.1
^ permalink raw reply related
* [PATCH v2 7/7] ARM: dts: aspeed: witherspoon: Enable XDMA Engine
From: Eddie James @ 2019-05-20 20:19 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <1558383565-11821-1-git-send-email-eajames@linux.ibm.com>
Enable the XDMA engine node.
Signed-off-by: Eddie James <eajames@linux.ibm.com>
---
arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts b/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
index f1356ca..9d02759 100644
--- a/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
+++ b/arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts
@@ -640,3 +640,7 @@
&vhub {
status = "okay";
};
+
+&xdma {
+ status = "okay";
+};
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCH v2 4/7] drivers/soc: xdma: Add PCI device configuration sysfs
From: Andrew Jeffery @ 2019-05-21 3:22 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <1558383565-11821-5-git-send-email-eajames@linux.ibm.com>
On Tue, 21 May 2019, at 05:51, Eddie James wrote:
> The AST2500 has two PCI devices embedded. The XDMA engine can use either
> device to perform DMA transfers. Users need the capability to choose
> which device to use. This commit therefore adds two sysfs files that
> toggle the AST2500 and XDMA engine between the two PCI devices.
>
> Signed-off-by: Eddie James <eajames@linux.ibm.com>
> ---
> drivers/soc/aspeed/aspeed-xdma.c | 64 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 64 insertions(+)
>
> diff --git a/drivers/soc/aspeed/aspeed-xdma.c
> b/drivers/soc/aspeed/aspeed-xdma.c
> index 2162ca0..002b571 100644
> --- a/drivers/soc/aspeed/aspeed-xdma.c
> +++ b/drivers/soc/aspeed/aspeed-xdma.c
> @@ -667,6 +667,64 @@ static void aspeed_xdma_free_vga_blks(struct
> aspeed_xdma *ctx)
> }
> }
>
> +static int aspeed_xdma_change_pcie_conf(struct aspeed_xdma *ctx, u32 conf)
> +{
> + int rc;
> +
> + mutex_lock(&ctx->start_lock);
> + rc = wait_event_interruptible_timeout(ctx->wait,
> + !test_bit(XDMA_IN_PRG,
> + &ctx->flags),
> + msecs_to_jiffies(1000));
> + if (rc < 0) {
> + mutex_unlock(&ctx->start_lock);
> + return -EINTR;
> + }
> +
> + /* previous op didn't complete, wake up waiters anyway */
> + if (!rc)
> + wake_up_interruptible_all(&ctx->wait);
> +
> + reset_control_assert(ctx->reset);
> + msleep(10);
> +
> + aspeed_scu_pcie_write(ctx, conf);
> + msleep(10);
> +
> + reset_control_deassert(ctx->reset);
> + msleep(10);
> +
> + aspeed_xdma_init_eng(ctx);
> +
> + mutex_unlock(&ctx->start_lock);
> +
> + return 0;
> +}
> +
> +static ssize_t aspeed_xdma_use_bmc(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
> + int rc;
> + struct aspeed_xdma *ctx = dev_get_drvdata(dev);
> +
> + rc = aspeed_xdma_change_pcie_conf(ctx, aspeed_xdma_bmc_pcie_conf);
> + return rc ?: count;
> +}
> +static DEVICE_ATTR(use_bmc, 0200, NULL, aspeed_xdma_use_bmc);
> +
> +static ssize_t aspeed_xdma_use_vga(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
> + int rc;
> + struct aspeed_xdma *ctx = dev_get_drvdata(dev);
> +
> + rc = aspeed_xdma_change_pcie_conf(ctx, aspeed_xdma_vga_pcie_conf);
> + return rc ?: count;
> +}
> +static DEVICE_ATTR(use_vga, 0200, NULL, aspeed_xdma_use_vga);
> +
> static int aspeed_xdma_probe(struct platform_device *pdev)
> {
> int irq;
> @@ -745,6 +803,9 @@ static int aspeed_xdma_probe(struct platform_device *pdev)
> return rc;
> }
>
> + device_create_file(dev, &dev_attr_use_bmc);
> + device_create_file(dev, &dev_attr_use_vga);
Two attributes is a broken approach IMO. This gives the false representation of 4
states (neither, vga, bmc, both) when really there are only two (vga and bmc). I
think we should have one attribute that reacts to "vga" and "bmc" writes.
Andrew
> +
> return 0;
> }
>
> @@ -752,6 +813,9 @@ static int aspeed_xdma_remove(struct platform_device *pdev)
> {
> struct aspeed_xdma *ctx = platform_get_drvdata(pdev);
>
> + device_remove_file(ctx->dev, &dev_attr_use_vga);
> + device_remove_file(ctx->dev, &dev_attr_use_bmc);
> +
> misc_deregister(&ctx->misc);
>
> aspeed_xdma_free_vga_blks(ctx);
> --
> 1.8.3.1
>
>
^ permalink raw reply
* [PATCH v2 3/7] drivers/soc: xdma: Add user interface
From: Andrew Jeffery @ 2019-05-21 3:52 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <1558383565-11821-4-git-send-email-eajames@linux.ibm.com>
On Tue, 21 May 2019, at 05:49, Eddie James wrote:
> This commits adds a miscdevice to provide a user interface to the XDMA
> engine. The interface provides the write operation to start DMA
> operations. The DMA parameters are passed as the data to the write call.
> The actual data to transfer is NOT passed through write. Note that both
> directions of DMA operation are accomplished through the write command;
> BMC to host and host to BMC.
>
> The XDMA engine is restricted to only accessing the reserved memory
> space on the AST2500, typically used by the VGA. For this reason, this
> commit also adds a simple memory manager for this reserved memory space
> which can then be allocated in pages by users calling mmap. The space
> allocated by a client will be the space used in the DMA operation. For
> an "upstream" (BMC to host) operation, the data in the client's area
> will be transferred to the host. For a "downstream" (host to BMC)
> operation, the host data will be placed in the client's memory area.
Did you explore genalloc as a solution for allocating out of the VGA reserved
memory? Wondering if we can avoid implementing a custom allocator (even if
it is simple).
Andrew
>
> Poll is also provided in order to determine when the DMA operation is
> complete for non-blocking IO.
>
> Signed-off-by: Eddie James <eajames@linux.ibm.com>
> ---
> drivers/soc/aspeed/aspeed-xdma.c | 301 +++++++++++++++++++++++++++++++++++++++
> 1 file changed, 301 insertions(+)
>
> diff --git a/drivers/soc/aspeed/aspeed-xdma.c b/drivers/soc/aspeed/aspeed-xdma.c
> index 0992d2a..2162ca0 100644
> --- a/drivers/soc/aspeed/aspeed-xdma.c
> +++ b/drivers/soc/aspeed/aspeed-xdma.c
> @@ -118,6 +118,12 @@ struct aspeed_xdma_cmd {
> u32 resv1;
> };
>
> +struct aspeed_xdma_vga_blk {
> + u32 phys;
> + u32 size;
> + struct list_head list;
> +};
> +
> struct aspeed_xdma_client;
>
> struct aspeed_xdma {
> @@ -128,6 +134,8 @@ struct aspeed_xdma {
>
> unsigned long flags;
> unsigned int cmd_idx;
> + struct mutex list_lock;
> + struct mutex start_lock;
> wait_queue_head_t wait;
> struct aspeed_xdma_client *current_client;
>
> @@ -136,6 +144,9 @@ struct aspeed_xdma {
> dma_addr_t vga_dma;
> void *cmdq;
> void *vga_virt;
> + struct list_head vga_blks_free;
> +
> + struct miscdevice misc;
> };
>
> struct aspeed_xdma_client {
> @@ -325,6 +336,260 @@ static irqreturn_t aspeed_xdma_irq(int irq, void *arg)
> return IRQ_HANDLED;
> }
>
> +static u32 aspeed_xdma_alloc_vga_blk(struct aspeed_xdma *ctx, u32 req_size)
> +{
> + u32 phys = 0;
> + u32 size = PAGE_ALIGN(req_size);
> + struct aspeed_xdma_vga_blk *free;
> +
> + mutex_lock(&ctx->list_lock);
> +
> + list_for_each_entry(free, &ctx->vga_blks_free, list) {
> + if (free->size >= size) {
> + phys = free->phys;
> +
> + if (size == free->size) {
> + dev_dbg(ctx->dev,
> + "Allocd %08x[%08x r(%08x)], del.\n",
> + phys, size, req_size);
> + list_del(&free->list);
> + kfree(free);
> + } else {
> + free->phys += size;
> + free->size -= size;
> + dev_dbg(ctx->dev, "Allocd %08x[%08x r(%08x)], "
> + "shrunk %08x[%08x].\n", phys, size,
> + req_size, free->phys, free->size);
> + }
> +
> + break;
> + }
> + }
> +
> + mutex_unlock(&ctx->list_lock);
> +
> + return phys;
> +}
> +
> +static void aspeed_xdma_free_vga_blk(struct aspeed_xdma *ctx, u32 phys,
> + u32 req_size)
> +{
> + u32 min_free = UINT_MAX;
> + u32 size = PAGE_ALIGN(req_size);
> + const u32 end = phys + size;
> + struct aspeed_xdma_vga_blk *free;
> +
> + mutex_lock(&ctx->list_lock);
> +
> + list_for_each_entry(free, &ctx->vga_blks_free, list) {
> + if (end == free->phys) {
> + u32 fend = free->phys + free->size;
> +
> + dev_dbg(ctx->dev,
> + "Freed %08x[%08x r(%08x)], exp %08x[%08x].\n",
> + phys, size, req_size, free->phys, free->size);
> +
> + free->phys = phys;
> + free->size = fend - free->phys;
> +
> + mutex_unlock(&ctx->list_lock);
> + return;
> + }
> +
> + if (free->phys < min_free)
> + min_free = free->phys;
> + }
> +
> + free = kzalloc(sizeof(*free), GFP_KERNEL);
> + if (free) {
> + free->phys = phys;
> + free->size = size;
> +
> + dev_dbg(ctx->dev, "Freed %08x[%08x r(%08x)], new.\n", phys,
> + size, req_size);
> +
> + if (phys < min_free)
> + list_add(&free->list, &ctx->vga_blks_free);
> + else
> + list_add_tail(&free->list, &ctx->vga_blks_free);
> + } else {
> + dev_err(ctx->dev, "Failed to register freed block.\n");
> + }
> +
> + mutex_unlock(&ctx->list_lock);
> +}
> +
> +static ssize_t aspeed_xdma_write(struct file *file, const char __user *buf,
> + size_t len, loff_t *offset)
> +{
> + int rc;
> + struct aspeed_xdma_op op;
> + struct aspeed_xdma_client *client = file->private_data;
> + struct aspeed_xdma *ctx = client->ctx;
> + u32 offs = client->phys ? (client->phys - ctx->vga_phys) :
> + XDMA_CMDQ_SIZE;
> +
> + if (len != sizeof(struct aspeed_xdma_op))
> + return -EINVAL;
> +
> + rc = copy_from_user(&op, buf, len);
> + if (rc)
> + return rc;
> +
> + if (op.len > (ctx->vga_size - offs) || op.len < XDMA_BYTE_ALIGN)
> + return -EINVAL;
> +
> + if (file->f_flags & O_NONBLOCK) {
> + if (!mutex_trylock(&ctx->start_lock))
> + return -EAGAIN;
> +
> + if (test_bit(XDMA_IN_PRG, &ctx->flags)) {
> + mutex_unlock(&ctx->start_lock);
> + return -EAGAIN;
> + }
> + } else {
> + mutex_lock(&ctx->start_lock);
> +
> + rc = wait_event_interruptible(ctx->wait,
> + !test_bit(XDMA_IN_PRG,
> + &ctx->flags));
> + if (rc) {
> + mutex_unlock(&ctx->start_lock);
> + return -EINTR;
> + }
> + }
> +
> + ctx->current_client = client;
> + set_bit(XDMA_IN_PRG, &client->flags);
> +
> + aspeed_xdma_start(ctx, &op, ctx->vga_phys + offs);
> +
> + mutex_unlock(&ctx->start_lock);
> +
> + if (!(file->f_flags & O_NONBLOCK)) {
> + rc = wait_event_interruptible(ctx->wait,
> + !test_bit(XDMA_IN_PRG,
> + &ctx->flags));
> + if (rc)
> + return -EINTR;
> + }
> +
> + return len;
> +}
> +
> +static __poll_t aspeed_xdma_poll(struct file *file,
> + struct poll_table_struct *wait)
> +{
> + __poll_t mask = 0;
> + __poll_t req = poll_requested_events(wait);
> + struct aspeed_xdma_client *client = file->private_data;
> + struct aspeed_xdma *ctx = client->ctx;
> +
> + if (req & (EPOLLIN | EPOLLRDNORM)) {
> + if (test_bit(XDMA_IN_PRG, &client->flags))
> + poll_wait(file, &ctx->wait, wait);
> +
> + if (!test_bit(XDMA_IN_PRG, &client->flags))
> + mask |= EPOLLIN | EPOLLRDNORM;
> + }
> +
> + if (req & (EPOLLOUT | EPOLLWRNORM)) {
> + if (test_bit(XDMA_IN_PRG, &ctx->flags))
> + poll_wait(file, &ctx->wait, wait);
> +
> + if (!test_bit(XDMA_IN_PRG, &ctx->flags))
> + mask |= EPOLLOUT | EPOLLWRNORM;
> + }
> +
> + return mask;
> +}
> +
> +static void aspeed_xdma_vma_close(struct vm_area_struct *vma)
> +{
> + struct aspeed_xdma_client *client = vma->vm_private_data;
> +
> + aspeed_xdma_free_vga_blk(client->ctx, client->phys, client->size);
> +
> + client->phys = 0;
> + client->size = 0;
> +}
> +
> +static const struct vm_operations_struct aspeed_xdma_vm_ops = {
> + .close = aspeed_xdma_vma_close,
> +};
> +
> +static int aspeed_xdma_mmap(struct file *file, struct vm_area_struct *vma)
> +{
> + int rc;
> + struct aspeed_xdma_client *client = file->private_data;
> + struct aspeed_xdma *ctx = client->ctx;
> +
> + /* restrict file to one mapping */
> + if (client->size)
> + return -ENOMEM;
> +
> + client->size = vma->vm_end - vma->vm_start;
> + client->phys = aspeed_xdma_alloc_vga_blk(ctx, client->size);
> + if (!client->phys) {
> + client->size = 0;
> + return -ENOMEM;
> + }
> +
> + vma->vm_pgoff = (client->phys - ctx->vga_phys) >> PAGE_SHIFT;
> + vma->vm_ops = &aspeed_xdma_vm_ops;
> + vma->vm_private_data = client;
> +
> + rc = dma_mmap_coherent(ctx->dev, vma, ctx->vga_virt, ctx->vga_dma,
> + ctx->vga_size);
> + if (rc) {
> + aspeed_xdma_free_vga_blk(ctx, client->phys, client->size);
> +
> + client->phys = 0;
> + client->size = 0;
> + return rc;
> + }
> +
> + dev_dbg(ctx->dev, "mmap: v[%08lx] to p[%08x], s[%08x]\n",
> + vma->vm_start, client->phys, client->size);
> +
> + return 0;
> +}
> +
> +static int aspeed_xdma_open(struct inode *inode, struct file *file)
> +{
> + struct miscdevice *misc = file->private_data;
> + struct aspeed_xdma *ctx = container_of(misc, struct aspeed_xdma, misc);
> + struct aspeed_xdma_client *client = kzalloc(sizeof(*client),
> + GFP_KERNEL);
> +
> + if (!client)
> + return -ENOMEM;
> +
> + client->ctx = ctx;
> + file->private_data = client;
> + return 0;
> +}
> +
> +static int aspeed_xdma_release(struct inode *inode, struct file *file)
> +{
> + struct aspeed_xdma_client *client = file->private_data;
> +
> + if (client->ctx->current_client == client)
> + client->ctx->current_client = NULL;
> +
> + kfree(client);
> + return 0;
> +}
> +
> +static const struct file_operations aspeed_xdma_fops = {
> + .owner = THIS_MODULE,
> + .write = aspeed_xdma_write,
> + .poll = aspeed_xdma_poll,
> + .mmap = aspeed_xdma_mmap,
> + .open = aspeed_xdma_open,
> + .release = aspeed_xdma_release,
> +};
> +
> static int aspeed_xdma_init_mem(struct aspeed_xdma *ctx)
> {
> int rc;
> @@ -382,12 +647,26 @@ static int aspeed_xdma_init_mem(struct aspeed_xdma *ctx)
> return -ENOMEM;
> }
>
> + aspeed_xdma_free_vga_blk(ctx, ctx->vga_phys, ctx->vga_size);
> + aspeed_xdma_alloc_vga_blk(ctx, XDMA_CMDQ_SIZE);
> +
> dev_dbg(ctx->dev, "VGA mapped at phys[%08x], size[%08x].\n",
> ctx->vga_phys, ctx->vga_size);
>
> return 0;
> }
>
> +static void aspeed_xdma_free_vga_blks(struct aspeed_xdma *ctx)
> +{
> + struct aspeed_xdma_vga_blk *free;
> + struct aspeed_xdma_vga_blk *tmp;
> +
> + list_for_each_entry_safe(free, tmp, &ctx->vga_blks_free, list) {
> + list_del(&free->list);
> + kfree(free);
> + }
> +}
> +
> static int aspeed_xdma_probe(struct platform_device *pdev)
> {
> int irq;
> @@ -402,6 +681,9 @@ static int aspeed_xdma_probe(struct platform_device *pdev)
> ctx->dev = dev;
> platform_set_drvdata(pdev, ctx);
> init_waitqueue_head(&ctx->wait);
> + mutex_init(&ctx->list_lock);
> + mutex_init(&ctx->start_lock);
> + INIT_LIST_HEAD(&ctx->vga_blks_free);
>
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> ctx->base = devm_ioremap_resource(dev, res);
> @@ -447,6 +729,22 @@ static int aspeed_xdma_probe(struct platform_device *pdev)
>
> aspeed_xdma_init_eng(ctx);
>
> + ctx->misc.minor = MISC_DYNAMIC_MINOR;
> + ctx->misc.fops = &aspeed_xdma_fops;
> + ctx->misc.name = "xdma";
> + ctx->misc.parent = dev;
> + rc = misc_register(&ctx->misc);
> + if (rc) {
> + dev_err(dev, "Unable to register xdma miscdevice\n");
> +
> + aspeed_xdma_free_vga_blks(ctx);
> + dma_free_coherent(dev, ctx->vga_size, ctx->vga_virt,
> + ctx->vga_dma);
> + dma_release_declared_memory(dev);
> + reset_control_assert(ctx->reset);
> + return rc;
> + }
> +
> return 0;
> }
>
> @@ -454,6 +752,9 @@ static int aspeed_xdma_remove(struct platform_device *pdev)
> {
> struct aspeed_xdma *ctx = platform_get_drvdata(pdev);
>
> + misc_deregister(&ctx->misc);
> +
> + aspeed_xdma_free_vga_blks(ctx);
> dma_free_coherent(ctx->dev, ctx->vga_size, ctx->vga_virt,
> ctx->vga_dma);
> dma_release_declared_memory(ctx->dev);
> --
> 1.8.3.1
>
>
^ permalink raw reply
* [PATCH v2 5/7] drivers/soc: xdma: Add debugfs entries
From: Arnd Bergmann @ 2019-05-21 11:58 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <1558383565-11821-6-git-send-email-eajames@linux.ibm.com>
On Mon, May 20, 2019 at 10:19 PM Eddie James <eajames@linux.ibm.com> wrote:
> struct aspeed_xdma_client {
> @@ -656,6 +662,92 @@ static int aspeed_xdma_init_mem(struct aspeed_xdma *ctx)
> return 0;
> }
>
> +#if IS_ENABLED(CONFIG_DEBUG_FS)
> +static ssize_t aspeed_xdma_debugfs_vga_read(struct file *file,
> + char __user *buf, size_t len,
> + loff_t *offset)
> +{
> + int rc;
I think it would be more readable to move the IS_ENABLED()
check into the function and do
if (!IS_ENABLED(CONFIG_DEBUG_FS))
return;
in the init_debugfs() function.
> + struct inode *inode = file_inode(file);
> + struct aspeed_xdma *ctx = inode->i_private;
> + void __iomem *vga = ioremap(ctx->vga_phys, ctx->vga_size);
> + loff_t offs = *offset;
> + void *tmp;
> +
> + if (!vga)
> + return -ENOMEM;
> +
> + if (len + offs > ctx->vga_size) {
> + iounmap(vga);
> + return -EINVAL;
> + }
The usual read() behavior is to use truncate the
read at the maximum size, rather than return an
error for an access beyond the end of file.
> +
> + tmp = kzalloc(len, GFP_KERNEL);
> + if (!tmp) {
> + iounmap(vga);
> + return -ENOMEM;
> + }
Use 'goto out;' to consolidate the unmap/free here?
> +static void aspeed_xdma_init_debugfs(struct aspeed_xdma *ctx)
> +{
> + ctx->debugfs_dir = debugfs_create_dir(DEVICE_NAME, NULL);
> + if (IS_ERR_OR_NULL(ctx->debugfs_dir)) {
debugfs_create_dir() never returns NULL.
Usually if you have to use IS_ERR_OR_NULL() in your code, that
is a bug, or a very badly defined interface.
Arnd
^ permalink raw reply
* [PATCH v2 2/7] drivers/soc: Add Aspeed XDMA Engine Driver
From: Arnd Bergmann @ 2019-05-21 12:02 UTC (permalink / raw)
To: linux-aspeed
In-Reply-To: <1558383565-11821-3-git-send-email-eajames@linux.ibm.com>
On Mon, May 20, 2019 at 10:19 PM Eddie James <eajames@linux.ibm.com> wrote:
> diff --git a/include/uapi/linux/aspeed-xdma.h b/include/uapi/linux/aspeed-xdma.h
> new file mode 100644
> index 0000000..2a4bd13
> --- /dev/null
> +++ b/include/uapi/linux/aspeed-xdma.h
> @@ -0,0 +1,26 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +/* Copyright IBM Corp 2019 */
> +
> +#ifndef _UAPI_LINUX_ASPEED_XDMA_H_
> +#define _UAPI_LINUX_ASPEED_XDMA_H_
> +
> +#include <linux/types.h>
> +
> +/*
> + * aspeed_xdma_op
> + *
> + * upstream: boolean indicating the direction of the DMA operation; upstream
> + * means a transfer from the BMC to the host
> + *
> + * host_addr: the DMA address on the host side, typically configured by PCI
> + * subsystem
> + *
> + * len: the size of the transfer in bytes; it should be a multiple of 16 bytes
> + */
> +struct aspeed_xdma_op {
> + __u32 upstream;
> + __u64 host_addr;
> + __u32 len;
> +};
> +
> +#endif /* _UAPI_LINUX_ASPEED_XDMA_H_ */
If this is a user space interface, please remove the holes in the
data structure.
I don't see how this is actually used in this patch, maybe you meant
the definition to be part of another patch?
Arnd
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox