Re: [PATCH v2, RESEND] misc: new driver sram_uapi for user level SRAM access
From: Arnd Bergmann <arnd@arndb.de>
Date: 2020-04-20 14:35:14
Also in:
lkml
On Mon, Apr 20, 2020 at 5:06 AM Wang Wenhu [off-list ref] wrote:
A generic User-Kernel interface that allows a misc device created by it to support file-operations of ioctl and mmap to access SRAM memory from user level. Different kinds of SRAM alloction and free APIs could be registered by specific SRAM hardware level driver to the available list and then be chosen by users to allocate and map SRAM memory from user level. It is extremely helpful for the user space applications that require high performance memory accesses, such as embedded networking devices that would process data in user space, and PowerPC e500 is a case. Signed-off-by: Wang Wenhu <redacted> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Christophe Leroy <redacted> Cc: Scott Wood <oss@buserror.net> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Randy Dunlap <redacted> Cc: linuxppc-dev@lists.ozlabs.org --- Changes since v1: addressed comments from Arnd * Changed the ioctl cmd definitions using _IO micros * Export interfaces for HW-SRAM drivers to register apis to available list * Modified allocation alignment to PAGE_SIZE * Use phys_addr_t as type of SRAM resource size and offset * Support compat_ioctl * Misc device name:sram
Looks much better already.
Note: From this on, the SRAM_UAPI driver is independent to any hardware drivers, so I would only commit the patch itself as v2, while the v1 of it was wrapped together with patches for Freescale L2-Cache-SRAM device. Then after, I'd create patches for Freescale L2-Cache-SRAM device as another series.
What I meant to suggest was actually to tie it more closely to the code we already have in drivers/misc/sram.c, which already has some form of abstraction.
+static int __init sram_uapi_init(void)
+{
+ int ret;
+
+ INIT_LIST_HEAD(&sram_api_list);
+ mutex_init(&sram_api_list_lock);
+
+ ret = misc_register(&sram_uapi_miscdev);
+ if (ret)
+ pr_err("failed to register sram uapi misc device\n");
The mutex and listhead are already initialized, so this can
be a one-line function
return misc_register(&sram_uapi_miscdev);
quoted hunk ↗ jump to hunk
--- /dev/null +++ b/include/linux/sram_uapi.h
The ioctl definitions need to be in include/uapi/linux/
quoted hunk ↗ jump to hunk
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __SRAM_UAPI_H +#define __SRAM_UAPI_H + +/* Set SRAM type to be accessed */ +#define SRAM_UAPI_IOC_SET_SRAM_TYPE _IOW('S', 0, __u32) + +/* Allocate resource from SRAM */ +#define SRAM_UAPI_IOC_ALLOC _IOWR('S', 1, struct res_info) + +/* Free allocated resource of SRAM */ +#define SRAM_UAPI_IOC_FREE _IOW('S', 2, struct res_info)
struct res_info needs to also be defined here, so user applications can
see the definition, and it has to use __u64, not phys_addr_t, to ensure
the API does not depend on kernel configuraiton.
Arnd