Skip to contentSkip to conversation

ethosu: Add Arm Ethos-U driver

PATCH NAK Alison Wang 5 participants 25 messages Jun 16, 2023 – Jul 6, 2023

lore
Share & tools
lore
#0 lore raw

cover ethosu: Add Arm Ethos-U driver

This series contains Arm's NPU Ethos-U driver for NXP i.MX93 platform.

Ethos-U Linux driver is to provide an example of how a rich operating system like Linux can dispatch inferences to an Arm Cortex-M subsystem, consisting of an Arm Cortex-M and an Arm Ethos-U NPU.

----------------------------------------------------------------
Alison Wang (8):
ethosu: Add Arm Ethos-U driver
ethosu: Use RPMsg messaging protocol based on i.MX Rpmsg implementation
ethosu: Add inference type option for model and op
ethosu: Add suspend/resume power management
ethosu: Use ids for identifying messages sent to Ethos-U firmware
ethosu: Add core message about network info
ethosu: Add core message about inference cancellation
ethosu: Add rwlock when alloc and remove msg id

 drivers/firmware/Kconfig                          |   1 +
 drivers/firmware/Makefile                         |   1 +
 drivers/firmware/ethosu/Kconfig                   |  24 ++++
 drivers/firmware/ethosu/Makefile                  |  31 +++++
 drivers/firmware/ethosu/ethosu_buffer.c           | 319 +++++++++++++++++++++++++++++++++++++++++++
 drivers/firmware/ethosu/ethosu_buffer.h           | 106 +++++++++++++++
 drivers/firmware/ethosu/ethosu_cancel_inference.c | 185 +++++++++++++++++++++++++
 drivers/firmware/ethosu/ethosu_cancel_inference.h |  55 ++++++++
 drivers/firmware/ethosu/ethosu_capabilities.c     | 157 ++++++++++++++++++++++
 drivers/firmware/ethosu/ethosu_capabilities.h     |  47 +++++++
 drivers/firmware/ethosu/ethosu_core_interface.h   | 276 ++++++++++++++++++++++++++++++++++++++
 drivers/firmware/ethosu/ethosu_device.c           | 404 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/firmware/ethosu/ethosu_device.h           |  81 +++++++++++
 drivers/firmware/ethosu/ethosu_driver.c           | 201 +++++++++++++++++++++++++++
 drivers/firmware/ethosu/ethosu_inference.c        | 529 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/firmware/ethosu/ethosu_inference.h        | 125 +++++++++++++++++
 drivers/firmware/ethosu/ethosu_network.c          | 229 +++++++++++++++++++++++++++++++
 drivers/firmware/ethosu/ethosu_network.h          |  84 ++++++++++++
 drivers/firmware/ethosu/ethosu_network_info.c     | 184 +++++++++++++++++++++++++
 drivers/firmware/ethosu/ethosu_network_info.h     |  56 ++++++++
 drivers/firmware/ethosu/ethosu_rpmsg.c            | 414 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/firmware/ethosu/ethosu_rpmsg.h            | 155 +++++++++++++++++++++
 drivers/firmware/ethosu/uapi/ethosu.h             | 285 +++++++++++++++++++++++++++++++++++++++
 23 files changed, 3949 insertions(+)
 create mode 100644 drivers/firmware/ethosu/Kconfig
 create mode 100644 drivers/firmware/ethosu/Makefile
 create mode 100644 drivers/firmware/ethosu/ethosu_buffer.c
 create mode 100644 drivers/firmware/ethosu/ethosu_buffer.h
 create mode 100644 drivers/firmware/ethosu/ethosu_cancel_inference.c
 create mode 100644 drivers/firmware/ethosu/ethosu_cancel_inference.h
 create mode 100644 drivers/firmware/ethosu/ethosu_capabilities.c
 create mode 100644 drivers/firmware/ethosu/ethosu_capabilities.h
 create mode 100644 drivers/firmware/ethosu/ethosu_core_interface.h
 create mode 100644 drivers/firmware/ethosu/ethosu_device.c
 create mode 100644 drivers/firmware/ethosu/ethosu_device.h
 create mode 100644 drivers/firmware/ethosu/ethosu_driver.c
 create mode 100644 drivers/firmware/ethosu/ethosu_inference.c
 create mode 100644 drivers/firmware/ethosu/ethosu_inference.h
 create mode 100644 drivers/firmware/ethosu/ethosu_network.c
 create mode 100644 drivers/firmware/ethosu/ethosu_network.h
 create mode 100644 drivers/firmware/ethosu/ethosu_network_info.c
 create mode 100644 drivers/firmware/ethosu/ethosu_network_info.h
 create mode 100644 drivers/firmware/ethosu/ethosu_rpmsg.c
 create mode 100644 drivers/firmware/ethosu/ethosu_rpmsg.h
 create mode 100644 drivers/firmware/ethosu/uapi/ethosu.h

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#1 lore raw

PATCH 1/8 ethosu: Add Arm Ethos-U driver

Ethos-U Linux driver is to provide an example of how a rich operating system like Linux can dispatch inferences to an Arm Cortex-M subsystem, consisting of an Arm Cortex-M and an Arm Ethos-U NPU.

Tag: 22.02

---
 drivers/firmware/Kconfig                      |   1 +
 drivers/firmware/Makefile                     |   1 +
 drivers/firmware/ethosu/Kconfig               |  24 +
 drivers/firmware/ethosu/Makefile              |  28 ++
 drivers/firmware/ethosu/ethosu_buffer.c       | 312 ++++++++++++
 drivers/firmware/ethosu/ethosu_buffer.h       | 106 ++++
 .../firmware/ethosu/ethosu_core_interface.h   | 183 +++++++
 drivers/firmware/ethosu/ethosu_device.c       | 474 ++++++++++++++++++
 drivers/firmware/ethosu/ethosu_device.h       |  88 ++++
 drivers/firmware/ethosu/ethosu_driver.c       | 191 +++++++
 drivers/firmware/ethosu/ethosu_inference.c    | 417 +++++++++++++++
 drivers/firmware/ethosu/ethosu_inference.h    | 120 +++++
 drivers/firmware/ethosu/ethosu_mailbox.c      | 377 ++++++++++++++
 drivers/firmware/ethosu/ethosu_mailbox.h      | 140 ++++++
 drivers/firmware/ethosu/ethosu_network.c      | 201 ++++++++
 drivers/firmware/ethosu/ethosu_network.h      |  81 +++
 drivers/firmware/ethosu/uapi/ethosu.h         | 207 ++++++++
 17 files changed, 2951 insertions(+)
 create mode 100644 drivers/firmware/ethosu/Kconfig
 create mode 100644 drivers/firmware/ethosu/Makefile
 create mode 100644 drivers/firmware/ethosu/ethosu_buffer.c
 create mode 100644 drivers/firmware/ethosu/ethosu_buffer.h
 create mode 100644 drivers/firmware/ethosu/ethosu_core_interface.h
 create mode 100644 drivers/firmware/ethosu/ethosu_device.c
 create mode 100644 drivers/firmware/ethosu/ethosu_device.h
 create mode 100644 drivers/firmware/ethosu/ethosu_driver.c
 create mode 100644 drivers/firmware/ethosu/ethosu_inference.c
 create mode 100644 drivers/firmware/ethosu/ethosu_inference.h
 create mode 100644 drivers/firmware/ethosu/ethosu_mailbox.c
 create mode 100644 drivers/firmware/ethosu/ethosu_mailbox.h
 create mode 100644 drivers/firmware/ethosu/ethosu_network.c
 create mode 100644 drivers/firmware/ethosu/ethosu_network.h
 create mode 100644 drivers/firmware/ethosu/uapi/ethosu.h
drivers/firmware/Kconfig +1 -0
index b59e3041fd62..bbad6dc81e7b 100644
@@ -308,6 +308,7 @@ source "drivers/firmware/broadcom/Kconfig"
 source "drivers/firmware/cirrus/Kconfig"
 source "drivers/firmware/google/Kconfig"
 source "drivers/firmware/efi/Kconfig"
+source "drivers/firmware/ethosu/Kconfig"
 source "drivers/firmware/imx/Kconfig"
 source "drivers/firmware/meson/Kconfig"
 source "drivers/firmware/psci/Kconfig"
drivers/firmware/Makefile +1 -0
index 28fcddcd688f..6c597a78daa7 100644
@@ -33,6 +33,7 @@ obj-y				+= cirrus/
 obj-y				+= meson/
 obj-$(CONFIG_GOOGLE_FIRMWARE)	+= google/
 obj-y				+= efi/
+obj-$(CONFIG_ETHOSU)		+= ethosu/
 obj-y				+= imx/
 obj-y				+= psci/
 obj-y				+= smccc/
drivers/firmware/ethosu/Kconfig new file +24 -0
new file mode 100644
index 000000000000..ce837f45f8e5
@@ -0,0 +1,24 @@
+#
+# (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
+#
+# This program is free software and is provided to you under the terms of the
+# GNU General Public License version 2 as published by the Free Software
+# Foundation, and any use by you of this program is subject to the terms
+# of such GNU licence.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, you can access it online at
+# http://www.gnu.org/licenses/gpl-2.0.html.
+#
+# SPDX-License-Identifier: GPL-2.0-only
+#
+
+config ETHOSU
+    tristate "Arm Ethos-U NPU support"
+    help
+      Arm Ethos-U NPU driver.
drivers/firmware/ethosu/Makefile new file +28 -0
new file mode 100644
index 000000000000..933efee1b22f
@@ -0,0 +1,28 @@
+#
+# (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
+#
+# This program is free software and is provided to you under the terms of the
+# GNU General Public License version 2 as published by the Free Software
+# Foundation, and any use by you of this program is subject to the terms
+# of such GNU licence.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, you can access it online at
+# http://www.gnu.org/licenses/gpl-2.0.html.
+#
+# SPDX-License-Identifier: GPL-2.0-only
+#
+
+obj-$(CONFIG_ETHOSU) = ethosu.o
+
+ethosu-objs := ethosu_driver.o \
+               ethosu_buffer.o \
+               ethosu_device.o \
+               ethosu_inference.o \
+               ethosu_mailbox.o \
+               ethosu_network.o
drivers/firmware/ethosu/ethosu_buffer.c new file +312 -0

312 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_buffer.h new file +106 -0

106 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_core_interface.h new file +183 -0

183 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_device.c new file +474 -0

474 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_device.h new file +88 -0

88 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_driver.c new file +191 -0

191 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_inference.c new file +417 -0

417 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_inference.h new file +120 -0

120 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_mailbox.c new file +377 -0

377 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_mailbox.h new file +140 -0

140 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_network.c new file +201 -0

201 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_network.h new file +81 -0

81 lines not on this page · raw message

drivers/firmware/ethosu/uapi/ethosu.h new file +207 -0

207 lines not on this page · raw message

Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#2 lore raw
Quoted 6 lines · Alison Wang

Ethos-U Linux driver is to provide an example of how a rich operating system like Linux can dispatch inferences to an Arm Cortex-M subsystem, consisting of an Arm Cortex-M and an Arm Ethos-U NPU.

Tag: 22.02

What does "Tag:" mean?

Quoted 8 lines

If this many people signed off on this, it better be correct :)

drivers/firmware/ethosu/Kconfig line 2

Quoted 5 lines
drivers/firmware/ethosu/Kconfig new file +2 -0
@@ -0,0 +1,24 @@
+#
+# (C) COPYRIGHT 2020 ARM Limited. All rights reserved.

It's not 2020 anymore.

Quoted 12 lines
drivers/firmware/ethosu/Kconfig new file +12 -0
+#
+# This program is free software and is provided to you under the terms of the
+# GNU General Public License version 2 as published by the Free Software
+# Foundation, and any use by you of this program is subject to the terms
+# of such GNU licence.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License

drivers/firmware/ethosu/Kconfig line 24

Quoted 10 lines
drivers/firmware/ethosu/Kconfig new file +10 -0
+# along with this program; if not, you can access it online at
+# http://www.gnu.org/licenses/gpl-2.0.html.
+#
+# SPDX-License-Identifier: GPL-2.0-only
+#
+
+config ETHOSU
+    tristate "Arm Ethos-U NPU support"
+    help
+      Arm Ethos-U NPU driver.

{sigh}

With all of those people, NO ONE ran checkpatch.pl on the thing?

I'm stopping here, please go do that, fix up the obvious issues it tells you about (hint, no SPDX line and drop the huge license "boiler plate" texts)

And also provide a REAL configuration help text, 4 words for this is just not acceptable, what would you do if you were asked to review this?

thanks,

greg k-h

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#3 lore raw
Quoted 4 lines · Alison Wang

Ethos-U Linux driver is to provide an example of how a rich operating system like Linux can dispatch inferences to an Arm Cortex-M subsystem, consisting of an Arm Cortex-M and an Arm Ethos-U NPU.

Quoted 9 lines

Link:
https://git/.
mlplatform.org%2Fml%2Fethos-u%2Fethos-u-linux-driver-stack.git&data=05 %7C01%7Calison.wang%40nxp.com%7C4b1681cd19b9450e832208db6e32709b%7C686 ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638224935139578328%7CUnknown%7 CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXV CI6Mn0%3D%7C3000%7C%7C%7C&sdata=jwhvw5i1Q2M%2FOLID8TsOOnaI9LqD6y%2BMnn jzdvdCXcw%3D&reserved=0
Tag: 22.02

What does "Tag:" mean?

Quoted 8 lines

If this many people signed off on this, it better be correct :)
[Alison Wang] The source codes of this patch come from the kernel folder of https://git.mlplatform.org/ml/ethos-u/ethos-u-linux-driver-stack.git, the detailed tag is 22.02. So the source codes of this patch are written by Arm guys. The above people are all the authors. I list them all to avoid any missing.

drivers/firmware/ethosu/Kconfig line 2

Quoted 5 lines
drivers/firmware/ethosu/Kconfig new file +2 -0
@@ -0,0 +1,24 @@
+#
+# (C) COPYRIGHT 2020 ARM Limited. All rights reserved.

It's not 2020 anymore.

Quoted 11 lines
drivers/firmware/ethosu/Kconfig new file +11 -0
+#
+# This program is free software and is provided to you under the
+terms of the # GNU General Public License version 2 as published by
+the Free Software # Foundation, and any use by you of this program is
+subject to the terms # of such GNU licence.
+#
+# This program is distributed in the hope that it will be useful, #
+but WITHOUT ANY WARRANTY; without even the implied warranty of #
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU
+General Public License for more details.
+#

drivers/firmware/ethosu/Kconfig line 23

Quoted 10 lines
drivers/firmware/ethosu/Kconfig new file +10 -0
+# You should have received a copy of the GNU General Public License #
+along with this program; if not, you can access it online at #
+http://www.gnu.org/licenses/gpl-2.0.html.
+#
+# SPDX-License-Identifier: GPL-2.0-only #
+
+config ETHOSU
+    tristate "Arm Ethos-U NPU support"
+    help
+      Arm Ethos-U NPU driver.

{sigh}

With all of those people, NO ONE ran checkpatch.pl on the thing?

I'm stopping here, please go do that, fix up the obvious issues it tells you about (hint, no SPDX line and drop the huge license "boiler plate" texts)

And also provide a REAL configuration help text, 4 words for this is just not acceptable, what would you do if you were asked to review this? [Alison Wang] So sorry, I didn't do any change for the issues you mentioned above for this patch.
My previous idea is the first patch comes from Arm guys and the other patches are written by NXP guys. It seems this is not a good idea. I will change this way in the next version.

