All of lore.kernel.org
 help / color / mirror / Atom feed
From: Karol Wachowski <karol.wachowski@linux.intel.com>
To: Alexander Usyskin <alexander.usyskin@intel.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org,
	Menachem Adin <menachem.adin@intel.com>,
	Andrzej Kacprowski <andrzej.kacprowski@linux.intel.com>
Subject: Re: [PATCH char-misc-next v3 3/4] issei: host_client: add dma allocation support
Date: Thu, 19 Nov 2026 10:09:51 +0100	[thread overview]
Message-ID: <bf484fbe-7ac1-4fa5-9d56-5cb9f11e6f7a@linux.intel.com> (raw)
In-Reply-To: <20261111-issei_pm_and_itf-v3-3-4f4f6d626ff3@intel.com>

On 11-Nov-26 8:40, Alexander Usyskin wrote:
> Add functions to allow dedicated DMA buffer allocated on current
> hardware device per host client.
> 
> Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
> ---
>   drivers/misc/issei/host_client.c | 66 ++++++++++++++++++++++++++++++++++++++++
>   drivers/misc/issei/host_client.h | 12 ++++++++
>   drivers/misc/issei/issei_dev.h   |  3 ++
>   3 files changed, 81 insertions(+)
> 
> diff --git a/drivers/misc/issei/host_client.c b/drivers/misc/issei/host_client.c
> index d16b5835c619..751296e3dc25 100644
> --- a/drivers/misc/issei/host_client.c
> +++ b/drivers/misc/issei/host_client.c
> @@ -2,6 +2,7 @@
>   /* Copyright (C) 2023-2026 Intel Corporation */
>   #include <linux/cleanup.h>
>   #include <linux/dev_printk.h>
> +#include <linux/dma-mapping.h>
>   #include <linux/err.h>
>   #include <linux/fs.h>
>   #include <linux/kobject.h>
> @@ -112,6 +113,17 @@ static void __issei_cl_disconnect(struct issei_device *idev, struct issei_host_c
>   	cl_dbg(idev, cl, "Disconnected\n");
>   }
>   
> +static void __issei_cl_dma_unmap(struct issei_host_client *cl)
> +{
> +	if (!cl->dma_size)
> +		return;
> +
> +	dma_free_coherent(cl->idev->parent, cl->dma_size, cl->dma_vaddr, cl->dma_daddr);
> +	cl->dma_size = 0;
> +	cl->dma_vaddr = NULL;
> +	cl->dma_daddr = 0;
> +}
> +
>   static void __issei_cl_init(struct issei_host_client *cl, struct issei_device *idev,
>   			    u16 id, struct file *fp)
>   {
> @@ -185,6 +197,8 @@ void issei_cl_remove(struct issei_host_client *cl)
>   
>   	__issei_cl_disconnect(idev, cl);
>   
> +	__issei_cl_dma_unmap(cl);
> +
>   	cl_dbg(idev, cl, "Removed\n");
>   	kfree(cl);
>   }
> @@ -521,3 +535,55 @@ void issei_cl_clean_all_wbuf(struct issei_host_client *cl)
>   
>   	__issei_cl_clean_all_wbuf(idev, cl);
>   }
> +
> +/**
> + * issei_cl_dma_map - allocate DMA mapping for client
> + *
> + * @cl: host client
> + * @size: memory size to allocate
> + * @daddr: pointer for buffer DMA address
> + * @vaddr: pointer for buffer virtual address
> + *
> + * Return: 0 on success, < 0 on error
> + */
> +int issei_cl_dma_map(struct issei_host_client *cl, size_t size,
> +		     dma_addr_t *daddr, void **vaddr)
> +{
> +	struct issei_device *idev = cl->idev;
> +
> +	if (size == 0 || size > ISSEI_HOST_DMA_MAX_SIZE) {
> +		cl_err(idev, cl, "The size is out of bounds.\n");
> +		return -EINVAL;
> +	}
> +
> +	guard(mutex)(&idev->client_lock);
> +
> +	if (cl->dma_size) {
> +		cl_err(idev, cl, "DMA already allocated.\n");
> +		return -EALREADY;
> +	}
> +
> +	cl->dma_vaddr = dma_alloc_coherent(cl->idev->parent, size, &cl->dma_daddr, GFP_KERNEL);
> +	if (!cl->dma_vaddr)
> +		return -ENOMEM;
> +
> +	cl->dma_size = size;
> +
> +	*daddr = cl->dma_daddr;
> +	*vaddr = cl->dma_vaddr;
> +	return 0;
> +}
> +
> +/**
> + * issei_cl_dma_unmap - deallocate DMA mapping for client
> + *
> + * @cl: host client
> + */
> +void issei_cl_dma_unmap(struct issei_host_client *cl)
> +{
> +	struct issei_device *idev = cl->idev;
> +
> +	guard(mutex)(&idev->client_lock);
> +
> +	__issei_cl_dma_unmap(cl);
> +}
> diff --git a/drivers/misc/issei/host_client.h b/drivers/misc/issei/host_client.h
> index 05e2f4ade9c3..987cee609676 100644
> --- a/drivers/misc/issei/host_client.h
> +++ b/drivers/misc/issei/host_client.h
> @@ -38,6 +38,10 @@ enum issei_host_client_state {
>    * @read_wait: waitqueue for read object
>    * @read_data: received data pointer
>    * @read_data_size: received data size
> + *
> + * @dma_vaddr: allocated DMA buffer virtual address
> + * @dma_daddr: allocated DMA buffer DMA address
> + * @dma_size: allocated DMA buffer size, zero if no buffer allocated
>    */
>   struct issei_host_client {
>   	struct list_head list;
> @@ -54,6 +58,10 @@ struct issei_host_client {
>   	wait_queue_head_t read_wait;
>   	u8 *read_data;
>   	size_t read_data_size;
> +
> +	void *dma_vaddr;
> +	dma_addr_t dma_daddr;
> +	size_t dma_size;
>   };
>   
>   struct issei_host_client *issei_cl_create(struct issei_device *idev, struct file *fp);
> @@ -72,4 +80,8 @@ int issei_cl_check_read(struct issei_host_client *cl);
>   int issei_cl_check_write(struct issei_host_client *cl);
>   void issei_cl_clean_all_wbuf(struct issei_host_client *cl);
>   
> +int issei_cl_dma_map(struct issei_host_client *cl, size_t size,
> +		     dma_addr_t *daddr, void **vaddr);
> +void issei_cl_dma_unmap(struct issei_host_client *cl);
> +
>   #endif /* ISSEI_HOST_CLIENT_H_ */
> diff --git a/drivers/misc/issei/issei_dev.h b/drivers/misc/issei/issei_dev.h
> index b47c4a7c2da4..244dc62ad85f 100644
> --- a/drivers/misc/issei/issei_dev.h
> +++ b/drivers/misc/issei/issei_dev.h
> @@ -6,6 +6,7 @@
>   #include <linux/device.h>
>   #include <linux/mutex.h>
>   #include <linux/sched.h>
> +#include <linux/sizes.h>
>   #include <linux/time64.h>
>   #include <linux/types.h>
>   #include <linux/wait.h>
> @@ -31,6 +32,8 @@ extern struct class *issei_class;
>   #define ISSEI_STOP_TIMEOUT_MSEC         500
>   #define ISSEI_WRITE_TIMEOUT_MSEC        (MSEC_PER_SEC)
>   
> +#define ISSEI_HOST_DMA_MAX_SIZE	        SZ_64M
> +
>   /**
>    * struct issei_write_buf - write buffer object
>    * @list: linked list pointer
> 

Reviewed-by: Karol Wachowski <karol.wachowski@linux.intel.com>

  reply	other threads:[~2026-11-19  9:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  7:40 [PATCH char-misc-next v3 0/4] issei: runtime power management, dma and in-kernel interface Alexander Usyskin
2026-11-11  7:40 ` [PATCH char-misc-next v3 1/4] issei: save power_down flag while processing event Alexander Usyskin
2026-11-19  9:09   ` Karol Wachowski
2026-11-11  7:40 ` [PATCH char-misc-next v3 2/4] issei: add runtime pm Alexander Usyskin
2026-11-19  9:11   ` Karol Wachowski
2026-11-11  7:40 ` [PATCH char-misc-next v3 3/4] issei: host_client: add dma allocation support Alexander Usyskin
2026-11-19  9:09   ` Karol Wachowski [this message]
2026-11-11  7:40 ` [PATCH char-misc-next v3 4/4] issei: add driver to driver interface Alexander Usyskin
2026-11-19  9:10   ` Karol Wachowski

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=bf484fbe-7ac1-4fa5-9d56-5cb9f11e6f7a@linux.intel.com \
    --to=karol.wachowski@linux.intel.com \
    --cc=alexander.usyskin@intel.com \
    --cc=andrzej.kacprowski@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=menachem.adin@intel.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.