All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiho Chu <jiho.chu@samsung.com>
To: "Arnd Bergmann" <arnd@arndb.de>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	ogabbay@kernel.org,
	"Krzysztof Kozlowski" <krzysztof.kozlowski@linaro.org>,
	"Mark Brown" <broonie@kernel.org>,
	linux-kernel@vger.kernel.org, yelini.jeong@samsung.com,
	myungjoo.ham@samsung.com
Subject: Re: [PATCH v2 01/13] trinity: Add base driver
Date: Sat, 17 Sep 2022 23:49:18 +0900	[thread overview]
Message-ID: <20220917234918.8b94d2690b8533bd47cf64e0@samsung.com> (raw)
In-Reply-To: <e035ac54-35af-4e86-a74a-9a4c7f936a19@www.fastmail.com>

On Sat, 17 Sep 2022 09:41:13 +0200
"Arnd Bergmann" <arnd@arndb.de> wrote:

> On Sat, Sep 17, 2022, at 9:23 AM, Jiho Chu wrote:
> > It contains the base codes for trinity driver. Minimal codes to load and
> > probe device is provided. The Trinity Family is controlled by the
> > Memory-Mapped Registers, the register addresses and offsets are
> > described. And user api interfaces are presented to control device under
> > ioctl manner.
> 
> I'm not doing a full review of the driver at the moment, but
> here are some comments on the usage of chardev ioctl based on
> Documentation/driver-api/ioctl.rst
> 

Hi, Arnd
Thanks for your review.
I'll read the document more precisely.

> > +int trinity_probe(struct platform_device *pdev, const struct 
> > trinity_desc *desc)
> > +{
> > +	struct device_node *np;
> > +	struct device *dev;
> > +	struct trinity_driver *drv;
> > +	int i, err;
> > +
> > +	dev = &pdev->dev;
> > +	dev->id = ((desc->ver & TRINITY_MASK_DEV) >> TRINITY_SHIFT_DEV);
> > +
> > +	/* set private data */
> > +	drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL);
> > +	if (!drv)
> > +		return -ENOMEM;
> > +
> > +	drv->dev_id = ida_alloc(&dev_nrs, GFP_KERNEL);
> > +	if (drv->dev_id < 0) {
> > +		devm_kfree(dev, drv);
> > +		return drv->dev_id;
> > +	}
> > +	snprintf(drv->name, DEV_NAME_LEN, "%s-%u", desc->type, drv->dev_id);
> > +
> > +	platform_set_drvdata(pdev, drv);
> > +	dev_set_drvdata(dev, drv);
> > +
> 
> If you have the need to manage multiple devices here, maybe use
> a dynamic major number and have the chardev code allocate the
> minor numbers, instead of using multiple misc devices and
> doing that yourself.
> 

I'm little confusing. It means that managing own char devices is proper,
not using misc device? But, it's still under misc dir.

> > +
> > +#ifndef TASK_COMM_LEN
> > +#define TASK_COMM_LEN 16
> > +#endif
> > +
> > +#define TRINITY_APP_NAME_MAX TASK_COMM_LEN
> > +#define TRINITY_APP_STAT_MAX 10
> > +#define TRINITY_REQ_STAT_MAX 10
> 
> The structure layout should not depend on whether an application
> has included a header that defines TASK_COMM_LEN.
> 
> What is the purpose of including an application name here?
> 
> > +/**
> > + * struct trinity_ioctl_stat_app - Describes stat of the target app
> > + * @app_id: Trinity app id (currently, equal to pid)
> > + * @name: Trinity app name
> > + * @status: Trinity app status
> > + * @num_total_reqs: Number of total requests in app (including 
> > finished ones)
> > + * @num_active_reqs: Number of active (running or pending) requests in 
> > app
> > + * @total_alloc_mem: Total size of allocated memory in the device
> > + * @total_freed_mem: Total size of freed memory in the device
> > + */
> > +struct trinity_ioctl_stat_app {
> > +	__s32 app_id;
> > +
> > +	char name[TRINITY_APP_NAME_MAX];
> > +	enum trinity_app_status status;
> > +
> > +	__u32 num_total_reqs;
> > +	__u32 num_active_reqs;
> > +
> > +	__u64 total_alloc_mem;
> > +	__u64 total_freed_mem;
> > +} __packed;
> 
> 'enum' in a uapi structure is not well-defined across
> architectures, so better use a fixed-size type there.
> 
> Instead of packing the structure, you should keep all
> members naturally aligned and add explicit padding
> or change some members for 32-bit to 64-bit size
> to keep everything naturally aligned.
> 

I checked, the members will be aligned.


> > +/**
> > + * struct trinity_ioctl_profile_buff - Describes profiling buff info.
> > + * @req_id: The target req id for profiling
> > + * @profile_pos: The start position to extract profiling data
> > + * @profile_size: The size of user-allocated profiling buffer
> > + * @profile_buf: The profiling buffer which user allocated
> > + */
> > +struct trinity_ioctl_profile_buff {
> > +	__s32 req_id;
> > +	__u32 profile_pos;
> > +	__u32 profile_size;
> > +	void __user *profile_buf;
> > +} __packed;
> 
> Don't put pointers into ioctl structures, they just make compat
> mode unnecessarily hard. You can use a __u64 member.
> 

OK. thanks.