Thanks a lot for your review.

thanks,

greg k-h

#4 lore raw
Quoted 26 lines · Alison Wang
Quoted 4 lines · Alison Wang

Ethos-U Linux driver is to provide an example of how a rich operating system like Linux can dispatch inferences to an Arm Cortex-M subsystem, consisting of an Arm Cortex-M and an Arm Ethos-U NPU.

Quoted 9 lines

Link:
https://git/.
mlplatform.org%2Fml%2Fethos-u%2Fethos-u-linux-driver-stack.git&data=05 %7C01%7Calison.wang%40nxp.com%7C4b1681cd19b9450e832208db6e32709b%7C686 ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638224935139578328%7CUnknown%7 CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXV CI6Mn0%3D%7C3000%7C%7C%7C&sdata=jwhvw5i1Q2M%2FOLID8TsOOnaI9LqD6y%2BMnn jzdvdCXcw%3D&reserved=0
Tag: 22.02

What does "Tag:" mean?

Quoted 8 lines
Quoted 3 lines

If this many people signed off on this, it better be correct :)
[Alison Wang] The source codes of this patch come from the kernel folder of https://git.mlplatform.org/ml/ethos-u/ethos-u-linux-driver-stack.git, the detailed tag is 22.02. So the source codes of this patch are written by Arm guys. The above people are all the authors. I list them all to avoid any missing.

Hi Alison

Maybe you should spend a few days reading email from others on the list. Notice that netiquette style is used. Lines are wrapped to around 80. Quoting is done using > etc. You are expected to follow these guidelines.

Can i suggest you find somebody in NXP to be your mentor and help you get up to speed with how mainline works. There are plenty of very good mainline developers in the Ethernet group for example.

Andrew

#5 lore raw
In reply to Greg KH
Quoted 35 lines · Alison Wang
Quoted 7 lines

Ethos-U Linux driver is to provide an example of how a rich operating system like Linux can dispatch inferences to an Arm Cortex-M subsystem, consisting of an Arm Cortex-M and an Arm Ethos-U NPU.

Link:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.

mlplatform.org%2Fml%2Fethos-u%2Fethos-u-linux-driver-stack.git&data=05

Quoted 1 line

%7C01%7Calison.wang%40nxp.com%7C4b1681cd19b9450e832208db6e32

709b%7C686

Quoted 1 line

ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638224935139578328%7C Unknown%7

Quoted 1 line

CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwi LCJXV

Quoted 1 line

CI6Mn0%3D%7C3000%7C%7C%7C&sdata=jwhvw5i1Q2M%2FOLID8TsOOnaI 9LqD6y%2BMnn

Quoted 2 lines

jzdvdCXcw%3D&reserved=0
Tag: 22.02

What does "Tag:" mean?

Quoted 8 lines
Quoted 1 line

If this many people signed off on this, it better be correct :)

Our patches are derived from the ethos-u-linux-driver-stack in mlplatform (https://git.mlplatform.org/ml/ethos-u/ethos-u-linux-driver-stack.git).
As a gesture of respect to the original authors, we initially included the ARM authors' names on the signed-off-by line.
However, after discussions with ARM, we would like to clarify Arm has not signed off on this patchset and therefore we will remove their signed-off-by tags on the next update.

Thanks.
Alison

#6 lore raw
In reply to Alison Wang

drivers/firmware/ethosu/ethosu_buffer.c line 141

Quoted 6 lines · Alison Wang
drivers/firmware/ethosu/ethosu_buffer.c new file +6 -0
+static int ethosu_buffer_release(struct inode *inode,
+				 struct file *file)
+{
+	struct ethosu_buffer *buf = file->private_data;
+
+	dev_info(buf->edev->dev, "Buffer release. handle=0x%pK\n", buf);

Oh, and please remove your debugging code that you have here, and all over the place in the driver. When drivers work properly, they are quiet, NOT printing out to the information log.

Are you sure that all of those people reviewed this thing?

greg k-h

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#7 lore raw

drivers/firmware/ethosu/ethosu_buffer.c line 141

Quoted 5 lines · Alison Wang
drivers/firmware/ethosu/ethosu_buffer.c new file +5 -0
+static int ethosu_buffer_release(struct inode *inode,
+                              struct file *file) {
+     struct ethosu_buffer *buf = file->private_data;
+
+     dev_info(buf->edev->dev, "Buffer release. handle=0x%pK\n", buf);

Oh, and please remove your debugging code that you have here, and all over the place in the driver. When drivers work properly, they are quiet, NOT printing out to the information log.

Are you sure that all of those people reviewed this thing?
[Alison Wang] These codes are also written by Arm guys. I changed dev_info to dev_dbg in the later patches. Ok, I will remove these code.

Thanks a lot for your review.

greg k-h

#8 lore raw
In reply to Alison Wang
kernel test robot noticed the following build warnings:

Hi Alison,

kernel test robot noticed the following build warnings:

[auto build test WARNING on soc/for-next]
[also build test WARNING on linus/master v6.4-rc6 next-20230616] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Alison-Wang/ethosu-Add-Arm-Ethos-U-driver/20230616-141036
base:   https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next
patch link:    https://lore.kernel.org/r/20230616055913.2360-2-alison.wang%40nxp.com
patch subject: [PATCH 1/8] ethosu: Add Arm Ethos-U driver
config: sparc-allyesconfig (https://download.01.org/0day-ci/archive/20230616/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 12.3.0

reproduce (this is a W=1 build):
mkdir -p ~/bin
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git remote add soc https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git
git fetch soc for-next
git checkout soc/for-next
b4 shazam https://lore.kernel.org/r/[email protected]
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=sparc olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=sparc SHELL=/bin/bash drivers/firmware/ethosu/

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from include/linux/device.h:15,
from include/linux/mailbox_client.h:11,
from drivers/firmware/ethosu/ethosu_mailbox.h:30, from drivers/firmware/ethosu/ethosu_device.h:29, from drivers/firmware/ethosu/ethosu_buffer.c:27:
drivers/firmware/ethosu/ethosu_buffer.c: In function 'ethosu_buffer_create':

>> drivers/firmware/ethosu/ethosu_buffer.c:253:18: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 8 has type 'long unsigned int' [-Wformat=]
     253 |                  "Buffer create. handle=0x%pK, capacity=%zu, cpu_addr=0x%pK, dma_addr=0x%llx, dma_addr_orig=0x%llx, phys_addr=0x%llx\n",
         |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:110:30: note: in definition of macro 'dev_printk_index_wrap'
     110 |                 _p_func(dev, fmt, ##__VA_ARGS__);                       \
         |                              ^~~
   include/linux/dev_printk.h:150:58: note: in expansion of macro 'dev_fmt'
     150 |         dev_printk_index_wrap(_dev_info, KERN_INFO, dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                                                          ^~~~~~~
   drivers/firmware/ethosu/ethosu_buffer.c:252:9: note: in expansion of macro 'dev_info'
     252 |         dev_info(buf->edev->dev,
         |         ^~~~~~~~
   drivers/firmware/ethosu/ethosu_buffer.c:253:132: note: format string is defined here
     253 |                  "Buffer create. handle=0x%pK, capacity=%zu, cpu_addr=0x%pK, dma_addr=0x%llx, dma_addr_orig=0x%llx, phys_addr=0x%llx\n",
         |                                                                                                                                 ~~~^
         |                                                                                                                                    |
         |                                                                                                                                    long long unsigned int
         |                                                                                                                                 %lx

vim +253 drivers/firmware/ethosu/ethosu_buffer.c

218
219 int ethosu_buffer_create(struct ethosu_device *edev,
220 size_t capacity)
221 {
222 struct ethosu_buffer *buf;
223 int ret = -ENOMEM;
224
225 buf = devm_kzalloc(edev->dev, sizeof(*buf), GFP_KERNEL);
226 if (!buf)
227 return -ENOMEM;
228
229 buf->edev = edev;
230 buf->capacity = capacity;
231 buf->offset = 0;
232 buf->size = 0;
233 kref_init(&buf->kref);
234
235 buf->cpu_addr = dma_alloc_coherent(buf->edev->dev, capacity,
236 &buf->dma_addr_orig, GFP_KERNEL);
237 if (!buf->cpu_addr)
238 goto free_buf;
239
240 buf->dma_addr = ethosu_buffer_dma_ranges(buf->edev->dev,
241 buf->dma_addr_orig,
242 buf->capacity);
243
244 ret = anon_inode_getfd("ethosu-buffer", &ethosu_buffer_fops, buf,
245 O_RDWR | O_CLOEXEC);
246 if (ret < 0)
247 goto free_dma;
248
249 buf->file = fget(ret);
250 fput(buf->file);
251
252 dev_info(buf->edev->dev,

 > 253			 "Buffer create. handle=0x%pK, capacity=%zu, cpu_addr=0x%pK, dma_addr=0x%llx, dma_addr_orig=0x%llx, phys_addr=0x%llx\n",

254 buf, capacity, buf->cpu_addr, buf->dma_addr,
255 buf->dma_addr_orig, virt_to_phys(buf->cpu_addr));
256
257 return ret;
258
259 free_dma:
260 dma_free_coherent(buf->edev->dev, buf->capacity, buf->cpu_addr,
261 buf->dma_addr_orig);
262
263 free_buf:
264 devm_kfree(buf->edev->dev, buf);
265
266 return ret;
267 }
268

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#9 lore raw
In reply to Alison Wang

On 2023-06-16 06:59, Alison Wang wrote:
[...]

Quoted 5 lines

+/*
+ * The 'dma-ranges' device tree property for shared dma memory does not seem
+ * to be fully supported for coherent memory. Therefor we apply the DMA range
+ * offset ourselves.
+ */

NAK - if there's a bug in the core code, that wants to be fixed, not bodged around by individual drivers. However from the look of the code here, the driver appears to be misusing the property in an incorrect manner anyway. But of course there's no devicetree binding here, so we don't even really know what it thinks it expects... :/

I'd also agree with Greg that this is definitely not a firmware driver. IIUC it's not so much a driver for the Ethos-U NPU itself, but one for this particular subsystem configuration where requests to the NPU are proxied through a dedicated Cortex-M core. As such, if you don't think it belongs in drivers/accel, then drivers/remoteproc might be the next most relevant choice. Also, is there a more specific name for this particular subsystem, or is there a general expectation that this is the only way an Ethos-U should ever be exposed to Linux, and it should never have direct access to the hardware (as it would with an Ethos-N), and thus there's no chance of ending up with multiple different "Ethos-U" drivers in future?

Thanks,
Robin.

Quoted 49 lines
drivers/firmware/ethosu/ethosu_buffer.c new file +49 -0
+static dma_addr_t ethosu_buffer_dma_ranges(struct device *dev,
+					   dma_addr_t dma_addr,
+					   size_t dma_buf_size)
+{
+	struct device_node *node = dev->of_node;
+	const __be32 *ranges;
+	int len;
+	int naddr;
+	int nsize;
+	int inc;
+	int i;
+
+	if (!node)
+		return dma_addr;
+
+	/* Get the #address-cells and #size-cells properties */
+	naddr = of_n_addr_cells(node);
+	nsize = of_n_size_cells(node);
+
+	/* Read the 'dma-ranges' property */
+	ranges = of_get_property(node, "dma-ranges", &len);
+	if (!ranges || len <= 0)
+		return dma_addr;
+
+	dev_dbg(dev, "ranges=%p, len=%d, naddr=%d, nsize=%d\n",
+		ranges, len, naddr, nsize);
+
+	len /= sizeof(*ranges);
+	inc = naddr + naddr + nsize;
+
+	for (i = 0; (i + inc) <= len; i += inc) {
+		dma_addr_t daddr;
+		dma_addr_t paddr;
+		dma_addr_t size;
+
+		daddr = of_read_number(&ranges[i], naddr);
+		paddr = of_read_number(&ranges[i + naddr], naddr);
+		size = of_read_number(&ranges[i + naddr + naddr], nsize);
+
+		dev_dbg(dev, "daddr=0x%llx, paddr=0x%llx, size=0x%llx\n",
+			daddr, paddr, size);
+
+		if (dma_addr >= paddr &&
+		    (dma_addr + dma_buf_size) < (paddr + size))
+			return dma_addr + daddr - paddr;
+	}
+
+	return dma_addr;
+}
#10 lore raw
In reply to Alison Wang
kernel test robot noticed the following build warnings:

Hi Alison,

kernel test robot noticed the following build warnings:

[auto build test WARNING on soc/for-next]
[also build test WARNING on linus/master v6.4-rc6 next-20230616] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Alison-Wang/ethosu-Add-Arm-Ethos-U-driver/20230616-141036
base:   https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next
patch link:    https://lore.kernel.org/r/20230616055913.2360-2-alison.wang%40nxp.com
patch subject: [PATCH 1/8] ethosu: Add Arm Ethos-U driver
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20230617/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce: (https://download.01.org/0day-ci/archive/20230617/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from include/linux/printk.h:564,

                    from include/linux/kernel.h:30,
                    from arch/x86/include/asm/percpu.h:27,
                    from arch/x86/include/asm/preempt.h:6,
                    from include/linux/preempt.h:78,
                    from include/linux/spinlock.h:56,
                    from include/linux/kref.h:16,
                    from drivers/firmware/ethosu/ethosu_buffer.h:28,
                    from drivers/firmware/ethosu/ethosu_buffer.c:25:
   drivers/firmware/ethosu/ethosu_buffer.c: In function 'ethosu_buffer_dma_ranges':
>> drivers/firmware/ethosu/ethosu_buffer.c:108:30: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 4 has type 'dma_addr_t' {aka 'unsigned int'} [-Wformat=]
     108 |                 dev_dbg(dev, "daddr=0x%llx, paddr=0x%llx, size=0x%llx\n",
         |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:222:29: note: in definition of macro '__dynamic_func_call_cls'
     222 |                 func(&id, ##__VA_ARGS__);                       \
         |                             ^~~~~~~~~~~
   include/linux/dynamic_debug.h:248:9: note: in expansion of macro '_dynamic_func_call_cls'
     248 |         _dynamic_func_call_cls(_DPRINTK_CLASS_DFLT, fmt, func, ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:271:9: note: in expansion of macro '_dynamic_func_call'
     271 |         _dynamic_func_call(fmt, __dynamic_dev_dbg,              \
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:9: note: in expansion of macro 'dynamic_dev_dbg'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:30: note: in expansion of macro 'dev_fmt'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                              ^~~~~~~
   drivers/firmware/ethosu/ethosu_buffer.c:108:17: note: in expansion of macro 'dev_dbg'
     108 |                 dev_dbg(dev, "daddr=0x%llx, paddr=0x%llx, size=0x%llx\n",
         |                 ^~~~~~~
   drivers/firmware/ethosu/ethosu_buffer.c:108:42: note: format string is defined here
     108 |                 dev_dbg(dev, "daddr=0x%llx, paddr=0x%llx, size=0x%llx\n",
         |                                       ~~~^
         |                                          |
         |                                          long long unsigned int
         |                                       %x
   drivers/firmware/ethosu/ethosu_buffer.c:108:30: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 5 has type 'dma_addr_t' {aka 'unsigned int'} [-Wformat=]
     108 |                 dev_dbg(dev, "daddr=0x%llx, paddr=0x%llx, size=0x%llx\n",
         |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:222:29: note: in definition of macro '__dynamic_func_call_cls'
     222 |                 func(&id, ##__VA_ARGS__);                       \
         |                             ^~~~~~~~~~~
   include/linux/dynamic_debug.h:248:9: note: in expansion of macro '_dynamic_func_call_cls'
     248 |         _dynamic_func_call_cls(_DPRINTK_CLASS_DFLT, fmt, func, ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:271:9: note: in expansion of macro '_dynamic_func_call'
     271 |         _dynamic_func_call(fmt, __dynamic_dev_dbg,              \
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:9: note: in expansion of macro 'dynamic_dev_dbg'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:30: note: in expansion of macro 'dev_fmt'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                              ^~~~~~~
   drivers/firmware/ethosu/ethosu_buffer.c:108:17: note: in expansion of macro 'dev_dbg'
     108 |                 dev_dbg(dev, "daddr=0x%llx, paddr=0x%llx, size=0x%llx\n",
         |                 ^~~~~~~
   drivers/firmware/ethosu/ethosu_buffer.c:108:56: note: format string is defined here
     108 |                 dev_dbg(dev, "daddr=0x%llx, paddr=0x%llx, size=0x%llx\n",
         |                                                     ~~~^
         |                                                        |
         |                                                        long long unsigned int
         |                                                     %x
   drivers/firmware/ethosu/ethosu_buffer.c:108:30: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 6 has type 'dma_addr_t' {aka 'unsigned int'} [-Wformat=]
     108 |                 dev_dbg(dev, "daddr=0x%llx, paddr=0x%llx, size=0x%llx\n",
         |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:222:29: note: in definition of macro '__dynamic_func_call_cls'
     222 |                 func(&id, ##__VA_ARGS__);                       \
         |                             ^~~~~~~~~~~
   include/linux/dynamic_debug.h:248:9: note: in expansion of macro '_dynamic_func_call_cls'
     248 |         _dynamic_func_call_cls(_DPRINTK_CLASS_DFLT, fmt, func, ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:271:9: note: in expansion of macro '_dynamic_func_call'
     271 |         _dynamic_func_call(fmt, __dynamic_dev_dbg,              \
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:9: note: in expansion of macro 'dynamic_dev_dbg'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:30: note: in expansion of macro 'dev_fmt'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                              ^~~~~~~
   drivers/firmware/ethosu/ethosu_buffer.c:108:17: note: in expansion of macro 'dev_dbg'
     108 |                 dev_dbg(dev, "daddr=0x%llx, paddr=0x%llx, size=0x%llx\n",
         |                 ^~~~~~~
   drivers/firmware/ethosu/ethosu_buffer.c:108:69: note: format string is defined here
     108 |                 dev_dbg(dev, "daddr=0x%llx, paddr=0x%llx, size=0x%llx\n",
         |                                                                  ~~~^
         |                                                                     |
         |                                                                     long long unsigned int
         |                                                                  %x
   In file included from include/linux/device.h:15,
                    from include/linux/mailbox_client.h:11,
                    from drivers/firmware/ethosu/ethosu_mailbox.h:30,
                    from drivers/firmware/ethosu/ethosu_device.h:29,
                    from drivers/firmware/ethosu/ethosu_buffer.c:27:
   drivers/firmware/ethosu/ethosu_buffer.c: In function 'ethosu_buffer_create':
   drivers/firmware/ethosu/ethosu_buffer.c:253:18: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 6 has type 'dma_addr_t' {aka 'unsigned int'} [-Wformat=]
     253 |                  "Buffer create. handle=0x%pK, capacity=%zu, cpu_addr=0x%pK, dma_addr=0x%llx, dma_addr_orig=0x%llx, phys_addr=0x%llx\n",
         |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:110:30: note: in definition of macro 'dev_printk_index_wrap'
     110 |                 _p_func(dev, fmt, ##__VA_ARGS__);                       \
         |                              ^~~
   include/linux/dev_printk.h:150:58: note: in expansion of macro 'dev_fmt'
     150 |         dev_printk_index_wrap(_dev_info, KERN_INFO, dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                                                          ^~~~~~~
   drivers/firmware/ethosu/ethosu_buffer.c:252:9: note: in expansion of macro 'dev_info'
     252 |         dev_info(buf->edev->dev,
         |         ^~~~~~~~
   drivers/firmware/ethosu/ethosu_buffer.c:253:92: note: format string is defined here
     253 |                  "Buffer create. handle=0x%pK, capacity=%zu, cpu_addr=0x%pK, dma_addr=0x%llx, dma_addr_orig=0x%llx, phys_addr=0x%llx\n",
         |                                                                                         ~~~^
         |                                                                                            |
         |                                                                                            long long unsigned int
         |                                                                                         %x
   drivers/firmware/ethosu/ethosu_buffer.c:253:18: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 7 has type 'dma_addr_t' {aka 'unsigned int'} [-Wformat=]
     253 |                  "Buffer create. handle=0x%pK, capacity=%zu, cpu_addr=0x%pK, dma_addr=0x%llx, dma_addr_orig=0x%llx, phys_addr=0x%llx\n",
         |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:110:30: note: in definition of macro 'dev_printk_index_wrap'
     110 |                 _p_func(dev, fmt, ##__VA_ARGS__);                       \
         |                              ^~~
   include/linux/dev_printk.h:150:58: note: in expansion of macro 'dev_fmt'
     150 |         dev_printk_index_wrap(_dev_info, KERN_INFO, dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                                                          ^~~~~~~
   drivers/firmware/ethosu/ethosu_buffer.c:252:9: note: in expansion of macro 'dev_info'
     252 |         dev_info(buf->edev->dev,
         |         ^~~~~~~~
   drivers/firmware/ethosu/ethosu_buffer.c:253:114: note: format string is defined here
     253 |                  "Buffer create. handle=0x%pK, capacity=%zu, cpu_addr=0x%pK, dma_addr=0x%llx, dma_addr_orig=0x%llx, phys_addr=0x%llx\n",
         |                                                                                                               ~~~^
         |                                                                                                                  |
         |                                                                                                                  long long unsigned int
         |                                                                                                               %x
>> drivers/firmware/ethosu/ethosu_buffer.c:253:18: warning: format '%llx' expects argument of type 'long long unsigned int', but argument 8 has type 'phys_addr_t' {aka 'unsigned int'} [-Wformat=]
     253 |                  "Buffer create. handle=0x%pK, capacity=%zu, cpu_addr=0x%pK, dma_addr=0x%llx, dma_addr_orig=0x%llx, phys_addr=0x%llx\n",
         |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:110:30: note: in definition of macro 'dev_printk_index_wrap'
     110 |                 _p_func(dev, fmt, ##__VA_ARGS__);                       \
         |                              ^~~
   include/linux/dev_printk.h:150:58: note: in expansion of macro 'dev_fmt'
     150 |         dev_printk_index_wrap(_dev_info, KERN_INFO, dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                                                          ^~~~~~~
   drivers/firmware/ethosu/ethosu_buffer.c:252:9: note: in expansion of macro 'dev_info'
     252 |         dev_info(buf->edev->dev,
         |         ^~~~~~~~
   drivers/firmware/ethosu/ethosu_buffer.c:253:132: note: format string is defined here
     253 |                  "Buffer create. handle=0x%pK, capacity=%zu, cpu_addr=0x%pK, dma_addr=0x%llx, dma_addr_orig=0x%llx, phys_addr=0x%llx\n",
         |                                                                                                                                 ~~~^
         |                                                                                                                                    |
         |                                                                                                                                    long long unsigned int
         |                                                                                                                                 %x

vim +108 drivers/firmware/ethosu/ethosu_buffer.c

    59	
    60	/****************************************************************************
    61	 * Functions
    62	 ****************************************************************************/
    63	
    64	/*
    65	 * The 'dma-ranges' device tree property for shared dma memory does not seem
    66	 * to be fully supported for coherent memory. Therefor we apply the DMA range
    67	 * offset ourselves.
    68	 */
    69	static dma_addr_t ethosu_buffer_dma_ranges(struct device *dev,
    70						   dma_addr_t dma_addr,
    71						   size_t dma_buf_size)
    72	{
    73		struct device_node *node = dev->of_node;
    74		const __be32 *ranges;
    75		int len;
    76		int naddr;
    77		int nsize;
    78		int inc;
    79		int i;
    80	
    81		if (!node)
    82			return dma_addr;
    83	
    84		/* Get the #address-cells and #size-cells properties */
    85		naddr = of_n_addr_cells(node);
    86		nsize = of_n_size_cells(node);
    87	
    88		/* Read the 'dma-ranges' property */
    89		ranges = of_get_property(node, "dma-ranges", &len);
    90		if (!ranges || len <= 0)
    91			return dma_addr;
    92	
    93		dev_dbg(dev, "ranges=%p, len=%d, naddr=%d, nsize=%d\n",
    94			ranges, len, naddr, nsize);
    95	
    96		len /= sizeof(*ranges);
    97		inc = naddr + naddr + nsize;
    98	
    99		for (i = 0; (i + inc) <= len; i += inc) {
   100			dma_addr_t daddr;
   101			dma_addr_t paddr;
   102			dma_addr_t size;
   103	
   104			daddr = of_read_number(&ranges[i], naddr);
   105			paddr = of_read_number(&ranges[i + naddr], naddr);
   106			size = of_read_number(&ranges[i + naddr + naddr], nsize);
   107	
 > 108			dev_dbg(dev, "daddr=0x%llx, paddr=0x%llx, size=0x%llx\n",
   109				daddr, paddr, size);
   110	
   111			if (dma_addr >= paddr &&
   112			    (dma_addr + dma_buf_size) < (paddr + size))
   113				return dma_addr + daddr - paddr;
   114		}
   115	
   116		return dma_addr;
   117	}
   118	
   119	static bool ethosu_buffer_verify(struct file *file)
   120	{
   121		return file->f_op == &ethosu_buffer_fops;
   122	}
   123	
   124	static void ethosu_buffer_destroy(struct kref *kref)
   125	{
   126		struct ethosu_buffer *buf =
   127			container_of(kref, struct ethosu_buffer, kref);
   128	
   129		dev_info(buf->edev->dev, "Buffer destroy. handle=0x%pK\n", buf);
   130	
   131		dma_free_coherent(buf->edev->dev, buf->capacity, buf->cpu_addr,
   132				  buf->dma_addr_orig);
   133		devm_kfree(buf->edev->dev, buf);
   134	}
   135	
   136	static int ethosu_buffer_release(struct inode *inode,
   137					 struct file *file)
   138	{
   139		struct ethosu_buffer *buf = file->private_data;
   140	
   141		dev_info(buf->edev->dev, "Buffer release. handle=0x%pK\n", buf);
   142	
   143		ethosu_buffer_put(buf);
   144	
   145		return 0;
   146	}
   147	
   148	static int ethosu_buffer_mmap(struct file *file,
   149				      struct vm_area_struct *vma)
   150	{
   151		struct ethosu_buffer *buf = file->private_data;
   152		int ret;
   153	
   154		dev_info(buf->edev->dev, "Buffer mmap. handle=0x%pK\n", buf);
   155	
   156		ret = dma_mmap_coherent(buf->edev->dev, vma, buf->cpu_addr,
   157					buf->dma_addr_orig,
   158					buf->capacity);
   159	
   160		return ret;
   161	}
   162	
   163	static long ethosu_buffer_ioctl(struct file *file,
   164					unsigned int cmd,
   165					unsigned long arg)
   166	{
   167		struct ethosu_buffer *buf = file->private_data;
   168		void __user *udata = (void __user *)arg;
   169		int ret = -EINVAL;
   170	
   171		ret = mutex_lock_interruptible(&buf->edev->mutex);
   172		if (ret)
   173			return ret;
   174	
   175		dev_info(buf->edev->dev, "Ioctl. cmd=%u, arg=%lu\n", cmd, arg);
   176	
   177		switch (cmd) {
   178		case ETHOSU_IOCTL_BUFFER_SET: {
   179			struct ethosu_uapi_buffer uapi;
   180	
   181			if (copy_from_user(&uapi, udata, sizeof(uapi)))
   182				break;
   183	
   184			dev_info(buf->edev->dev,
   185				 "Ioctl: Buffer set. size=%u, offset=%u\n",
   186				 uapi.size, uapi.offset);
   187	
   188			ret = ethosu_buffer_resize(buf, uapi.size, uapi.offset);
   189			break;
   190		}
   191		case ETHOSU_IOCTL_BUFFER_GET: {
   192			struct ethosu_uapi_buffer uapi;
   193	
   194			uapi.size = buf->size;
   195			uapi.offset = buf->offset;
   196	
   197			dev_info(buf->edev->dev,
   198				 "Ioctl: Buffer get. size=%u, offset=%u\n",
   199				 uapi.size, uapi.offset);
   200	
   201			if (copy_to_user(udata, &uapi, sizeof(uapi)))
   202				break;
   203	
   204			ret = 0;
   205			break;
   206		}
   207		default: {
   208			dev_err(buf->edev->dev, "Invalid ioctl. cmd=%u, arg=%lu",
   209				cmd, arg);
   210			break;
   211		}
   212		}
   213	
   214		mutex_unlock(&buf->edev->mutex);
   215	
   216		return ret;
   217	}
   218	
   219	int ethosu_buffer_create(struct ethosu_device *edev,
   220				 size_t capacity)
   221	{
   222		struct ethosu_buffer *buf;
   223		int ret = -ENOMEM;
   224	
   225		buf = devm_kzalloc(edev->dev, sizeof(*buf), GFP_KERNEL);
   226		if (!buf)
   227			return -ENOMEM;
   228	
   229		buf->edev = edev;
   230		buf->capacity = capacity;
   231		buf->offset = 0;
   232		buf->size = 0;
   233		kref_init(&buf->kref);
   234	
   235		buf->cpu_addr = dma_alloc_coherent(buf->edev->dev, capacity,
   236						   &buf->dma_addr_orig, GFP_KERNEL);
   237		if (!buf->cpu_addr)
   238			goto free_buf;
   239	
   240		buf->dma_addr = ethosu_buffer_dma_ranges(buf->edev->dev,
   241							 buf->dma_addr_orig,
   242							 buf->capacity);
   243	
   244		ret = anon_inode_getfd("ethosu-buffer", &ethosu_buffer_fops, buf,
   245				       O_RDWR | O_CLOEXEC);
   246		if (ret < 0)
   247			goto free_dma;
   248	
   249		buf->file = fget(ret);
   250		fput(buf->file);
   251	
   252		dev_info(buf->edev->dev,
 > 253			 "Buffer create. handle=0x%pK, capacity=%zu, cpu_addr=0x%pK, dma_addr=0x%llx, dma_addr_orig=0x%llx, phys_addr=0x%llx\n",

254 buf, capacity, buf->cpu_addr, buf->dma_addr,
255 buf->dma_addr_orig, virt_to_phys(buf->cpu_addr));
256
257 return ret;
258
259 free_dma:
260 dma_free_coherent(buf->edev->dev, buf->capacity, buf->cpu_addr,
261 buf->dma_addr_orig);
262
263 free_buf:
264 devm_kfree(buf->edev->dev, buf);
265
266 return ret;
267 }
268

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#11 lore raw
In reply to Alison Wang
kernel test robot noticed the following build warnings:

Hi Alison,

kernel test robot noticed the following build warnings:

[auto build test WARNING on soc/for-next]
[also build test WARNING on linus/master v6.4-rc7 next-20230623] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Alison-Wang/ethosu-Add-Arm-Ethos-U-driver/20230616-141036
base:   https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next
patch link:    https://lore.kernel.org/r/20230616055913.2360-2-alison.wang%40nxp.com
patch subject: [PATCH 1/8] ethosu: Add Arm Ethos-U driver
config: mips-randconfig-s032-20230625 (https://download.01.org/0day-ci/archive/20230625/[email protected]/config)
compiler: mipsel-linux-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230625/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

>> drivers/firmware/ethosu/ethosu_inference.c:54:28: sparse: sparse: incorrect type in initializer (different base types) @@     expected restricted __poll_t ( *poll )( ... ) @@     got unsigned int ( * )( ... ) @@

drivers/firmware/ethosu/ethosu_inference.c:54:28: sparse: expected restricted __poll_t ( *poll )( ... )
drivers/firmware/ethosu/ethosu_inference.c:54:28: sparse: got unsigned int ( * )( ... )
drivers/firmware/ethosu/ethosu_inference.c:361:44: sparse: sparse: non size-preserving integer to pointer cast

vim +54 drivers/firmware/ethosu/ethosu_inference.c

    37	
    38	/****************************************************************************
    39	 * Variables
    40	 ****************************************************************************/
    41	
    42	static int ethosu_inference_release(struct inode *inode,
    43					    struct file *file);
    44	
    45	static unsigned int ethosu_inference_poll(struct file *file,
    46						  poll_table *wait);
    47	
    48	static long ethosu_inference_ioctl(struct file *file,
    49					   unsigned int cmd,
    50					   unsigned long arg);
    51	
    52	static const struct file_operations ethosu_inference_fops = {
    53		.release        = &ethosu_inference_release,
  > 54		.poll           = &ethosu_inference_poll,

55 .unlocked_ioctl = &ethosu_inference_ioctl,
56 #ifdef CONFIG_COMPAT
57 .compat_ioctl = &ethosu_inference_ioctl,
58 #endif
59 };
60

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#12 lore raw

PATCH 2/8 ethosu: Use RPMsg messaging protocol based on i.MX Rpmsg implementation

In reply to Alison Wang

RPMsg is used for the communication mechanism between Cortex-A and Cortex-M for Ethos-U driver.

---
 drivers/firmware/ethosu/Makefile           |   2 +-
 drivers/firmware/ethosu/ethosu_device.c    | 143 ++++----
 drivers/firmware/ethosu/ethosu_device.h    |   8 +-
 drivers/firmware/ethosu/ethosu_driver.c    |  23 +-
 drivers/firmware/ethosu/ethosu_inference.c |   2 +-
 drivers/firmware/ethosu/ethosu_mailbox.c   | 377 ---------------------
 drivers/firmware/ethosu/ethosu_mailbox.h   | 140 --------
 drivers/firmware/ethosu/ethosu_rpmsg.c     | 235 +++++++++++++
 drivers/firmware/ethosu/ethosu_rpmsg.h     |  73 ++++
 9 files changed, 383 insertions(+), 620 deletions(-)
 delete mode 100644 drivers/firmware/ethosu/ethosu_mailbox.c
 delete mode 100644 drivers/firmware/ethosu/ethosu_mailbox.h
 create mode 100644 drivers/firmware/ethosu/ethosu_rpmsg.c
 create mode 100644 drivers/firmware/ethosu/ethosu_rpmsg.h
drivers/firmware/ethosu/Makefile +1 -1
index 933efee1b22f..0b3fe72c9c4f 100644
@@ -24,5 +24,5 @@ ethosu-objs := ethosu_driver.o \
                ethosu_buffer.o \
                ethosu_device.o \
                ethosu_inference.o \
-               ethosu_mailbox.o \
+               ethosu_rpmsg.o \
                ethosu_network.o
drivers/firmware/ethosu/ethosu_device.c +68 -75

261 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_device.h +3 -5
index 3afdda84862d..3943c8df8f28 100644
@@ -26,7 +26,7 @@
  ****************************************************************************/
 
 #include "uapi/ethosu.h"
-#include "ethosu_mailbox.h"
+#include "ethosu_rpmsg.h"
 
 #include <linux/device.h>
 #include <linux/cdev.h>
@@ -48,7 +48,7 @@ struct ethosu_device {
 	struct                class *class;
 	dev_t                 devt;
 	struct mutex          mutex;
-	struct ethosu_mailbox mailbox;
+	struct ethosu_rpmsg   erp;
 	struct list_head      capabilities_list;
 	struct list_head      inference_list;
 };
@@ -76,9 +76,7 @@ struct ethosu_capabilities {
 int ethosu_dev_init(struct ethosu_device *edev,
 		    struct device *dev,
 		    struct class *class,
-		    dev_t devt,
-		    struct resource *in_queue,
-		    struct resource *out_queue);
+		    dev_t devt);
 
 /**
  * ethosu_dev_deinit() - Initialize the device
drivers/firmware/ethosu/ethosu_driver.c +2 -21
index 9d02431d3194..27931e9aa97c 100644
@@ -1,5 +1,6 @@
 /*
  * (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
+ * Copyright 2020-2022 NXP
  *
  * This program is free software and is provided to you under the terms of the
  * GNU General Public License version 2 as published by the Free Software
@@ -55,8 +56,6 @@ static DECLARE_BITMAP(minors, MINOR_COUNT);
 static int ethosu_pdev_probe(struct platform_device *pdev)
 {
 	struct ethosu_device *edev;
-	struct resource *in_queue_res;
-	struct resource *out_queue_res;
 	int minor;
 	int ret;
 
@@ -69,23 +68,6 @@ static int ethosu_pdev_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	}
 
-	/* Get path to TCM memory */
-	in_queue_res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
-						    "in_queue");
-	if (IS_ERR(in_queue_res)) {
-		dev_err(&pdev->dev, "Failed to get in_queue resource.\n");
-
-		return PTR_ERR(in_queue_res);
-	}
-
-	out_queue_res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
-						     "out_queue");
-	if (IS_ERR(out_queue_res)) {
-		dev_err(&pdev->dev, "Failed to get out_queue resource.\n");
-
-		return PTR_ERR(out_queue_res);
-	}
-
 	/* Allocate memory for Arm Ethos-U device */
 	edev = devm_kzalloc(&pdev->dev, sizeof(*edev), GFP_KERNEL);
 	if (!edev)
@@ -95,8 +77,7 @@ static int ethosu_pdev_probe(struct platform_device *pdev)
 
 	/* Initialize device */
 	ret = ethosu_dev_init(edev, &pdev->dev, ethosu_class,
-			      MKDEV(MAJOR(devt), minor), in_queue_res,
-			      out_queue_res);
+			      MKDEV(MAJOR(devt), minor));
 	if (ret)
 		goto free_dev;
 
drivers/firmware/ethosu/ethosu_inference.c +1 -1
index 6fde92c148a0..853947a2334e 100644
@@ -86,7 +86,7 @@ static int ethosu_inference_send(struct ethosu_inference *inf)
 
 	inf->status = ETHOSU_UAPI_STATUS_ERROR;
 
-	ret = ethosu_mailbox_inference(&inf->edev->mailbox, inf,
+	ret = ethosu_rpmsg_inference(&inf->edev->erp, inf,
 				       inf->ifm_count, inf->ifm,
 				       inf->ofm_count, inf->ofm,
 				       inf->net->buf,
drivers/firmware/ethosu/ethosu_mailbox.c deleted +0 -377

377 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_mailbox.h deleted +0 -140

140 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_rpmsg.c new file +235 -0

235 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_rpmsg.h new file +73 -0

73 lines not on this page · raw message

Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#13 lore raw

PATCH 3/8 ethosu: Add inference type option for model and op

In reply to Alison Wang

This patch adds inference type option for model and op.

---
 drivers/firmware/ethosu/ethosu_core_interface.h |  6 +++++-
 drivers/firmware/ethosu/ethosu_inference.c      | 14 +++++++++++++-
 drivers/firmware/ethosu/ethosu_inference.h      |  1 +
 drivers/firmware/ethosu/ethosu_rpmsg.c          |  4 +++-
 drivers/firmware/ethosu/ethosu_rpmsg.h          |  3 ++-
 drivers/firmware/ethosu/uapi/ethosu.h           | 11 ++++++++++-
 6 files changed, 34 insertions(+), 5 deletions(-)
drivers/firmware/ethosu/ethosu_core_interface.h +5 -1
index ef63c3b55352..b60508e4792f 100644
@@ -35,13 +35,16 @@ namespace EthosU {
 #define ETHOSU_CORE_BUFFER_MAX 16
 
 /** Maximum number of PMU counters to be returned for inference */
-#define ETHOSU_CORE_PMU_MAX 8
+#define ETHOSU_CORE_PMU_MAX 4
 
 #define ETHOSU_CORE_MSG_MAGIC 0x41457631
 #define ETHOSU_CORE_MSG_VERSION_MAJOR 0
 #define ETHOSU_CORE_MSG_VERSION_MINOR 2
 #define ETHOSU_CORE_MSG_VERSION_PATCH 0
 
+#define ETHOSU_CORE_INFERENCE_MODEL 0
+#define ETHOSU_CORE_INFERENCE_OP    1
+
 /**
  * enum ethosu_core_msg_type - Message types
  *
@@ -107,6 +110,7 @@ struct ethosu_core_inference_req {
 	struct ethosu_core_buffer network;
 	uint8_t                   pmu_event_config[ETHOSU_CORE_PMU_MAX];
 	uint32_t                  pmu_cycle_counter_enable;
+	uint32_t                  inference_type;
 };
 
 struct ethosu_core_inference_rsp {
drivers/firmware/ethosu/ethosu_inference.c +13 -1
index 853947a2334e..b5e94e19bce0 100644
@@ -92,7 +92,8 @@ static int ethosu_inference_send(struct ethosu_inference *inf)
 				       inf->net->buf,
 				       inf->pmu_event_config,
 				       ETHOSU_PMU_EVENT_MAX,
-				       inf->pmu_cycle_counter_enable);
+				       inf->pmu_cycle_counter_enable,
+				       inf->inference_type);
 	if (ret)
 		return ret;
 
@@ -233,6 +234,17 @@ int ethosu_inference_create(struct ethosu_device *edev,
 	inf = devm_kzalloc(edev->dev, sizeof(*inf), GFP_KERNEL);
 	if (!inf)
 		return -ENOMEM;
+	switch (uapi->inference_type) {
+	case ETHOSU_UAPI_INFERENCE_MODEL:
+		inf->inference_type = ETHOSU_CORE_INFERENCE_MODEL;
+		break;
+	case ETHOSU_UAPI_INFERENCE_OP:
+		inf->inference_type = ETHOSU_CORE_INFERENCE_OP;
+		break;
+	default:
+		inf->inference_type = ETHOSU_CORE_INFERENCE_MODEL;
+		break;
+	}
 
 	inf->edev = edev;
 	inf->net = net;
drivers/firmware/ethosu/ethosu_inference.h +1 -0
index 07370ca01f22..8414eadbda92 100644
@@ -74,6 +74,7 @@ struct ethosu_inference {
 	uint32_t                pmu_event_count[ETHOSU_PMU_EVENT_MAX];
 	uint32_t                pmu_cycle_counter_enable;
 	uint64_t                pmu_cycle_counter_count;
+	uint32_t                inference_type;
 	struct list_head        list;
 };
 
drivers/firmware/ethosu/ethosu_rpmsg.c +3 -1
index cb7e4556f635..e4cf398468e4 100644
@@ -107,7 +107,8 @@ int ethosu_rpmsg_inference(struct ethosu_rpmsg *erp,
 			   struct ethosu_buffer *network,
 			   uint8_t *pmu_event_config,
 			   uint8_t pmu_event_config_count,
-			   uint8_t pmu_cycle_counter_enable)
+			   uint8_t pmu_cycle_counter_enable,
+			   uint32_t inference_type)
 {
 	struct ethosu_core_msg msg = {
 		.magic  = ETHOSU_CORE_MSG_MAGIC,
@@ -132,6 +133,7 @@ int ethosu_rpmsg_inference(struct ethosu_rpmsg *erp,
 	req.ifm_count = ifm_count;
 	req.ofm_count = ofm_count;
 	req.pmu_cycle_counter_enable = pmu_cycle_counter_enable;
+	req.inference_type = inference_type;
 
 	for (i = 0; i < ifm_count; i++)
 		ethosu_core_set_size(ifm[i], &req.ifm[i]);
drivers/firmware/ethosu/ethosu_rpmsg.h +2 -1
index dd08e0d7945b..a4a639997a26 100644
@@ -63,7 +63,8 @@ int ethosu_rpmsg_inference(struct ethosu_rpmsg *erp,
 			   struct ethosu_buffer *network,
 			   uint8_t *pmu_event_config,
 			   uint8_t pmu_event_config_count,
-			   uint8_t pmu_cycle_counter_enable
+			   uint8_t pmu_cycle_counter_enable,
+			   uint32_t inference_type
 			   );
 
 int ethosu_rpmsg_init(struct ethosu_rpmsg *erp,
drivers/firmware/ethosu/uapi/ethosu.h +10 -1
index 903316dff7b3..c4a0df67336c 100644
@@ -62,7 +62,7 @@ namespace EthosU {
 #define ETHOSU_FD_MAX                   16
 
 /* Maximum number of PMUs available */
-#define ETHOSU_PMU_EVENT_MAX             8
+#define ETHOSU_PMU_EVENT_MAX             4
 
 /****************************************************************************
  * Types
@@ -173,6 +173,14 @@ struct ethosu_uapi_device_capabilities {
 	__u32                            driver_major_rev;
 };
 
+/**
+ * enum ethosu_uapi_inference_type - Inference type
+ */
+enum ethosu_uapi_inference_type {
+	ETHOSU_UAPI_INFERENCE_MODEL = 0,
+	ETHOSU_UAPI_INFERENCE_OP
+};
+
 /**
  * struct ethosu_uapi_inference_create - Create network request
  * @ifm_count:		Number of IFM file descriptors
@@ -185,6 +193,7 @@ struct ethosu_uapi_inference_create {
 	__u32                         ifm_fd[ETHOSU_FD_MAX];
 	__u32                         ofm_count;
 	__u32                         ofm_fd[ETHOSU_FD_MAX];
+	enum ethosu_uapi_inference_type inference_type;
 	struct ethosu_uapi_pmu_config pmu_config;
 };
 
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#14 lore raw

PATCH 4/8 ethosu: Add suspend/resume power management

In reply to Alison Wang

This patch adds suspend and resume power management support. The corresponding message will be sent to Cortex-M core via RPMsg protocol.

---
 drivers/firmware/ethosu/ethosu_buffer.c       |  3 ++
 .../firmware/ethosu/ethosu_core_interface.h   | 14 ++++++++
 drivers/firmware/ethosu/ethosu_device.c       | 36 +++++++++++++++++++
 drivers/firmware/ethosu/ethosu_device.h       | 10 ++++++
 drivers/firmware/ethosu/ethosu_driver.c       | 29 +++++++++++++++
 drivers/firmware/ethosu/ethosu_rpmsg.c        | 30 ++++++++++++++++
 drivers/firmware/ethosu/ethosu_rpmsg.h        | 11 ++++++
 7 files changed, 133 insertions(+)
drivers/firmware/ethosu/ethosu_buffer.c +3 -0
index 43a433355f30..c8aa8031a8de 100644
@@ -222,6 +222,9 @@ int ethosu_buffer_create(struct ethosu_device *edev,
 	struct ethosu_buffer *buf;
 	int ret = -ENOMEM;
 
+	if (!capacity)
+		return -EINVAL;
+
 	buf = devm_kzalloc(edev->dev, sizeof(*buf), GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;
drivers/firmware/ethosu/ethosu_core_interface.h +14 -0
index b60508e4792f..9267e96aec9b 100644
@@ -60,6 +60,8 @@ enum ethosu_core_msg_type {
 	ETHOSU_CORE_MSG_VERSION_RSP,
 	ETHOSU_CORE_MSG_CAPABILITIES_REQ,
 	ETHOSU_CORE_MSG_CAPABILITIES_RSP,
+	ETHOSU_CORE_MSG_POWER_REQ,
+	ETHOSU_CORE_MSG_POWER_RSP,
 	ETHOSU_CORE_MSG_MAX
 };
 
@@ -161,6 +163,18 @@ struct ethosu_core_msg_capabilities_rsp {
 	uint32_t custom_dma;
 };
 
+enum ethosu_core_power_req_type {
+	ETHOSU_CORE_POWER_REQ_SUSPEND = 0,
+	ETHOSU_CORE_POWER_REQ_RESUME
+};
+
+/**
+ * struct ethosu_core_power_req - Message power request
+ */
+struct ethosu_core_power_req {
+	enum ethosu_core_power_req_type type;
+};
+
 /**
  * enum ethosu_core_msg_err_type - Error types
  */
drivers/firmware/ethosu/ethosu_device.c +36 -0
index b2d4737080ac..1627f25c8a95 100644
@@ -38,6 +38,7 @@
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/of_reserved_mem.h>
+#include <linux/remoteproc.h>
 #include <linux/uaccess.h>
 #include <linux/slab.h>
 
@@ -49,6 +50,8 @@
 
 #define CAPABILITIES_RESP_TIMEOUT_MS 2000
 
+#define ETHOSU_FIRMWARE_NAME "ethosu_firmware"
+
 /****************************************************************************
  * Types
  ****************************************************************************/
@@ -161,6 +164,9 @@ static int ethosu_handle_msg(struct ethosu_device *edev, void *data)
 	case ETHOSU_CORE_MSG_PONG:
 		dev_info(edev->dev, "Msg: Pong\n");
 		break;
+	case ETHOSU_CORE_MSG_POWER_RSP:
+		dev_info(edev->dev, "Msg: Power response\n");
+		break;
 	case ETHOSU_CORE_MSG_INFERENCE_RSP:
 		if (header->length != sizeof(struct ethosu_core_inference_rsp)) {
 			dev_warn(edev->dev,
@@ -243,11 +249,41 @@ static int ethosu_open(struct inode *inode,
 {
 	struct ethosu_device *edev =
 		container_of(inode->i_cdev, struct ethosu_device, cdev);
+	phandle rproc_phandle;
+	struct rproc *rproc;
+	int ret = 0;
 
 	file->private_data = edev;
 
 	dev_info(edev->dev, "Opening device node.\n");
 
+	if (of_property_read_u32(edev->dev->of_node, "fsl,cm33-proc",
+				 &rproc_phandle)) {
+		dev_err(edev->dev, "could not get rproc phandle\n");
+		return -ENODEV;
+	}
+
+	rproc = rproc_get_by_phandle(rproc_phandle);
+	if (!rproc) {
+		dev_err(edev->dev, "could not get rproc handle\n");
+		return -EINVAL;
+	}
+
+	ret = rproc_set_firmware(rproc, ETHOSU_FIRMWARE_NAME);
+
+	if (!ret && atomic_read(&rproc->power) == 0) {
+		init_completion(&edev->erp.rpmsg_ready);
+		ret = rproc_boot(rproc);
+		if (ret)
+			dev_err(edev->dev, "could not boot a remote processor\n");
+		else
+			wait_for_completion_interruptible(&edev->erp.rpmsg_ready);
+	} else {
+		dev_err(edev->dev, "can't change firmware or remote processor is running\n");
+	}
+
+	edev->open = true;
+
 	return nonseekable_open(inode, file);
 }
 
drivers/firmware/ethosu/ethosu_device.h +10 -0
index 3943c8df8f28..da470241b6a1 100644
@@ -51,6 +51,7 @@ struct ethosu_device {
 	struct ethosu_rpmsg   erp;
 	struct list_head      capabilities_list;
 	struct list_head      inference_list;
+	bool                  open;
 };
 
 /**
@@ -83,4 +84,13 @@ int ethosu_dev_init(struct ethosu_device *edev,
  */
 void ethosu_dev_deinit(struct ethosu_device *edev);
 
+/**
+ * ethosu_suspend() - Suspend the device
+ */
+int ethosu_suspend(struct device *dev);
+/**
+ * ethosu_resume() - Resume the device
+ */
+int ethosu_resume(struct device *dev);
+
 #endif /* ETHOSU_DEVICE_H */
drivers/firmware/ethosu/ethosu_driver.c +29 -0
index 27931e9aa97c..d3306ef625ae 100644
@@ -27,6 +27,7 @@
 #include <linux/of_address.h>
 #include <linux/platform_device.h>
 
+#include "ethosu_core_interface.h"
 #include "ethosu_device.h"
 
 /****************************************************************************
@@ -101,6 +102,33 @@ static int ethosu_pdev_remove(struct platform_device *pdev)
 	return 0;
 }
 
+int ethosu_suspend(struct device *dev)
+{
+	struct ethosu_device *edev = dev->driver_data;
+	int ret = 0;
+
+	if (edev->open)
+		ret = ethosu_rpmsg_power_request(&edev->erp, ETHOSU_CORE_POWER_REQ_SUSPEND);
+
+	return ret;
+}
+
+int ethosu_resume(struct device *dev)
+{
+	struct ethosu_device *edev = dev->driver_data;
+	int ret = 0;
+
+	if (edev->open)
+		ret = ethosu_rpmsg_power_request(&edev->erp, ETHOSU_CORE_POWER_REQ_RESUME);
+
+	return ret;
+}
+
+struct dev_pm_ops ethosu_pm_ops = {
+	.suspend = ethosu_suspend,
+	.resume = ethosu_resume,
+};
+
 static const struct of_device_id ethosu_pdev_match[] = {
 	{ .compatible = "arm,ethosu" },
 	{ /* Sentinel */ },
@@ -115,6 +143,7 @@ static struct platform_driver ethosu_pdev_driver = {
 		.name           = ETHOSU_DRIVER_NAME,
 		.owner          = THIS_MODULE,
 		.of_match_table = of_match_ptr(ethosu_pdev_match),
+		.pm		= &ethosu_pm_ops,
 	},
 };
 
drivers/firmware/ethosu/ethosu_rpmsg.c +30 -0
index e4cf398468e4..a0320b8407d1 100644
@@ -98,6 +98,35 @@ int ethosu_rpmsg_capabilities_request(struct ethosu_rpmsg *erp, void *user_arg)
 	return 0;
 }
 
+int ethosu_rpmsg_power_request(struct ethosu_rpmsg *erp,
+			       enum ethosu_core_power_req_type power_type)
+{
+	struct ethosu_core_msg msg = {
+		.magic  = ETHOSU_CORE_MSG_MAGIC,
+		.type   = ETHOSU_CORE_MSG_POWER_REQ,
+		.length = sizeof(struct ethosu_core_power_req)
+	};
+	struct ethosu_core_power_req req;
+	struct rpmsg_device *rpdev = erp->rpdev;
+	uint8_t data[sizeof(struct ethosu_core_msg) +
+		sizeof(struct ethosu_core_power_req)];
+	int ret;
+
+	req.type = power_type;
+	memcpy(data, &msg, sizeof(struct ethosu_core_msg));
+	memcpy(data + sizeof(struct ethosu_core_msg), &req,
+	       sizeof(struct ethosu_core_power_req));
+
+	ret = rpmsg_send(rpdev->ept, (void *)&data,
+			 sizeof(struct ethosu_core_msg) +
+			 sizeof(struct ethosu_core_power_req));
+	if (ret) {
+		dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
+		return ret;
+	}
+	return 0;
+}
+
 int ethosu_rpmsg_inference(struct ethosu_rpmsg *erp,
 			   void *user_arg,
 			   uint32_t ifm_count,
@@ -193,6 +222,7 @@ static int ethosu_rpmsg_probe(struct rpmsg_device *rpdev)
 	if (ret) {
 		dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
 	}
+	complete(&grp->rpmsg_ready);
 
 	return 0;
 }
drivers/firmware/ethosu/ethosu_rpmsg.h +11 -0
index a4a639997a26..cee3d96c7895 100644
@@ -7,6 +7,8 @@
 #define ETHOSU_RPMSG_H
 
 #include <linux/types.h>
+#include <linux/completion.h>
+#include "ethosu_core_interface.h"
 
 struct device;
 struct ethosu_buffer;
@@ -19,6 +21,7 @@ struct ethosu_rpmsg {
 	struct rpmsg_device	*rpdev;
 	ethosu_rpmsg_cb		callback;
 	void			*user_arg;
+	struct completion       rpmsg_ready;
 };
 /**
  * ethosu_rpmsg_ping() - Send ping message
@@ -49,6 +52,14 @@ int ethosu_rpmsg_version_request(struct ethosu_rpmsg *erp);
 int ethosu_rpmsg_capabilities_request(struct ethosu_rpmsg *erp,
 				      void *user_arg);
 
+/**
+ * ethosu_rpmsg_power_request - Send power request
+ *
+ * Return: 0 on success, else error code
+ */
+int ethosu_rpmsg_power_request(struct ethosu_rpmsg *erp,
+			       enum ethosu_core_power_req_type power_type);
+
 /**
  * ethosu_rpmsg_inference() - Send inference
  *
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#15 lore raw

PATCH 5/8 ethosu: Use ids for identifying messages sent to Ethos-U firmware

In reply to Alison Wang

Avoid to use pointers to kernel memory as identify messages, prior this change, if memory is reused that can lead to unexpected conflicts.

Remove ref counting from capabilities since memory is freed in only one place.

Finally, extract the capabilities code in its own files.

---
 drivers/firmware/ethosu/Kconfig               |   2 +-
 drivers/firmware/ethosu/Makefile              |   5 +-
 drivers/firmware/ethosu/ethosu_buffer.c       |  34 +--
 drivers/firmware/ethosu/ethosu_buffer.h       |   2 +-
 drivers/firmware/ethosu/ethosu_capabilities.c | 157 ++++++++++++
 drivers/firmware/ethosu/ethosu_capabilities.h |  47 ++++
 .../firmware/ethosu/ethosu_core_interface.h   |  20 +-
 drivers/firmware/ethosu/ethosu_device.c       | 229 +++++-------------
 drivers/firmware/ethosu/ethosu_device.h       |  17 +-
 drivers/firmware/ethosu/ethosu_driver.c       |   4 +-
 drivers/firmware/ethosu/ethosu_inference.c    | 229 ++++++++++++------
 drivers/firmware/ethosu/ethosu_inference.h    |  14 +-
 drivers/firmware/ethosu/ethosu_network.c      |  22 +-
 drivers/firmware/ethosu/ethosu_network.h      |   2 +-
 drivers/firmware/ethosu/ethosu_rpmsg.c        |  72 +++++-
 drivers/firmware/ethosu/ethosu_rpmsg.h        |  53 +++-
 drivers/firmware/ethosu/uapi/ethosu.h         |   8 +-
 17 files changed, 606 insertions(+), 311 deletions(-)
 create mode 100644 drivers/firmware/ethosu/ethosu_capabilities.c
 create mode 100644 drivers/firmware/ethosu/ethosu_capabilities.h
drivers/firmware/ethosu/Kconfig +1 -1
index ce837f45f8e5..4d3b1b86aabe 100644
@@ -1,5 +1,5 @@
 #
-# (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
+# (C) COPYRIGHT 2020,2022 ARM Limited.
 #
 # This program is free software and is provided to you under the terms of the
 # GNU General Public License version 2 as published by the Free Software
drivers/firmware/ethosu/Makefile +3 -2
index 0b3fe72c9c4f..fa0731adad35 100644
@@ -1,5 +1,5 @@
 #
-# (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
+# Copyright (c) 2020,2022 Arm Limited.
 #
 # This program is free software and is provided to you under the terms of the
 # GNU General Public License version 2 as published by the Free Software
@@ -25,4 +25,5 @@ ethosu-objs := ethosu_driver.o \
                ethosu_device.o \
                ethosu_inference.o \
                ethosu_rpmsg.o \
-               ethosu_network.o
+               ethosu_network.o \
+               ethosu_capabilities.o
drivers/firmware/ethosu/ethosu_buffer.c +19 -15
index c8aa8031a8de..d71db348a240 100644
@@ -1,5 +1,5 @@
 /*
- * (C) COPYRIGHT 2020-2021 Arm Limited. All rights reserved.
+ * Copyright (c) 2020-2022 Arm Limited.
  *
  * This program is free software and is provided to you under the terms of the
  * GNU General Public License version 2 as published by the Free Software
@@ -126,7 +126,7 @@ static void ethosu_buffer_destroy(struct kref *kref)
 	struct ethosu_buffer *buf =
 		container_of(kref, struct ethosu_buffer, kref);
 
-	dev_info(buf->edev->dev, "Buffer destroy. handle=0x%pK\n", buf);
+	dev_dbg(buf->edev->dev, "Buffer destroy. buf=0x%pK\n", buf);
 
 	dma_free_coherent(buf->edev->dev, buf->capacity, buf->cpu_addr,
 			  buf->dma_addr_orig);
@@ -138,7 +138,8 @@ static int ethosu_buffer_release(struct inode *inode,
 {
 	struct ethosu_buffer *buf = file->private_data;
 
-	dev_info(buf->edev->dev, "Buffer release. handle=0x%pK\n", buf);
+	dev_dbg(buf->edev->dev, "Buffer release. file=0x%pK, buf=0x%pK\n",
+		file, buf);
 
 	ethosu_buffer_put(buf);
 
@@ -151,7 +152,8 @@ static int ethosu_buffer_mmap(struct file *file,
 	struct ethosu_buffer *buf = file->private_data;
 	int ret;
 
-	dev_info(buf->edev->dev, "Buffer mmap. handle=0x%pK\n", buf);
+	dev_dbg(buf->edev->dev, "Buffer mmap. file=0x%pK, buf=0x%pK\n",
+		file, buf);
 
 	ret = dma_mmap_coherent(buf->edev->dev, vma, buf->cpu_addr,
 				buf->dma_addr_orig,
@@ -172,7 +174,9 @@ static long ethosu_buffer_ioctl(struct file *file,
 	if (ret)
 		return ret;
 
-	dev_info(buf->edev->dev, "Ioctl. cmd=%u, arg=%lu\n", cmd, arg);
+	dev_dbg(buf->edev->dev,
+		"Buffer ioctl. file=0x%pK, buf=0x%pK, cmd=0x%x, arg=%lu\n",
+		file, buf, cmd, arg);
 
 	switch (cmd) {
 	case ETHOSU_IOCTL_BUFFER_SET: {
@@ -181,9 +185,9 @@ static long ethosu_buffer_ioctl(struct file *file,
 		if (copy_from_user(&uapi, udata, sizeof(uapi)))
 			break;
 
-		dev_info(buf->edev->dev,
-			 "Ioctl: Buffer set. size=%u, offset=%u\n",
-			 uapi.size, uapi.offset);
+		dev_dbg(buf->edev->dev,
+			"Buffer ioctl: Buffer set. size=%u, offset=%u\n",
+			uapi.size, uapi.offset);
 
 		ret = ethosu_buffer_resize(buf, uapi.size, uapi.offset);
 		break;
@@ -194,9 +198,9 @@ static long ethosu_buffer_ioctl(struct file *file,
 		uapi.size = buf->size;
 		uapi.offset = buf->offset;
 
-		dev_info(buf->edev->dev,
-			 "Ioctl: Buffer get. size=%u, offset=%u\n",
-			 uapi.size, uapi.offset);
+		dev_dbg(buf->edev->dev,
+			"Buffer ioctl: Buffer get. size=%u, offset=%u\n",
+			uapi.size, uapi.offset);
 
 		if (copy_to_user(udata, &uapi, sizeof(uapi)))
 			break;
@@ -252,10 +256,10 @@ int ethosu_buffer_create(struct ethosu_device *edev,
 	buf->file = fget(ret);
 	fput(buf->file);
 
-	dev_info(buf->edev->dev,
-		 "Buffer create. handle=0x%pK, capacity=%zu, cpu_addr=0x%pK, dma_addr=0x%llx, dma_addr_orig=0x%llx, phys_addr=0x%llx\n",
-		 buf, capacity, buf->cpu_addr, buf->dma_addr,
-		 buf->dma_addr_orig, virt_to_phys(buf->cpu_addr));
+	dev_dbg(buf->edev->dev,
+		"Buffer create. file=0x%pK, fd=%d, buf=0x%pK, capacity=%zu, cpu_addr=0x%pK, dma_addr=0x%llx, dma_addr_orig=0x%llx, phys_addr=0x%llx\n",
+		buf->file, ret, buf, capacity, buf->cpu_addr, buf->dma_addr,
+		buf->dma_addr_orig, virt_to_phys(buf->cpu_addr));
 
 	return ret;
 
drivers/firmware/ethosu/ethosu_buffer.h +1 -1
index 14f26c2b0a9d..7a21fcb36b2d 100644
@@ -1,5 +1,5 @@
 /*
- * (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
+ * Copyright (c) 2020,2022 ARM Limited.
  *
  * This program is free software and is provided to you under the terms of the
  * GNU General Public License version 2 as published by the Free Software
drivers/firmware/ethosu/ethosu_capabilities.c new file +157 -0

157 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_capabilities.h new file +47 -0

47 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_core_interface.h +18 -2
index 9267e96aec9b..11b695a5219d 100644
@@ -1,5 +1,5 @@
 /*
- * (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
+ * Copyright (c) 2020-2022 Arm Limited.
  *
  * This program is free software and is provided to you under the terms of the
  * GNU General Public License version 2 as published by the Free Software
@@ -93,11 +93,24 @@ struct ethosu_core_queue {
 	uint8_t                         data[];
 };
 
+/**
+ * enum ethosu_core_status - Status
+ */
 enum ethosu_core_status {
 	ETHOSU_CORE_STATUS_OK,
-	ETHOSU_CORE_STATUS_ERROR
+	ETHOSU_CORE_STATUS_ERROR,
+	ETHOSU_CORE_STATUS_RUNNING,
+	ETHOSU_CORE_STATUS_REJECTED,
+	ETHOSU_CORE_STATUS_ABORTED,
+	ETHOSU_CORE_STATUS_ABORTING,
 };
 
+/**
+ * struct ethosu_core_buffer - Buffer descriptor
+ *
+ * Pointer and size to a buffer within the Ethos-U
+ * address space.
+ */
 struct ethosu_core_buffer {
 	uint32_t ptr;
 	uint32_t size;
@@ -115,6 +128,9 @@ struct ethosu_core_inference_req {
 	uint32_t                  inference_type;
 };
 
+/**
+ * struct ethosu_core_inference_rsp - Inference response
+ */
 struct ethosu_core_inference_rsp {
 	uint64_t user_arg;
 	uint32_t ofm_count;
drivers/firmware/ethosu/ethosu_device.c +56 -173

340 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_device.h +1 -16
index da470241b6a1..d027d8d9b11d 100644
@@ -1,5 +1,5 @@
 /*
- * (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
+ * Copyright (c) 2020-2022 Arm Limited.
  *
  * This program is free software and is provided to you under the terms of the
  * GNU General Public License version 2 as published by the Free Software
@@ -32,8 +32,6 @@
 #include <linux/cdev.h>
 #include <linux/io.h>
 #include <linux/mutex.h>
-#include <linux/workqueue.h>
-#include <linux/completion.h>
 
 /****************************************************************************
  * Types
@@ -49,22 +47,9 @@ struct ethosu_device {
 	dev_t                 devt;
 	struct mutex          mutex;
 	struct ethosu_rpmsg   erp;
-	struct list_head      capabilities_list;
-	struct list_head      inference_list;
 	bool                  open;
 };
 
-/**
- * struct ethosu_capabilities - Capabilities internal struct
- */
-struct ethosu_capabilities {
-	struct ethosu_device                   *edev;
-	struct completion                      done;
-	struct kref                            refcount;
-	struct ethosu_uapi_device_capabilities *capabilities;
-	struct list_head                       list;
-};
-
 /****************************************************************************
  * Functions
  ****************************************************************************/
drivers/firmware/ethosu/ethosu_driver.c +2 -2
index d3306ef625ae..59ae79256564 100644
@@ -1,5 +1,5 @@
 /*
- * (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
+ * Copyright (c) 2020-2022 Arm Limited.
  * Copyright 2020-2022 NXP
  *
  * This program is free software and is provided to you under the terms of the
@@ -60,7 +60,7 @@ static int ethosu_pdev_probe(struct platform_device *pdev)
 	int minor;
 	int ret;
 
-	dev_info(&pdev->dev, "Probe\n");
+	dev_dbg(&pdev->dev, "Probe\n");
 
 	minor = find_first_zero_bit(minors, MINOR_COUNT);
 	if (minor >= MINOR_COUNT) {
drivers/firmware/ethosu/ethosu_inference.c +156 -73

377 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_inference.h +9 -5
index 8414eadbda92..311c727b2897 100644
@@ -1,5 +1,5 @@
 /*
- * (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
+ * Copyright (c) 2020,2022 ARM Limited.
  *
  * This program is free software and is provided to you under the terms of the
  * GNU General Public License version 2 as published by the Free Software
@@ -25,6 +25,7 @@
  * Includes
  ****************************************************************************/
 
+#include "ethosu_rpmsg.h"
 #include "uapi/ethosu.h"
 
 #include <linux/kref.h>
@@ -48,34 +49,35 @@ struct file;
  * @file:			File handle
  * @kref:			Reference counter
  * @waitq:			Wait queue
+ * @done:			Wait condition is done
  * @ifm:			Pointer to IFM buffer
  * @ofm:			Pointer to OFM buffer
  * @net:			Pointer to network
- * @pending:			Pending response from the firmware
  * @status:			Inference status
  * @pmu_event_config:		PMU event configuration
  * @pmu_event_count:		PMU event count after inference
  * @pmu_cycle_counter_enable:	PMU cycle counter config
  * @pmu_cycle_counter_count:	PMU cycle counter count after inference
+ * @msg:			Rpmsg message
  */
 struct ethosu_inference {
 	struct ethosu_device    *edev;
 	struct file             *file;
 	struct kref             kref;
 	wait_queue_head_t       waitq;
+	bool                    done;
 	uint32_t                ifm_count;
 	struct ethosu_buffer    *ifm[ETHOSU_FD_MAX];
 	uint32_t                ofm_count;
 	struct ethosu_buffer    *ofm[ETHOSU_FD_MAX];
 	struct ethosu_network   *net;
-	bool                    pending;
 	enum ethosu_uapi_status status;
 	uint8_t                 pmu_event_config[ETHOSU_PMU_EVENT_MAX];
 	uint32_t                pmu_event_count[ETHOSU_PMU_EVENT_MAX];
 	uint32_t                pmu_cycle_counter_enable;
 	uint64_t                pmu_cycle_counter_count;
 	uint32_t                inference_type;
-	struct list_head        list;
+	struct ethosu_rpmsg_msg msg;
 };
 
 /****************************************************************************
@@ -109,8 +111,10 @@ void ethosu_inference_get(struct ethosu_inference *inf);
 
 /**
  * ethosu_inference_put() - Put inference
+ *
+ * Return: 1 if object was removed, else 0.
  */
-void ethosu_inference_put(struct ethosu_inference *inf);
+int ethosu_inference_put(struct ethosu_inference *inf);
 
 /**
  * ethosu_inference_rsp() - Handle inference response
drivers/firmware/ethosu/ethosu_network.c +13 -9
index 4d68f0537e38..a7249619291b 100644
@@ -1,5 +1,5 @@
 /*
- * (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
+ * Copyright (c) 2020,2022 Arm Limited.
  *
  * This program is free software and is provided to you under the terms of the
  * GNU General Public License version 2 as published by the Free Software
@@ -67,7 +67,7 @@ static void ethosu_network_destroy(struct kref *kref)
 	struct ethosu_network *net =
 		container_of(kref, struct ethosu_network, kref);
 
-	dev_info(net->edev->dev, "Network destroy. handle=0x%pK\n", net);
+	dev_dbg(net->edev->dev, "Network destroy. net=0x%pK\n", net);
 
 	ethosu_buffer_put(net->buf);
 	devm_kfree(net->edev->dev, net);
@@ -78,7 +78,8 @@ static int ethosu_network_release(struct inode *inode,
 {
 	struct ethosu_network *net = file->private_data;
 
-	dev_info(net->edev->dev, "Network release. handle=0x%pK\n", net);
+	dev_dbg(net->edev->dev, "Network release. file=0x%pK, net=0x%pK\n",
+		file, net);
 
 	ethosu_network_put(net);
 
@@ -97,7 +98,9 @@ static long ethosu_network_ioctl(struct file *file,
 	if (ret)
 		return ret;
 
-	dev_info(net->edev->dev, "Ioctl: cmd=%u, arg=%lu\n", cmd, arg);
+	dev_dbg(net->edev->dev,
+		"Network ioctl: file=0x%pK, net=0x%pK, cmd=0x%x, arg=0x%lx\n",
+		file, net, cmd, arg);
 
 	switch (cmd) {
 	case ETHOSU_IOCTL_INFERENCE_CREATE: {
@@ -106,9 +109,9 @@ static long ethosu_network_ioctl(struct file *file,
 		if (copy_from_user(&uapi, udata, sizeof(uapi)))
 			break;
 
-		dev_info(net->edev->dev,
-			 "Ioctl: Inference. ifm_fd=%u, ofm_fd=%u\n",
-			 uapi.ifm_fd[0], uapi.ofm_fd[0]);
+		dev_dbg(net->edev->dev,
+			"Network ioctl: Inference. ifm_fd=%u, ofm_fd=%u\n",
+			uapi.ifm_fd[0], uapi.ofm_fd[0]);
 
 		ret = ethosu_inference_create(net->edev, net, &uapi);
 		break;
@@ -154,8 +157,9 @@ int ethosu_network_create(struct ethosu_device *edev,
 	net->file = fget(ret);
 	fput(net->file);
 
-	dev_info(edev->dev, "Network create. handle=0x%pK",
-		 net);
+	dev_dbg(edev->dev,
+		"Network create. file=0x%pK, fd=%d, net=0x%pK, buf=0x%pK",
+		net->file, ret, net, net->buf);
 
 	return ret;
 
drivers/firmware/ethosu/ethosu_network.h +1 -1
index bb70afcb2572..4236e1586efb 100644
@@ -1,5 +1,5 @@
 /*
- * (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
+ * Copyright (c) 2020,2022 Arm Limited.
  *
  * This program is free software and is provided to you under the terms of the
  * GNU General Public License version 2 as published by the Free Software
drivers/firmware/ethosu/ethosu_rpmsg.c +65 -7

120 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_rpmsg.h +51 -2

84 lines not on this page · raw message

drivers/firmware/ethosu/uapi/ethosu.h +6 -2
index c4a0df67336c..648cec40473b 100644
@@ -1,5 +1,5 @@
 /*
- * (C) COPYRIGHT 2020 ARM Limited. All rights reserved.
+ * Copyright (c) 2020-2022 Arm Limited.
  *
  * This program is free software and is provided to you under the terms of the
  * GNU General Public License version 2 as published by the Free Software
@@ -73,7 +73,11 @@ namespace EthosU {
  */
 enum ethosu_uapi_status {
 	ETHOSU_UAPI_STATUS_OK,
-	ETHOSU_UAPI_STATUS_ERROR
+	ETHOSU_UAPI_STATUS_ERROR,
+	ETHOSU_UAPI_STATUS_RUNNING,
+	ETHOSU_UAPI_STATUS_REJECTED,
+	ETHOSU_UAPI_STATUS_ABORTED,
+	ETHOSU_UAPI_STATUS_ABORTING,
 };
 
 /**
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#16 lore raw

PATCH 6/8 ethosu: Add core message about network info

In reply to Alison Wang

Add core message that allows user space to fetch information about network models built into the firmware.

---
 drivers/firmware/ethosu/Makefile              |   1 +
 .../firmware/ethosu/ethosu_core_interface.h   |  62 +++++-
 drivers/firmware/ethosu/ethosu_device.c       |  28 ++-
 drivers/firmware/ethosu/ethosu_inference.c    |   1 +
 drivers/firmware/ethosu/ethosu_network.c      |  62 ++++--
 drivers/firmware/ethosu/ethosu_network.h      |   5 +-
 drivers/firmware/ethosu/ethosu_network_info.c | 184 ++++++++++++++++++
 drivers/firmware/ethosu/ethosu_network_info.h |  56 ++++++
 drivers/firmware/ethosu/ethosu_rpmsg.c        |  50 ++++-
 drivers/firmware/ethosu/ethosu_rpmsg.h        |  11 ++
 drivers/firmware/ethosu/uapi/ethosu.h         |  42 +++-
 11 files changed, 470 insertions(+), 32 deletions(-)
 create mode 100644 drivers/firmware/ethosu/ethosu_network_info.c
 create mode 100644 drivers/firmware/ethosu/ethosu_network_info.h
drivers/firmware/ethosu/Makefile +1 -0
index fa0731adad35..a162a3bd32e3 100644
@@ -26,4 +26,5 @@ ethosu-objs := ethosu_driver.o \
                ethosu_inference.o \
                ethosu_rpmsg.o \
                ethosu_network.o \
+               ethosu_network_info.o \
                ethosu_capabilities.o
drivers/firmware/ethosu/ethosu_core_interface.h +59 -3

92 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_device.c +23 -5
index 6643a7aaad5b..b0be4bcba7a1 100644
@@ -30,6 +30,7 @@
 #include "ethosu_capabilities.h"
 #include "ethosu_inference.h"
 #include "ethosu_network.h"
+#include "ethosu_network_info.h"
 #include "uapi/ethosu.h"
 
 #include <linux/dma-mapping.h>
@@ -75,6 +76,9 @@ static int ethosu_handle_msg(struct ethosu_device *edev, void *data)
 	struct ethosu_core_msg_capabilities_rsp *capabilities =
 			(struct ethosu_core_msg_capabilities_rsp *)
 			((char *)data + sizeof(struct ethosu_core_msg));
+	struct ethosu_core_network_info_rsp *network_info =
+			(struct ethosu_core_network_info_rsp *)
+			((char *)data + sizeof(struct ethosu_core_msg));
 
 	switch (header->type) {
 	case ETHOSU_CORE_MSG_ERR:
@@ -168,6 +172,22 @@ static int ethosu_handle_msg(struct ethosu_device *edev, void *data)
 
 		ethosu_capability_rsp(edev, capabilities);
 		break;
+	case ETHOSU_CORE_MSG_NETWORK_INFO_RSP:
+		if (header->length != sizeof(struct ethosu_core_network_info_rsp)) {
+			dev_warn(edev->dev,
+				 "Msg: Network info response of incorrect size. size=%u, expected=%zu\n",
+				 header->length, sizeof(struct ethosu_core_network_info_rsp));
+			ret = -EBADMSG;
+			break;
+		}
+
+		dev_dbg(edev->dev,
+			"Msg: Network info response. user_arg=0x%llx, status=%u",
+			network_info->user_arg,
+			network_info->status);
+
+		ethosu_network_info_rsp(edev, network_info);
+		break;
 	default:
 		/* This should not happen due to version checks */
 		dev_warn(edev->dev, "Msg: Protocol error\n");
@@ -208,10 +228,8 @@ static int ethosu_open(struct inode *inode,
 	if (!ret && atomic_read(&rproc->power) == 0) {
 		init_completion(&edev->erp.rpmsg_ready);
 		ret = rproc_boot(rproc);
-		if (ret)
+		if (ret || wait_for_completion_interruptible(&edev->erp.rpmsg_ready))
 			dev_err(edev->dev, "could not boot a remote processor\n");
-		else
-			wait_for_completion_interruptible(&edev->erp.rpmsg_ready);
 	} else {
 		dev_err(edev->dev, "can't change firmware or remote processor is running\n");
 	}
@@ -279,8 +297,8 @@ static long ethosu_ioctl(struct file *file,
 			break;
 
 		dev_dbg(edev->dev,
-			"Device ioctl: Network create. fd=%u\n",
-			uapi.fd);
+			"Device ioctl: Network create. type=%u, fd/index=%u\n",
+			uapi.type, uapi.fd);
 
 		ret = ethosu_network_create(edev, &uapi);
 		break;
drivers/firmware/ethosu/ethosu_inference.c +1 -0
index 947988507792..4e5fa214c5d6 100644
@@ -99,6 +99,7 @@ static int ethosu_inference_send(struct ethosu_inference *inf)
 				     inf->ifm_count, inf->ifm,
 				     inf->ofm_count, inf->ofm,
 				     inf->net->buf,
+				     inf->net->index,
 				     inf->pmu_event_config,
 				     ETHOSU_PMU_EVENT_MAX,
 				     inf->pmu_cycle_counter_enable,
drivers/firmware/ethosu/ethosu_network.c +43 -19

113 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_network.h +4 -1
index 4236e1586efb..8ca2dd61886e 100644
@@ -43,6 +43,7 @@ struct ethosu_network {
 	struct file          *file;
 	struct kref          kref;
 	struct ethosu_buffer *buf;
+	u32                  index;
 };
 
 /****************************************************************************
@@ -75,7 +76,9 @@ void ethosu_network_get(struct ethosu_network *net);
 
 /**
  * ethosu_network_put() - Put network
+ *
+ * Return: 1 if object was removed, else 0.
  */
-void ethosu_network_put(struct ethosu_network *net);
+int ethosu_network_put(struct ethosu_network *net);
 
 #endif /* ETHOSU_NETWORK_H */
drivers/firmware/ethosu/ethosu_network_info.c new file +184 -0

184 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_network_info.h new file +56 -0

56 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_rpmsg.c +49 -1

68 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_rpmsg.h +11 -0
index 74ee2fdea5cb..ba6fb8fd5869 100644
@@ -84,12 +84,23 @@ int ethosu_rpmsg_inference(struct ethosu_rpmsg *erp,
 			   uint32_t ofm_count,
 			   struct ethosu_buffer **ofm,
 			   struct ethosu_buffer *network,
+			   u32 network_index,
 			   uint8_t *pmu_event_config,
 			   uint8_t pmu_event_config_count,
 			   uint8_t pmu_cycle_counter_enable,
 			   uint32_t inference_type
 			   );
 
+/**
+ * ethosu_rpmsg_network_info_request() - Send network info request
+ *
+ * Return: 0 on success, else error code.
+ */
+int ethosu_rpmsg_network_info_request(struct ethosu_rpmsg *erp,
+				      struct ethosu_rpmsg_msg *rpmsg,
+				      struct ethosu_buffer *network,
+				      uint32_t network_index);
+
 int ethosu_rpmsg_init(struct ethosu_rpmsg *erp,
 		      ethosu_rpmsg_cb callback, void *user_arg);
 
drivers/firmware/ethosu/uapi/ethosu.h +39 -3

71 lines not on this page · raw message

Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#17 lore raw

PATCH 7/8 ethosu: Add core message about inference cancellation

In reply to Alison Wang

This patch adds core message about sending cancel inference message to Ethos-U subsystem to abort inference execution.

---
 drivers/firmware/ethosu/Makefile              |   3 +-
 .../firmware/ethosu/ethosu_cancel_inference.c | 185 ++++++++++++++++++
 .../firmware/ethosu/ethosu_cancel_inference.h |  55 ++++++
 .../firmware/ethosu/ethosu_core_interface.h   |  37 ++--
 drivers/firmware/ethosu/ethosu_inference.c    |  16 ++
 drivers/firmware/ethosu/ethosu_rpmsg.c        |  33 ++++
 drivers/firmware/ethosu/ethosu_rpmsg.h        |   9 +
 drivers/firmware/ethosu/uapi/ethosu.h         |  29 +++
 8 files changed, 349 insertions(+), 18 deletions(-)
 create mode 100644 drivers/firmware/ethosu/ethosu_cancel_inference.c
 create mode 100644 drivers/firmware/ethosu/ethosu_cancel_inference.h
drivers/firmware/ethosu/Makefile +2 -1
index a162a3bd32e3..88a352690ddd 100644
@@ -27,4 +27,5 @@ ethosu-objs := ethosu_driver.o \
                ethosu_rpmsg.o \
                ethosu_network.o \
                ethosu_network_info.o \
-               ethosu_capabilities.o
+               ethosu_capabilities.o \
+               ethosu_cancel_inference.o
drivers/firmware/ethosu/ethosu_cancel_inference.c new file +185 -0

185 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_cancel_inference.h new file +55 -0

55 lines not on this page · raw message

drivers/firmware/ethosu/ethosu_core_interface.h +20 -17
index f804de40b004..b1244ce28d39 100644
@@ -1,21 +1,6 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (c) 2020-2022 Arm Limited.
- *
- * This program is free software and is provided to you under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation, and any use by you of this program is subject to the terms
- * of such GNU licence.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, you can access it online at
- * http://www.gnu.org/licenses/gpl-2.0.html.
- *
- * SPDX-License-Identifier: GPL-2.0-only
+ * Copyright (c) 2022 Arm Limited.
  */
 
 #ifndef ETHOSU_CORE_INTERFACE_H
@@ -64,6 +49,8 @@ enum ethosu_core_msg_type {
 	ETHOSU_CORE_MSG_CAPABILITIES_RSP,
 	ETHOSU_CORE_MSG_NETWORK_INFO_REQ,
 	ETHOSU_CORE_MSG_NETWORK_INFO_RSP,
+	ETHOSU_CORE_MSG_CANCEL_INFERENCE_REQ,
+	ETHOSU_CORE_MSG_CANCEL_INFERENCE_RSP,
 	ETHOSU_CORE_MSG_POWER_REQ,
 	ETHOSU_CORE_MSG_POWER_RSP,
 	ETHOSU_CORE_MSG_MAX
@@ -235,6 +222,22 @@ struct ethosu_core_msg_capabilities_rsp {
 	uint32_t custom_dma;
 };
 
+/**
+ * struct ethosu_core_cancel_inference_req - Message cancel inference request
+ */
+struct ethosu_core_cancel_inference_req {
+	u64 user_arg;
+	u64 inference_handle;
+};
+
+/**
+ * struct ethosu_core_cancel_inference_rsp - Message cancel inference response
+ */
+struct ethosu_core_cancel_inference_rsp {
+	u64 user_arg;
+	u32 status;
+};
+
 enum ethosu_core_power_req_type {
 	ETHOSU_CORE_POWER_REQ_SUSPEND = 0,
 	ETHOSU_CORE_POWER_REQ_RESUME
drivers/firmware/ethosu/ethosu_inference.c +16 -0
index 4e5fa214c5d6..8c0c59242650 100644
@@ -28,6 +28,7 @@
 #include "ethosu_core_interface.h"
 #include "ethosu_device.h"
 #include "ethosu_network.h"
+#include "ethosu_cancel_inference.h"
 #include "uapi/ethosu.h"
 
 #include <linux/anon_inodes.h>
@@ -267,6 +268,21 @@ static long ethosu_inference_ioctl(struct file *file,
 
 		break;
 	}
+	case ETHOSU_IOCTL_INFERENCE_CANCEL: {
+		struct ethosu_uapi_cancel_inference_status uapi;
+
+		dev_dbg(inf->edev->dev,
+			"Inference ioctl: Cancel Inference. Handle=%p\n",
+			inf);
+
+		ret = ethosu_cancel_inference_request(inf, &uapi);
+		if (ret)
+			break;
+
+		ret = copy_to_user(udata, &uapi, sizeof(uapi)) ? -EFAULT : 0;
+
+		break;
+	}
 	default: {
 		dev_err(inf->edev->dev, "Invalid ioctl. cmd=%u, arg=%lu\n",
 			cmd, arg);
drivers/firmware/ethosu/ethosu_rpmsg.c +33 -0
index 368a519e36b1..351a1046e65e 100644
@@ -294,6 +294,39 @@ int ethosu_rpmsg_network_info_request(struct ethosu_rpmsg *erp,
 	return 0;
 }
 
+int ethosu_rpmsg_cancel_inference(struct ethosu_rpmsg *erp,
+				  struct ethosu_rpmsg_msg *rpmsg,
+				  int inference_handle)
+{
+	struct ethosu_core_msg msg = {
+		.magic  = ETHOSU_CORE_MSG_MAGIC,
+		.type   = ETHOSU_CORE_MSG_CAPABILITIES_REQ,
+		.length = sizeof(struct ethosu_core_cancel_inference_req)
+	};
+	struct ethosu_core_cancel_inference_req req;
+	struct rpmsg_device *rpdev = erp->rpdev;
+	u8 data[sizeof(struct ethosu_core_msg) +
+		sizeof(struct ethosu_core_cancel_inference_req)];
+	int ret;
+
+	req.user_arg = rpmsg->id;
+	req.inference_handle = inference_handle;
+
+	memcpy(data, &msg, sizeof(struct ethosu_core_msg));
+	memcpy(data + sizeof(struct ethosu_core_msg), &req,
+	       sizeof(struct ethosu_core_cancel_inference_req));
+
+	ret = rpmsg_send(rpdev->ept, (void *)&data,
+			 sizeof(struct ethosu_core_msg) +
+			 sizeof(struct ethosu_core_cancel_inference_req));
+	if (ret) {
+		dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
 static int rpmsg_ethosu_cb(struct rpmsg_device *rpdev,
 		void *data, int len, void *priv, u32 src)
 {
drivers/firmware/ethosu/ethosu_rpmsg.h +9 -0
index ba6fb8fd5869..283d401a0dbf 100644
@@ -101,6 +101,15 @@ int ethosu_rpmsg_network_info_request(struct ethosu_rpmsg *erp,
 				      struct ethosu_buffer *network,
 				      uint32_t network_index);
 
+/**
+ * ethosu_rpmsg_cancel_inference() - Send inference cancellation
+ *
+ * Return: 0 on success, else error code.
+ */
+int ethosu_rpmsg_cancel_inference(struct ethosu_rpmsg *erp,
+				  struct ethosu_rpmsg_msg *rpmsg,
+				  int inference_handle);
+
 int ethosu_rpmsg_init(struct ethosu_rpmsg *erp,
 		      ethosu_rpmsg_cb callback, void *user_arg);
 
drivers/firmware/ethosu/uapi/ethosu.h +29 -0
index 64a7d9d4885e..3375b1d83ab0 100644
@@ -60,10 +60,15 @@ namespace EthosU {
 						   struct ethosu_uapi_inference_create)
 #define ETHOSU_IOCTL_INFERENCE_STATUS   ETHOSU_IOR(0x31, \
 						   struct ethosu_uapi_result_status)
+#define ETHOSU_IOCTL_INFERENCE_CANCEL   ETHOSU_IOR(0x32, \
+						   struct ethosu_uapi_cancel_inference_status)
 
 /* Maximum number of IFM/OFM file descriptors per network */
 #define ETHOSU_FD_MAX                   16
 
+/* Maximum number of dimensions for input and output */
+#define ETHOSU_DIM_MAX                   8
+
 /* Maximum number of PMUs available */
 #define ETHOSU_PMU_EVENT_MAX             4
 
@@ -133,15 +138,31 @@ struct ethosu_uapi_network_create {
  * @desc:		Network description
  * @ifm_count:		Number of IFM buffers
  * @ifm_size:		IFM buffer sizes
+ * @ifm_types:          IFM data types
+ * @ifm_offset:         IFM data offset in arena
+ * @ifm_dims:           IFM buffer dimensions
+ * @ifm_shapes:         IFM buffer shapes
  * @ofm_count:		Number of OFM buffers
  * @ofm_size:		OFM buffer sizes
+ * @ofm_offset:         OFM data offset in arena
+ * @ofm_dims:           OFM buffer dimensions
+ * @ofm_shapes:         OFM buffer shapes
  */
 struct ethosu_uapi_network_info {
 	char  desc[32];
+	__u32 is_vela;
 	__u32 ifm_count;
 	__u32 ifm_size[ETHOSU_FD_MAX];
+	__u32 ifm_types[ETHOSU_FD_MAX];
+	__u32 ifm_offset[ETHOSU_FD_MAX];
+	__u32 ifm_dims[ETHOSU_FD_MAX];
+	__u32 ifm_shapes[ETHOSU_FD_MAX][ETHOSU_DIM_MAX];
 	__u32 ofm_count;
 	__u32 ofm_size[ETHOSU_FD_MAX];
+	__u32 ofm_types[ETHOSU_FD_MAX];
+	__u32 ofm_offset[ETHOSU_FD_MAX];
+	__u32 ofm_dims[ETHOSU_FD_MAX];
+	__u32 ofm_shapes[ETHOSU_FD_MAX][ETHOSU_DIM_MAX];
 };
 
 /**
@@ -250,6 +271,14 @@ struct ethosu_uapi_result_status {
 	struct ethosu_uapi_pmu_counts pmu_count;
 };
 
+/**
+ * struct ethosu_uapi_cancel_status - Status of inference cancellation.
+ * @status	OK if inference cancellation was performed, ERROR otherwise.
+ */
+struct ethosu_uapi_cancel_inference_status {
+	enum ethosu_uapi_status status;
+};
+
 #ifdef __cplusplus
 } /* namespace EthosU */
 #endif
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#18 lore raw

Re: [PATCH 7/8] ethosu: Add core message about inference cancellation

kernel test robot noticed the following build warnings:

Hi Alison,

kernel test robot noticed the following build warnings:

[auto build test WARNING on soc/for-next]
[also build test WARNING on linus/master v6.4-rc6 next-20230616] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Alison-Wang/ethosu-Add-Arm-Ethos-U-driver/20230616-141036
base:   https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next
patch link:    https://lore.kernel.org/r/20230616055913.2360-8-alison.wang%40nxp.com
patch subject: [PATCH 7/8] ethosu: Add core message about inference cancellation
config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20230616/[email protected]/config)
compiler: arceb-elf-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230616/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/firmware/ethosu/ethosu_network.c: In function 'ethosu_network_ioctl':

>> drivers/firmware/ethosu/ethosu_network.c:149:1: warning: the frame size of 1580 bytes is larger than 1024 bytes [-Wframe-larger-than=]
     149 | }
         | ^

vim +149 drivers/firmware/ethosu/ethosu_network.c

e66deaf1b03f9c Alison Wang 2023-06-16   91  
e66deaf1b03f9c Alison Wang 2023-06-16   92  static long ethosu_network_ioctl(struct file *file,
e66deaf1b03f9c Alison Wang 2023-06-16   93  				 unsigned int cmd,
e66deaf1b03f9c Alison Wang 2023-06-16   94  				 unsigned long arg)
e66deaf1b03f9c Alison Wang 2023-06-16   95  {
e66deaf1b03f9c Alison Wang 2023-06-16   96  	struct ethosu_network *net = file->private_data;
e66deaf1b03f9c Alison Wang 2023-06-16   97  	void __user *udata = (void __user *)arg;
e66deaf1b03f9c Alison Wang 2023-06-16   98  	int ret = -EINVAL;
e66deaf1b03f9c Alison Wang 2023-06-16   99  
e66deaf1b03f9c Alison Wang 2023-06-16  100  	ret = mutex_lock_interruptible(&net->edev->mutex);
e66deaf1b03f9c Alison Wang 2023-06-16  101  	if (ret)
e66deaf1b03f9c Alison Wang 2023-06-16  102  		return ret;
e66deaf1b03f9c Alison Wang 2023-06-16  103  
5d698f8bcb8aa1 Alison Wang 2023-06-16  104  	dev_dbg(net->edev->dev,
5d698f8bcb8aa1 Alison Wang 2023-06-16  105  		"Network ioctl: file=0x%pK, net=0x%pK, cmd=0x%x, arg=0x%lx\n",
5d698f8bcb8aa1 Alison Wang 2023-06-16  106  		file, net, cmd, arg);
e66deaf1b03f9c Alison Wang 2023-06-16  107  
e66deaf1b03f9c Alison Wang 2023-06-16  108  	switch (cmd) {
9bdfe23d58ca27 Alison Wang 2023-06-16  109  	case ETHOSU_IOCTL_NETWORK_INFO: {
9bdfe23d58ca27 Alison Wang 2023-06-16  110  		struct ethosu_uapi_network_info uapi;
9bdfe23d58ca27 Alison Wang 2023-06-16  111  
9bdfe23d58ca27 Alison Wang 2023-06-16  112  		if (copy_from_user(&uapi, udata, sizeof(uapi)))
9bdfe23d58ca27 Alison Wang 2023-06-16  113  			break;
9bdfe23d58ca27 Alison Wang 2023-06-16  114  
9bdfe23d58ca27 Alison Wang 2023-06-16  115  		dev_dbg(net->edev->dev,
9bdfe23d58ca27 Alison Wang 2023-06-16  116  			 "Network ioctl: Network info. net=0x%pK\n",
9bdfe23d58ca27 Alison Wang 2023-06-16  117  			 net);
9bdfe23d58ca27 Alison Wang 2023-06-16  118  
9bdfe23d58ca27 Alison Wang 2023-06-16  119  		ret = ethosu_network_info_request(net, &uapi);
9bdfe23d58ca27 Alison Wang 2023-06-16  120  		if (ret)
9bdfe23d58ca27 Alison Wang 2023-06-16  121  			break;
9bdfe23d58ca27 Alison Wang 2023-06-16  122  
9bdfe23d58ca27 Alison Wang 2023-06-16  123  		ret = copy_to_user(udata, &uapi, sizeof(uapi)) ? -EFAULT : 0;
9bdfe23d58ca27 Alison Wang 2023-06-16  124  		break;
9bdfe23d58ca27 Alison Wang 2023-06-16  125  	}
e66deaf1b03f9c Alison Wang 2023-06-16  126  	case ETHOSU_IOCTL_INFERENCE_CREATE: {
e66deaf1b03f9c Alison Wang 2023-06-16  127  		struct ethosu_uapi_inference_create uapi;
e66deaf1b03f9c Alison Wang 2023-06-16  128  
e66deaf1b03f9c Alison Wang 2023-06-16  129  		if (copy_from_user(&uapi, udata, sizeof(uapi)))
e66deaf1b03f9c Alison Wang 2023-06-16  130  			break;
e66deaf1b03f9c Alison Wang 2023-06-16  131  
5d698f8bcb8aa1 Alison Wang 2023-06-16  132  		dev_dbg(net->edev->dev,
5d698f8bcb8aa1 Alison Wang 2023-06-16  133  			"Network ioctl: Inference. ifm_fd=%u, ofm_fd=%u\n",
e66deaf1b03f9c Alison Wang 2023-06-16  134  			uapi.ifm_fd[0], uapi.ofm_fd[0]);
e66deaf1b03f9c Alison Wang 2023-06-16  135  
e66deaf1b03f9c Alison Wang 2023-06-16  136  		ret = ethosu_inference_create(net->edev, net, &uapi);
e66deaf1b03f9c Alison Wang 2023-06-16  137  		break;
e66deaf1b03f9c Alison Wang 2023-06-16  138  	}
e66deaf1b03f9c Alison Wang 2023-06-16  139  	default: {
e66deaf1b03f9c Alison Wang 2023-06-16  140  		dev_err(net->edev->dev, "Invalid ioctl. cmd=%u, arg=%lu",
e66deaf1b03f9c Alison Wang 2023-06-16  141  			cmd, arg);
e66deaf1b03f9c Alison Wang 2023-06-16  142  		break;
e66deaf1b03f9c Alison Wang 2023-06-16  143  	}
e66deaf1b03f9c Alison Wang 2023-06-16  144  	}
e66deaf1b03f9c Alison Wang 2023-06-16  145  
e66deaf1b03f9c Alison Wang 2023-06-16  146  	mutex_unlock(&net->edev->mutex);
e66deaf1b03f9c Alison Wang 2023-06-16  147  
e66deaf1b03f9c Alison Wang 2023-06-16  148  	return ret;

e66deaf1b03f9c Alison Wang 2023-06-16 @149 }
e66deaf1b03f9c Alison Wang 2023-06-16 150

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#19 lore raw

PATCH 8/8 ethosu: Add rwlock when alloc and remove msg id

In reply to Alison Wang

The msg id will be removed unpredictable when one thread calls ethosu_rpmsg_register and another thread calls ethosu_rpmsg_deregister at the same time. This patch adds write_lock in ethosu_rpmsg_register/ethosu_rpmsg_deregister and adds read_lcok in ethosu_rpmsg_find.

---
 drivers/firmware/ethosu/ethosu_driver.c |  2 +-
 drivers/firmware/ethosu/ethosu_rpmsg.c  | 20 ++++++++++++++------
 drivers/firmware/ethosu/ethosu_rpmsg.h  |  1 +
 3 files changed, 16 insertions(+), 7 deletions(-)
drivers/firmware/ethosu/ethosu_driver.c +1 -1
index 59ae79256564..0742564cfaf2 100644
@@ -155,7 +155,7 @@ static int __init ethosu_init(void)
 {
 	int ret;
 
-	ethosu_class = class_create(THIS_MODULE, ETHOSU_DRIVER_NAME);
+	ethosu_class = class_create(ETHOSU_DRIVER_NAME);
 	if (IS_ERR(ethosu_class)) {
 		printk("Failed to create class '%s'.\n", ETHOSU_DRIVER_NAME);
 
drivers/firmware/ethosu/ethosu_rpmsg.c +14 -6
index 351a1046e65e..d3e597e82762 100644
@@ -35,7 +35,9 @@ static void ethosu_core_set_capacity(struct ethosu_buffer *buf,
 int ethosu_rpmsg_register(struct ethosu_rpmsg *erp,
 			  struct ethosu_rpmsg_msg *msg)
 {
+	write_lock(&erp->lock);
 	msg->id = idr_alloc_cyclic(&erp->msg_idr, msg, 0, INT_MAX, GFP_KERNEL);
+	write_unlock(&erp->lock);
 	if (msg->id < 0)
 		return msg->id;
 
@@ -45,14 +47,19 @@ int ethosu_rpmsg_register(struct ethosu_rpmsg *erp,
 void ethosu_rpmsg_deregister(struct ethosu_rpmsg *erp,
 			     struct ethosu_rpmsg_msg *msg)
 {
+	write_lock(&erp->lock);
 	idr_remove(&erp->msg_idr, msg->id);
+	write_unlock(&erp->lock);
 }
 
 struct ethosu_rpmsg_msg *ethosu_rpmsg_find(struct ethosu_rpmsg *erp,
 					   int msg_id)
 {
-	struct ethosu_rpmsg_msg *ptr =
-		(struct ethosu_rpmsg_msg *)idr_find(&erp->msg_idr, msg_id);
+	struct ethosu_rpmsg_msg *ptr;
+
+	read_lock(&erp->lock);
+	ptr = (struct ethosu_rpmsg_msg *)idr_find(&erp->msg_idr, msg_id);
+	read_unlock(&erp->lock);
 
 	if (!ptr)
 		return ERR_PTR(-EINVAL);
@@ -97,8 +104,8 @@ static int ethosu_rpmsg_send(struct ethosu_rpmsg *erp, uint32_t type)
 	msg.type = type;
 	msg.length = 0;
 
-	print_hex_dump(KERN_DEBUG, __func__, DUMP_PREFIX_NONE, 16, 1,
-			(void *)&msg, sizeof(msg),  true);
+	print_hex_dump_debug(__func__, DUMP_PREFIX_NONE, 16, 1, (void *)&msg,
+			     sizeof(msg), true);
 
 	ret = rpmsg_send(rpdev->ept, (void *)&msg, sizeof(msg));
 	if (ret) {
@@ -337,8 +344,8 @@ static int rpmsg_ethosu_cb(struct rpmsg_device *rpdev,
 
 	dev_dbg(&rpdev->dev, "msg(<- src 0x%x) len %d\n", src, len);
 
-	print_hex_dump(KERN_DEBUG, __func__, DUMP_PREFIX_NONE, 16, 1,
-			data, len,  true);
+	print_hex_dump_debug(__func__, DUMP_PREFIX_NONE, 16, 1, data,
+			     len, true);
 
 	rpmsg->callback(rpmsg->user_arg, data);
 
@@ -391,6 +398,7 @@ int ethosu_rpmsg_init(struct ethosu_rpmsg *erp,
 	erp->user_arg = user_arg;
 	erp->ping_count = 0;
 	idr_init(&erp->msg_idr);
+        rwlock_init(&erp->lock);
 
 	return register_rpmsg_driver(&ethosu_rpmsg_driver);
 }
drivers/firmware/ethosu/ethosu_rpmsg.h +1 -0
index 283d401a0dbf..a4b879e9ef6c 100644
@@ -21,6 +21,7 @@ struct ethosu_core_msg;
 typedef void (*ethosu_rpmsg_cb)(void *user_arg, void *data);
 
 struct ethosu_rpmsg {
+	rwlock_t		lock;
 	struct rpmsg_device	*rpdev;
 	ethosu_rpmsg_cb		callback;
 	void			*user_arg;
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#20 lore raw
In reply to Alison Wang
Quoted 5 lines · Alison Wang

This series contains Arm's NPU Ethos-U driver for NXP i.MX93 platform.

Ethos-U Linux driver is to provide an example of how a rich operating system like Linux can dispatch inferences to an Arm Cortex-M subsystem, consisting of an Arm Cortex-M and an Arm Ethos-U NPU.

What is an "inference"?

Where are the userspace tools (if any) that are needed for this driver to work properly?

thanks,

greg k-h

#21 lore raw
Quoted 5 lines · Alison Wang

This series contains Arm's NPU Ethos-U driver for NXP i.MX93 platform.

Ethos-U Linux driver is to provide an example of how a rich operating system like Linux can dispatch inferences to an Arm Cortex-M subsystem, consisting of an Arm Cortex-M and an Arm Ethos-U NPU.

What is an "inference"?
[Alison Wang] The inference here means machine learning inference. It is the process of running data points into a machine learning model to calculate an output such as a single numerical score. For example, we use this driver, user space application and Cortex-M firmware to complete an inference about image classification.

Where are the userspace tools (if any) that are needed for this driver to work properly? [Alison Wang] You could refer to https://github.com/nxp-imx/ethos-u-driver-stack-imx.git .

thanks,

greg k-h

#22 lore raw
Quoted 8 lines · Alison Wang
Quoted 5 lines · Alison Wang

This series contains Arm's NPU Ethos-U driver for NXP i.MX93 platform.

Ethos-U Linux driver is to provide an example of how a rich operating system like Linux can dispatch inferences to an Arm Cortex-M subsystem, consisting of an Arm Cortex-M and an Arm Ethos-U NPU.

Quoted 5 lines

What is an "inference"?
[Alison Wang] The inference here means machine learning inference. It is the process of running data points into a machine learning model to calculate an output such as a single numerical score. For example, we use this driver, user space application and Cortex-M firmware to complete an inference about image classification.

Nice, so why isn't this under drivers/accel/ then? Does it not need that framework?

Quoted 2 lines

Where are the userspace tools (if any) that are needed for this driver to work properly? [Alison Wang] You could refer to https://github.com/nxp-imx/ethos-u-driver-stack-imx.git .

Please put that in the documentation for the commit.

thanks,

greg k-h

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#23 lore raw
Quoted 8 lines · Alison Wang
Quoted 5 lines · Alison Wang

This series contains Arm's NPU Ethos-U driver for NXP i.MX93 platform.

Ethos-U Linux driver is to provide an example of how a rich operating system like Linux can dispatch inferences to an Arm Cortex-M subsystem, consisting of an Arm Cortex-M and an Arm Ethos-U NPU.

Quoted 5 lines

What is an "inference"?
[Alison Wang] The inference here means machine learning inference. It
is the process of running data points into a machine learning model to
calculate an output such as a single numerical score. For example, we
use this driver, user space application and Cortex-M firmware to complete an inference about image classification.

Nice, so why isn't this under drivers/accel/ then? Does it not need that framework? [Alison Wang] This driver doesn't need that framework.

Quoted 2 lines

Where are the userspace tools (if any) that are needed for this driver to work properly? [Alison Wang] You could refer to https://github.com/nxp-imx/ethos-u-driver-stack-imx.git .

Please put that in the documentation for the commit. [Alison Wang] Sure, I will.

thanks,

greg k-h

#24 lore raw
Quoted 9 lines · Alison Wang
Quoted 8 lines · Alison Wang
Quoted 5 lines · Alison Wang

This series contains Arm's NPU Ethos-U driver for NXP i.MX93 platform.

Ethos-U Linux driver is to provide an example of how a rich operating system like Linux can dispatch inferences to an Arm Cortex-M subsystem, consisting of an Arm Cortex-M and an Arm Ethos-U NPU.

Quoted 8 lines
Quoted 5 lines

What is an "inference"?
[Alison Wang] The inference here means machine learning inference. It
is the process of running data points into a machine learning model to
calculate an output such as a single numerical score. For example, we
use this driver, user space application and Cortex-M firmware to complete an inference about image classification.

Nice, so why isn't this under drivers/accel/ then? Does it not need that framework? [Alison Wang] This driver doesn't need that framework.

Odd quoting style...

Anyway, why not use that famework? That's what that subsystem is for, so you are going to have to document why this does not fit into that model at all and you need your own interface instead.

thanks,

greg k-h