> > +/**
> > + * Major number can not be dynamic as ioctls need it,
> > + */
> > +#define TRINITY_DRIVER_MAGIC 0x88
> > +
> > +#define TRINITY_IO(no) _IO(TRINITY_DRIVER_MAGIC, no)
> > +#define TRINITY_IOR(no, data_type) _IOR(TRINITY_DRIVER_MAGIC, no, 
> > data_type)
> > +#define TRINITY_IOW(no, data_type) _IOW(TRINITY_DRIVER_MAGIC, no, 
> > data_type)
> > +#define TRINITY_IOWR(no, data_type) _IOWR(TRINITY_DRIVER_MAGIC, no, 
> > data_type)
> 
> These macros just hurt tools that want to parse the headers.
> Please just open-code the usage.
> 
> > +#ifdef __KERNEL__
> > +__s32 trinity_run_internal_req(dev_t);
> > +#endif
> 
> This doesn't seem to belong into the uapi header.
> 
>       Arnd
> 

macros and useless codes will be cleared.

Thanks.
Jiho Chu








  reply	other threads:[~2022-09-17 14:49 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20220917072357epcas1p3fea7d947782d9ce58d91249533e0c1f7@epcas1p3.samsung.com>
2022-09-17  7:23 ` [PATCH v2 00/13] Samsung Trinity NPU device driver-v2 Jiho Chu
     [not found]   ` <CGME20220917072357epcas1p17b277154f0d020435417450fa0337906@epcas1p1.samsung.com>
2022-09-17  7:23     ` [PATCH v2 01/13] trinity: Add base driver Jiho Chu
2022-09-17  7:41       ` Arnd Bergmann
2022-09-17 14:49         ` Jiho Chu [this message]
2022-09-22 13:56           ` Arnd Bergmann
2022-09-23 15:09             ` Jiho Chu
2022-09-19  4:26         ` Jiho Chu
2022-09-18 10:35       ` Greg KH
2022-09-19  2:00         ` Jiho Chu
     [not found]         ` <CGME20220917072357epcas1p17b277154f0d020435417450fa0337906@epcms1p1>
2022-09-19  2:57           ` MyungJoo Ham
     [not found]   ` <CGME20220917072357epcas1p1bc8d924080c5dabafee1db779369078d@epcas1p1.samsung.com>
2022-09-17  7:23     ` [PATCH v2 02/13] tirnity: Add memory module Jiho Chu
     [not found]   ` <CGME20220917072357epcas1p4a5b3939adbe5e24c11bd2541f76f23f6@epcas1p4.samsung.com>
2022-09-17  7:23     ` [PATCH v2 03/13] trinity: Add IDU feature Jiho Chu
     [not found]   ` <CGME20220917072357epcas1p378e13844913c3c80acd183ddd59de456@epcas1p3.samsung.com>
2022-09-17  7:23     ` [PATCH v2 04/13] trinity: Add schduler module Jiho Chu
     [not found]   ` <CGME20220917072357epcas1p2735d98b043e2382aba1173c6b52af81a@epcas1p2.samsung.com>
2022-09-17  7:23     ` [PATCH v2 05/13] trinity: Add debugfs module Jiho Chu
     [not found]   ` <CGME20220917072357epcas1p2ec70909280eee82b0db5ad454247daf8@epcas1p2.samsung.com>
2022-09-17  7:23     ` [PATCH v2 06/13] trinity: add statistics module Jiho Chu
     [not found]   ` <CGME20220917072357epcas1p485a1cdcb71cc01274db1c8d00aec197c@epcas1p4.samsung.com>
2022-09-17  7:23     ` [PATCH v2 07/13] trinity: Add sysfs module Jiho Chu
2022-09-18 10:33       ` Greg KH
2022-09-19  6:44         ` Jiho Chu
     [not found]   ` <CGME20220917072358epcas1p14543c842bdf0b6f719d4e0d2ed3bf33c@epcas1p1.samsung.com>
2022-09-17  7:23     ` [PATCH v2 08/13] trinity: Add ioctl feature Jiho Chu
     [not found]   ` <CGME20220917072358epcas1p2ae33a31333089ea7b10844e42e14323b@epcas1p2.samsung.com>
2022-09-17  7:23     ` [PATCH v2 09/13] trinity: Add request and pm feature Jiho Chu
     [not found]   ` <CGME20220917072358epcas1p14997459c7add27bf7b4e9333cbf21b72@epcas1p1.samsung.com>
2022-09-17  7:23     ` [PATCH v2 10/13] trinity: Add profile module Jiho Chu
     [not found]   ` <CGME20220917072358epcas1p4e110e2025c90d78fad2182ec5cd66eb7@epcas1p4.samsung.com>
2022-09-17  7:23     ` [PATCH v2 11/13] trinity: Add trace module Jiho Chu
     [not found]   ` <CGME20220917072358epcas1p30b24a99cbf5a0ae7175efc794c5d218d@epcas1p3.samsung.com>
2022-09-17  7:23     ` [PATCH v2 12/13] MAINTAINERS: add TRINITY driver Jiho Chu
     [not found]   ` <CGME20220917072358epcas1p15d18d4cf27694f894332f975bb971bef@epcas1p1.samsung.com>
2022-09-17  7:23     ` [PATCH v2 13/13] dt-bindings: arm: Add Samsung Trinity bindings Jiho Chu
2022-09-21 18:42       ` Krzysztof Kozlowski
2022-09-22  2:20         ` Jiho Chu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220917234918.8b94d2690b8533bd47cf64e0@samsung.com \
    --to=jiho.chu@samsung.com \
    --cc=arnd@arndb.de \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=myungjoo.ham@samsung.com \
    --cc=ogabbay@kernel.org \
    --cc=yelini.jeong@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.