Re: [PATCH v11 15/15] media: vim2m-audio: add virtual driver for audio memory to memory

2024-01-17 Thread Hans Verkuil
On 18/01/2024 07:13, Shengjiu Wang wrote:
> On Wed, Jan 17, 2024 at 6:32 PM Hans Verkuil  wrote:
>>
>> On 22/11/2023 08:23, Shengjiu Wang wrote:
>>> Audio memory to memory virtual driver use video memory to memory
>>> virtual driver vim2m.c as example. The main difference is
>>> device type is VFL_TYPE_AUDIO and device cap type is V4L2_CAP_AUDIO_M2M.
>>>
>>> The device_run function is a dummy function, which is simply
>>> copy the data from input buffer to output buffer.
>>>
>>> Signed-off-by: Shengjiu Wang 
>>> ---
>>>  drivers/media/test-drivers/Kconfig   |  11 +
>>>  drivers/media/test-drivers/Makefile  |   1 +
>>>  drivers/media/test-drivers/vim2m-audio.c | 799 +++
>>>  3 files changed, 811 insertions(+)
>>>  create mode 100644 drivers/media/test-drivers/vim2m-audio.c
>>>
>>> diff --git a/drivers/media/test-drivers/Kconfig 
>>> b/drivers/media/test-drivers/Kconfig
>>> index 459b433e9fae..55f8af6ee4e2 100644
>>> --- a/drivers/media/test-drivers/Kconfig
>>> +++ b/drivers/media/test-drivers/Kconfig
>>> @@ -17,6 +17,17 @@ config VIDEO_VIM2M
>>> This is a virtual test device for the memory-to-memory driver
>>> framework.
>>>
>>> +config VIDEO_VIM2M_AUDIO
>>> + tristate "Virtual Memory-to-Memory Driver For Audio"
>>> + depends on VIDEO_DEV
>>> + select VIDEOBUF2_VMALLOC
>>> + select V4L2_MEM2MEM_DEV
>>> + select MEDIA_CONTROLLER
>>> + select MEDIA_CONTROLLER_REQUEST_API
>>
>> Drop this. This option has been removed.
>>
>>> + help
>>> +   This is a virtual audio test device for the memory-to-memory driver
>>> +   framework.
>>> +
>>>  source "drivers/media/test-drivers/vicodec/Kconfig"
>>>  source "drivers/media/test-drivers/vimc/Kconfig"
>>>  source "drivers/media/test-drivers/vivid/Kconfig"
>>> diff --git a/drivers/media/test-drivers/Makefile 
>>> b/drivers/media/test-drivers/Makefile
>>> index 740714a4584d..0c61c9ada3e1 100644
>>> --- a/drivers/media/test-drivers/Makefile
>>> +++ b/drivers/media/test-drivers/Makefile
>>> @@ -10,6 +10,7 @@ obj-$(CONFIG_DVB_VIDTV) += vidtv/
>>>
>>>  obj-$(CONFIG_VIDEO_VICODEC) += vicodec/
>>>  obj-$(CONFIG_VIDEO_VIM2M) += vim2m.o
>>> +obj-$(CONFIG_VIDEO_VIM2M_AUDIO) += vim2m-audio.o
>>>  obj-$(CONFIG_VIDEO_VIMC) += vimc/
>>>  obj-$(CONFIG_VIDEO_VIVID) += vivid/
>>>  obj-$(CONFIG_VIDEO_VISL) += visl/
>>> diff --git a/drivers/media/test-drivers/vim2m-audio.c 
>>> b/drivers/media/test-drivers/vim2m-audio.c
>>> new file mode 100644
>>> index ..72806ada8628
>>> --- /dev/null
>>> +++ b/drivers/media/test-drivers/vim2m-audio.c
>>> @@ -0,0 +1,799 @@
>>> +// SPDX-License-Identifier: GPL-2.0+
>>> +/*
>>> + * A virtual v4l2-mem2mem example for audio device.
>>> + */
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +MODULE_DESCRIPTION("Virtual device for audio mem2mem testing");
>>> +MODULE_LICENSE("GPL");
>>> +
>>> +static unsigned int debug;
>>> +module_param(debug, uint, 0644);
>>> +MODULE_PARM_DESC(debug, "debug level");
>>> +
>>> +#define MEM2MEM_NAME "vim2m-audio"
>>> +
>>> +#define dprintk(dev, lvl, fmt, arg...) \
>>> + v4l2_dbg(lvl, debug, &(dev)->v4l2_dev, "%s: " fmt, __func__, ## arg)
>>> +
>>> +#define SAMPLE_NUM 4096
>>> +
>>> +static void audm2m_dev_release(struct device *dev)
>>> +{}
>>> +
>>> +static struct platform_device audm2m_pdev = {
>>> + .name   = MEM2MEM_NAME,
>>> + .dev.release= audm2m_dev_release,
>>> +};
>>> +
>>> +static u32 formats[] = {
>>> + V4L2_AUDIO_FMT_S16_LE,
>>> +};
>>> +
>>> +#define NUM_FORMATS ARRAY_SIZE(formats)
>>> +
>>> +/* Per-queue, driver-specific private data */
>>> +struct audm2m_q_data {
>>> + unsigned intrate;
>>> + unsigned intchannels;
>>> + unsigned intbuffersize;
>>> + unsigned intsequence;
>>> + u32 fourcc;
>>> +};
>>> +
>>> +enum {
>>> + V4L2_M2M_SRC = 0,
>>> + V4L2_M2M_DST = 1,
>>> +};
>>> +
>>> +static snd_pcm_format_t find_format(u32 fourcc)
>>> +{
>>> + snd_pcm_format_t fmt;
>>> + unsigned int k;
>>> +
>>> + for (k = 0; k < NUM_FORMATS; k++) {
>>> + if (formats[k] == fourcc)
>>> + break;
>>> + }
>>> +
>>> + if (k == NUM_FORMATS)
>>> + return 0;
>>> +
>>> + fmt = v4l2_fourcc_to_audfmt(formats[k]);
>>> +
>>> + return fmt;
>>> +}
>>> +
>>> +struct audm2m_dev {
>>> + struct v4l2_device  v4l2_dev;
>>> + struct video_device vfd;
>>> +
>>> + struct mutexdev_mutex;
>>> +
>>> + struct v4l2_m2m_dev *m2m_dev;
>>> +#ifdef CONFIG_MEDIA_CONTROLLER
>>> + struct media_device mdev;
>>> +#endif
>>> +};
>>> +
>>> +struct audm2m_ctx {
>>> + struct v4l2_fh  fh;
>>> + struct v4l2_ctrl_handlerctrl_handler;
>>> + struct 

Re: [PATCH v11 15/15] media: vim2m-audio: add virtual driver for audio memory to memory

2024-01-17 Thread Shengjiu Wang
On Wed, Jan 17, 2024 at 6:32 PM Hans Verkuil  wrote:
>
> On 22/11/2023 08:23, Shengjiu Wang wrote:
> > Audio memory to memory virtual driver use video memory to memory
> > virtual driver vim2m.c as example. The main difference is
> > device type is VFL_TYPE_AUDIO and device cap type is V4L2_CAP_AUDIO_M2M.
> >
> > The device_run function is a dummy function, which is simply
> > copy the data from input buffer to output buffer.
> >
> > Signed-off-by: Shengjiu Wang 
> > ---
> >  drivers/media/test-drivers/Kconfig   |  11 +
> >  drivers/media/test-drivers/Makefile  |   1 +
> >  drivers/media/test-drivers/vim2m-audio.c | 799 +++
> >  3 files changed, 811 insertions(+)
> >  create mode 100644 drivers/media/test-drivers/vim2m-audio.c
> >
> > diff --git a/drivers/media/test-drivers/Kconfig 
> > b/drivers/media/test-drivers/Kconfig
> > index 459b433e9fae..55f8af6ee4e2 100644
> > --- a/drivers/media/test-drivers/Kconfig
> > +++ b/drivers/media/test-drivers/Kconfig
> > @@ -17,6 +17,17 @@ config VIDEO_VIM2M
> > This is a virtual test device for the memory-to-memory driver
> > framework.
> >
> > +config VIDEO_VIM2M_AUDIO
> > + tristate "Virtual Memory-to-Memory Driver For Audio"
> > + depends on VIDEO_DEV
> > + select VIDEOBUF2_VMALLOC
> > + select V4L2_MEM2MEM_DEV
> > + select MEDIA_CONTROLLER
> > + select MEDIA_CONTROLLER_REQUEST_API
>
> Drop this. This option has been removed.
>
> > + help
> > +   This is a virtual audio test device for the memory-to-memory driver
> > +   framework.
> > +
> >  source "drivers/media/test-drivers/vicodec/Kconfig"
> >  source "drivers/media/test-drivers/vimc/Kconfig"
> >  source "drivers/media/test-drivers/vivid/Kconfig"
> > diff --git a/drivers/media/test-drivers/Makefile 
> > b/drivers/media/test-drivers/Makefile
> > index 740714a4584d..0c61c9ada3e1 100644
> > --- a/drivers/media/test-drivers/Makefile
> > +++ b/drivers/media/test-drivers/Makefile
> > @@ -10,6 +10,7 @@ obj-$(CONFIG_DVB_VIDTV) += vidtv/
> >
> >  obj-$(CONFIG_VIDEO_VICODEC) += vicodec/
> >  obj-$(CONFIG_VIDEO_VIM2M) += vim2m.o
> > +obj-$(CONFIG_VIDEO_VIM2M_AUDIO) += vim2m-audio.o
> >  obj-$(CONFIG_VIDEO_VIMC) += vimc/
> >  obj-$(CONFIG_VIDEO_VIVID) += vivid/
> >  obj-$(CONFIG_VIDEO_VISL) += visl/
> > diff --git a/drivers/media/test-drivers/vim2m-audio.c 
> > b/drivers/media/test-drivers/vim2m-audio.c
> > new file mode 100644
> > index ..72806ada8628
> > --- /dev/null
> > +++ b/drivers/media/test-drivers/vim2m-audio.c
> > @@ -0,0 +1,799 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * A virtual v4l2-mem2mem example for audio device.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +MODULE_DESCRIPTION("Virtual device for audio mem2mem testing");
> > +MODULE_LICENSE("GPL");
> > +
> > +static unsigned int debug;
> > +module_param(debug, uint, 0644);
> > +MODULE_PARM_DESC(debug, "debug level");
> > +
> > +#define MEM2MEM_NAME "vim2m-audio"
> > +
> > +#define dprintk(dev, lvl, fmt, arg...) \
> > + v4l2_dbg(lvl, debug, &(dev)->v4l2_dev, "%s: " fmt, __func__, ## arg)
> > +
> > +#define SAMPLE_NUM 4096
> > +
> > +static void audm2m_dev_release(struct device *dev)
> > +{}
> > +
> > +static struct platform_device audm2m_pdev = {
> > + .name   = MEM2MEM_NAME,
> > + .dev.release= audm2m_dev_release,
> > +};
> > +
> > +static u32 formats[] = {
> > + V4L2_AUDIO_FMT_S16_LE,
> > +};
> > +
> > +#define NUM_FORMATS ARRAY_SIZE(formats)
> > +
> > +/* Per-queue, driver-specific private data */
> > +struct audm2m_q_data {
> > + unsigned intrate;
> > + unsigned intchannels;
> > + unsigned intbuffersize;
> > + unsigned intsequence;
> > + u32 fourcc;
> > +};
> > +
> > +enum {
> > + V4L2_M2M_SRC = 0,
> > + V4L2_M2M_DST = 1,
> > +};
> > +
> > +static snd_pcm_format_t find_format(u32 fourcc)
> > +{
> > + snd_pcm_format_t fmt;
> > + unsigned int k;
> > +
> > + for (k = 0; k < NUM_FORMATS; k++) {
> > + if (formats[k] == fourcc)
> > + break;
> > + }
> > +
> > + if (k == NUM_FORMATS)
> > + return 0;
> > +
> > + fmt = v4l2_fourcc_to_audfmt(formats[k]);
> > +
> > + return fmt;
> > +}
> > +
> > +struct audm2m_dev {
> > + struct v4l2_device  v4l2_dev;
> > + struct video_device vfd;
> > +
> > + struct mutexdev_mutex;
> > +
> > + struct v4l2_m2m_dev *m2m_dev;
> > +#ifdef CONFIG_MEDIA_CONTROLLER
> > + struct media_device mdev;
> > +#endif
> > +};
> > +
> > +struct audm2m_ctx {
> > + struct v4l2_fh  fh;
> > + struct v4l2_ctrl_handlerctrl_handler;
> > + struct audm2m_dev   *dev;
> > +
> > + struct mutex

[PATCH] init: refactor the generic cpu_to_node for NUMA

2024-01-17 Thread Huang Shijie
(0) We list the ARCHs which support the NUMA:
   arm64, loongarch, powerpc, riscv,
   sparc, mips, s390, x86,

(1) Some ARCHs in (0) override the generic cpu_to_node(), such as:
   sparc, mips, s390, x86.

Since these ARCHs have their own cpu_to_node(), we do not care
about them.

(2) The ARCHs enable NUMA and use the generic cpu_to_node.
From (0) and (1), we can know that four ARCHs support NUMA and
use the generic cpu_to_node:
arm64, loongarch, powerpc, riscv,

The generic cpu_to_node depends on percpu "numa_node".

(2.1) The loongarch sets "numa_node" in:
  start_kernel --> smp_prepare_boot_cpu()

(2.2) The arm64, powerpc, riscv set "numa_node" in:
  start_kernel --> arch_call_rest_init() --> rest_init()
   --> kernel_init() --> kernel_init_freeable()
   --> smp_prepare_cpus()

(2.3) The first place calling the cpu_to_node() is early_trace_init():
  start_kernel --> early_trace_init()--> __ring_buffer_alloc()
   --> rb_allocate_cpu_buffer()

(2.4) So it safe for loongarch. But for arm64, powerpc and riscv,
  there are at least four places in the common code where
  the cpu_to_node() is called before it is initialized:
   a.) early_trace_init() in kernel/trace/trace.c
   b.) sched_init()   in kernel/sched/core.c
   c.) init_sched_fair_class()in kernel/sched/fair.c
   d.) workqueue_init_early() in kernel/workqueue.c

(3) In order to fix the issue, the patch refactors the generic cpu_to_node:
(3.1) change cpu_to_node to function pointer,
  and export it for kernel modules.

(3.2) introduce _cpu_to_node() which is the original cpu_to_node().

(3.3) introduce smp_prepare_boot_cpu_start() to wrap the original
  smp_prepare_boot_cpu(), and set cpu_to_node with
  early_cpu_to_node which works fine for arm64, powerpc,
  riscv and loongarch.

(3.4) introduce smp_prepare_cpus_done() to wrap the original
  smp_prepare_cpus().
  The "numa_node" is ready after smp_prepare_cpus(),
  then set cpu_to_node with _cpu_to_node().

Signed-off-by: Huang Shijie 
---
 drivers/base/arch_numa.c | 11 +++
 include/linux/topology.h |  6 ++
 init/main.c  | 29 +++--
 3 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/drivers/base/arch_numa.c b/drivers/base/arch_numa.c
index 5b59d133b6af..867a477fa975 100644
--- a/drivers/base/arch_numa.c
+++ b/drivers/base/arch_numa.c
@@ -61,6 +61,17 @@ EXPORT_SYMBOL(cpumask_of_node);
 
 #endif
 
+#ifdef CONFIG_USE_PERCPU_NUMA_NODE_ID
+#ifndef cpu_to_node
+int _cpu_to_node(int cpu)
+{
+   return per_cpu(numa_node, cpu);
+}
+int (*cpu_to_node)(int cpu);
+EXPORT_SYMBOL(cpu_to_node);
+#endif
+#endif
+
 static void numa_update_cpu(unsigned int cpu, bool remove)
 {
int nid = cpu_to_node(cpu);
diff --git a/include/linux/topology.h b/include/linux/topology.h
index 52f5850730b3..e7ce2bae11dd 100644
--- a/include/linux/topology.h
+++ b/include/linux/topology.h
@@ -91,10 +91,8 @@ static inline int numa_node_id(void)
 #endif
 
 #ifndef cpu_to_node
-static inline int cpu_to_node(int cpu)
-{
-   return per_cpu(numa_node, cpu);
-}
+extern int (*cpu_to_node)(int cpu);
+extern int _cpu_to_node(int cpu);
 #endif
 
 #ifndef set_numa_node
diff --git a/init/main.c b/init/main.c
index e24b0780fdff..b142e9c51161 100644
--- a/init/main.c
+++ b/init/main.c
@@ -870,6 +870,18 @@ static void __init print_unknown_bootoptions(void)
memblock_free(unknown_options, len);
 }
 
+static void __init smp_prepare_boot_cpu_start(void)
+{
+   smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
+
+#ifdef CONFIG_USE_PERCPU_NUMA_NODE_ID
+#ifndef cpu_to_node
+   /* The early_cpu_to_node should be ready now. */
+   cpu_to_node = early_cpu_to_node;
+#endif
+#endif
+}
+
 asmlinkage __visible __init __no_sanitize_address __noreturn 
__no_stack_protector
 void start_kernel(void)
 {
@@ -899,7 +911,7 @@ void start_kernel(void)
setup_command_line(command_line);
setup_nr_cpu_ids();
setup_per_cpu_areas();
-   smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
+   smp_prepare_boot_cpu_start();
boot_cpu_hotplug_init();
 
pr_notice("Kernel command line: %s\n", saved_command_line);
@@ -1519,6 +1531,19 @@ void __init console_on_rootfs(void)
fput(file);
 }
 
+static void __init smp_prepare_cpus_done(unsigned int setup_max_cpus)
+{
+   /* Different ARCHs may override smp_prepare_cpus() */
+   smp_prepare_cpus(setup_max_cpus);
+
+#ifdef CONFIG_USE_PERCPU_NUMA_NODE_ID
+#ifndef cpu_to_node
+   /* Change to the formal function. */
+   cpu_to_node = _cpu_to_node;
+#endif
+#endif
+}
+
 static noinline void __init kernel_init_freeable(void)
 {
/* Now the scheduler is fully set up and can do 

[PATCH] powerpc: Enable support for 32 bit MSI-X vectors

2024-01-17 Thread Brian King
Some devices are not capable of addressing 64 bits
via DMA, which includes MSI-X vectors. This allows
us to ensure these devices use MSI-X vectors in
32 bit space.

Signed-off-by: Brian King 
---
 arch/powerpc/platforms/pseries/msi.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/msi.c 
b/arch/powerpc/platforms/pseries/msi.c
index 423ee1d5bd94..6dfb55b52d36 100644
--- a/arch/powerpc/platforms/pseries/msi.c
+++ b/arch/powerpc/platforms/pseries/msi.c
@@ -26,6 +26,7 @@ static int query_token, change_token;
 #define RTAS_CHANGE_MSI_FN 3
 #define RTAS_CHANGE_MSIX_FN4
 #define RTAS_CHANGE_32MSI_FN   5
+#define RTAS_CHANGE_32MSIX_FN  6
 
 /* RTAS Helpers */
 
@@ -41,7 +42,7 @@ static int rtas_change_msi(struct pci_dn *pdn, u32 func, u32 
num_irqs)
seq_num = 1;
do {
if (func == RTAS_CHANGE_MSI_FN || func == RTAS_CHANGE_MSIX_FN ||
-   func == RTAS_CHANGE_32MSI_FN)
+   func == RTAS_CHANGE_32MSI_FN || func == 
RTAS_CHANGE_32MSIX_FN)
rc = rtas_call(change_token, 6, 4, rtas_ret, addr,
BUID_HI(buid), BUID_LO(buid),
func, num_irqs, seq_num);
@@ -406,8 +407,12 @@ static int rtas_prepare_msi_irqs(struct pci_dev *pdev, int 
nvec_in, int type,
 
if (use_32bit_msi_hack && rc > 0)
rtas_hack_32bit_msi_gen2(pdev);
-   } else
-   rc = rtas_change_msi(pdn, RTAS_CHANGE_MSIX_FN, nvec);
+   } else {
+   if (pdev->no_64bit_msi)
+   rc = rtas_change_msi(pdn, RTAS_CHANGE_32MSIX_FN, nvec);
+   else
+   rc = rtas_change_msi(pdn, RTAS_CHANGE_MSIX_FN, nvec);
+   }
 
if (rc != nvec) {
if (nvec != nvec_in) {
-- 
2.39.3



Re: [PATCH v2 06/13] mm/gup: Drop folio_fast_pin_allowed() in hugepd processing

2024-01-17 Thread Jason Gunthorpe
On Tue, Jan 16, 2024 at 06:32:32PM +, Christophe Leroy wrote:
> >> hugepd is a page directory dedicated to huge pages, where you have huge
> >> pages listed instead of regular pages. For instance, on powerpc 32 with
> >> each PGD entries covering 4Mbytes, a regular page table has 1024 PTEs. A
> >> hugepd for 512k is a page table with 8 entries.
> >>
> >> And for 8Mbytes entries, the hugepd is a page table with only one entry.
> >> And 2 consecutive PGS entries will point to the same hugepd to cover the
> >> entire 8Mbytes.
> > 
> > That still sounds alot like the ARM thing - except ARM replicates the
> > entry, you also said PPC relicates the entry like ARM to get to the
> > 8M?
> 
> Is it like ARM ? Not sure. The PTE is not in the PGD it must be in a L2 
> directory, even for 8M.

Your diagram looks almost exactly like ARM to me.

The key thing is that the address for the L2 Table is *always* formed as:

   L2 Table Base << 12 + L2 Index << 2 + 00

Then the L2 Descriptor must contains bits indicating the page
size. The L2 Descriptor is replicated to every 4k entry that the page
size covers.

The only difference I see is the 8M case which has a page size greater
than a single L1 entry.

> Yes that's how it works on powerpc. For 8xx we used to do that for both 
> 8M and 512k pages. Now for 512k pages we do kind of like ARM (which 
> means replicating the entry 128 times) as that's needed to allow mixing 
> different page sizes for a given PGD entry.

Right, you want to have granular page sizes or it becomes unusable in
the general case
 
> But for 8M pages that would mean replicating the entry 2048 times. 
> That's a bit too much isn't it ?

Indeed, de-duplicating the L2 Table is a neat optimization.

> > So if you imagine a pmd_leaf(), pmd_leaf_size() and a pte_leaf_size()
> > that would return enough information for both.
> 
> pmd_leaf() ? Unless I'm missing something I can't do leaf at PMD (PGD) 
> level. It must be a two-level process even for pages bigger than a PMD 
> entry.

Right, this is the normal THP/hugetlb situation on x86/etc. It
wouldn't apply here since it seems the HW doesn't have a bit in the L1
descriptor to indicate leaf.

Instead for PPC this hugepd stuff should start to follow Ryan's
generic work for ARM contig:

https://lore.kernel.org/all/20231218105100.172635-1-ryan.robe...@arm.com/

Specifically the arch implementation:

https://lore.kernel.org/linux-mm/20231218105100.172635-15-ryan.robe...@arm.com/

Ie the arch should ultimately wire up the replication and variable
page size bits within its implementation of set_ptes(). set_ptes()s
gets a contiguous run of address and should install it with maximum
use of the variable page sizes. The core code will start to call
set_ptes() in more cases as Ryan gets along his project.

For the purposes of GUP, where are are today and where we are going,
it would be much better to not have a special PPC specific "hugepd"
parser. Just process each of the 4k replicates one by one like ARM is
starting with.

The arch would still have to return the correct page address from
pte_phys() which I think Ryan is doing by having the replicates encode
the full 4k based address in each entry. The HW will ignore those low
bits and pte_phys() then works properly. This would work for PPC as
well, excluding the 8M optimization.

Going forward I'd expect to see some pte_page_size() that returns the
size bits and GUP can have logic to skip reading replicates.

The advantage of all this is that it stops making the feature special
and the work Ryan is doing to generically push larger folios into
set_ptes will become usable on these PPC platforms as well. And we can
kill the PPC specific hugepd.

Jason


Re: [PATCH v11 15/15] media: vim2m-audio: add virtual driver for audio memory to memory

2024-01-17 Thread Hans Verkuil
On 22/11/2023 08:23, Shengjiu Wang wrote:
> Audio memory to memory virtual driver use video memory to memory
> virtual driver vim2m.c as example. The main difference is
> device type is VFL_TYPE_AUDIO and device cap type is V4L2_CAP_AUDIO_M2M.
> 
> The device_run function is a dummy function, which is simply
> copy the data from input buffer to output buffer.
> 
> Signed-off-by: Shengjiu Wang 
> ---
>  drivers/media/test-drivers/Kconfig   |  11 +
>  drivers/media/test-drivers/Makefile  |   1 +
>  drivers/media/test-drivers/vim2m-audio.c | 799 +++
>  3 files changed, 811 insertions(+)
>  create mode 100644 drivers/media/test-drivers/vim2m-audio.c
> 
> diff --git a/drivers/media/test-drivers/Kconfig 
> b/drivers/media/test-drivers/Kconfig
> index 459b433e9fae..55f8af6ee4e2 100644
> --- a/drivers/media/test-drivers/Kconfig
> +++ b/drivers/media/test-drivers/Kconfig
> @@ -17,6 +17,17 @@ config VIDEO_VIM2M
> This is a virtual test device for the memory-to-memory driver
> framework.
>  
> +config VIDEO_VIM2M_AUDIO
> + tristate "Virtual Memory-to-Memory Driver For Audio"
> + depends on VIDEO_DEV
> + select VIDEOBUF2_VMALLOC
> + select V4L2_MEM2MEM_DEV
> + select MEDIA_CONTROLLER
> + select MEDIA_CONTROLLER_REQUEST_API

Drop this. This option has been removed.

> + help
> +   This is a virtual audio test device for the memory-to-memory driver
> +   framework.
> +
>  source "drivers/media/test-drivers/vicodec/Kconfig"
>  source "drivers/media/test-drivers/vimc/Kconfig"
>  source "drivers/media/test-drivers/vivid/Kconfig"
> diff --git a/drivers/media/test-drivers/Makefile 
> b/drivers/media/test-drivers/Makefile
> index 740714a4584d..0c61c9ada3e1 100644
> --- a/drivers/media/test-drivers/Makefile
> +++ b/drivers/media/test-drivers/Makefile
> @@ -10,6 +10,7 @@ obj-$(CONFIG_DVB_VIDTV) += vidtv/
>  
>  obj-$(CONFIG_VIDEO_VICODEC) += vicodec/
>  obj-$(CONFIG_VIDEO_VIM2M) += vim2m.o
> +obj-$(CONFIG_VIDEO_VIM2M_AUDIO) += vim2m-audio.o
>  obj-$(CONFIG_VIDEO_VIMC) += vimc/
>  obj-$(CONFIG_VIDEO_VIVID) += vivid/
>  obj-$(CONFIG_VIDEO_VISL) += visl/
> diff --git a/drivers/media/test-drivers/vim2m-audio.c 
> b/drivers/media/test-drivers/vim2m-audio.c
> new file mode 100644
> index ..72806ada8628
> --- /dev/null
> +++ b/drivers/media/test-drivers/vim2m-audio.c
> @@ -0,0 +1,799 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * A virtual v4l2-mem2mem example for audio device.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +MODULE_DESCRIPTION("Virtual device for audio mem2mem testing");
> +MODULE_LICENSE("GPL");
> +
> +static unsigned int debug;
> +module_param(debug, uint, 0644);
> +MODULE_PARM_DESC(debug, "debug level");
> +
> +#define MEM2MEM_NAME "vim2m-audio"
> +
> +#define dprintk(dev, lvl, fmt, arg...) \
> + v4l2_dbg(lvl, debug, &(dev)->v4l2_dev, "%s: " fmt, __func__, ## arg)
> +
> +#define SAMPLE_NUM 4096
> +
> +static void audm2m_dev_release(struct device *dev)
> +{}
> +
> +static struct platform_device audm2m_pdev = {
> + .name   = MEM2MEM_NAME,
> + .dev.release= audm2m_dev_release,
> +};
> +
> +static u32 formats[] = {
> + V4L2_AUDIO_FMT_S16_LE,
> +};
> +
> +#define NUM_FORMATS ARRAY_SIZE(formats)
> +
> +/* Per-queue, driver-specific private data */
> +struct audm2m_q_data {
> + unsigned intrate;
> + unsigned intchannels;
> + unsigned intbuffersize;
> + unsigned intsequence;
> + u32 fourcc;
> +};
> +
> +enum {
> + V4L2_M2M_SRC = 0,
> + V4L2_M2M_DST = 1,
> +};
> +
> +static snd_pcm_format_t find_format(u32 fourcc)
> +{
> + snd_pcm_format_t fmt;
> + unsigned int k;
> +
> + for (k = 0; k < NUM_FORMATS; k++) {
> + if (formats[k] == fourcc)
> + break;
> + }
> +
> + if (k == NUM_FORMATS)
> + return 0;
> +
> + fmt = v4l2_fourcc_to_audfmt(formats[k]);
> +
> + return fmt;
> +}
> +
> +struct audm2m_dev {
> + struct v4l2_device  v4l2_dev;
> + struct video_device vfd;
> +
> + struct mutexdev_mutex;
> +
> + struct v4l2_m2m_dev *m2m_dev;
> +#ifdef CONFIG_MEDIA_CONTROLLER
> + struct media_device mdev;
> +#endif
> +};
> +
> +struct audm2m_ctx {
> + struct v4l2_fh  fh;
> + struct v4l2_ctrl_handlerctrl_handler;
> + struct audm2m_dev   *dev;
> +
> + struct mutexvb_mutex;
> +
> + /* Source and destination queue data */
> + struct audm2m_q_data   q_data[2];
> +};
> +
> +static inline struct audm2m_ctx *file2ctx(struct file *file)
> +{
> + return container_of(file->private_data, struct audm2m_ctx, fh);
> +}
> +
> +static struct audm2m_q_data *get_q_data(struct audm2m_ctx *ctx,
> +

Re: [PATCH v11 14/15] media: imx-asrc: Add memory to memory driver

2024-01-17 Thread Hans Verkuil
Some small comments:

On 22/11/2023 08:23, Shengjiu Wang wrote:
> Implement the ASRC memory to memory function using
> the v4l2 framework, user can use this function with
> v4l2 ioctl interface.
> 
> User send the output and capture buffer to driver and
> driver store the converted data to the capture buffer.
> 
> This feature can be shared by ASRC and EASRC drivers
> 
> Signed-off-by: Shengjiu Wang 
> ---
>  drivers/media/platform/nxp/Kconfig|   13 +
>  drivers/media/platform/nxp/Makefile   |1 +
>  drivers/media/platform/nxp/imx-asrc.c | 1264 +
>  3 files changed, 1278 insertions(+)
>  create mode 100644 drivers/media/platform/nxp/imx-asrc.c
> 
> diff --git a/drivers/media/platform/nxp/Kconfig 
> b/drivers/media/platform/nxp/Kconfig
> index 40e3436669e2..8d0ca335601f 100644
> --- a/drivers/media/platform/nxp/Kconfig
> +++ b/drivers/media/platform/nxp/Kconfig
> @@ -67,3 +67,16 @@ config VIDEO_MX2_EMMAPRP
>  
>  source "drivers/media/platform/nxp/dw100/Kconfig"
>  source "drivers/media/platform/nxp/imx-jpeg/Kconfig"
> +
> +config VIDEO_IMX_ASRC
> + tristate "NXP i.MX ASRC M2M support"
> + depends on V4L_MEM2MEM_DRIVERS
> + depends on MEDIA_SUPPORT
> + select VIDEOBUF2_DMA_CONTIG
> + select V4L2_MEM2MEM_DEV
> + select MEDIA_CONTROLLER
> + help
> + Say Y if you want to add ASRC M2M support for NXP CPUs.
> + It is a complement for ASRC M2P and ASRC P2M features.
> + This option is only useful for out-of-tree drivers since
> + in-tree drivers select it automatically.
> diff --git a/drivers/media/platform/nxp/Makefile 
> b/drivers/media/platform/nxp/Makefile
> index 4d90eb713652..1325675e34f5 100644
> --- a/drivers/media/platform/nxp/Makefile
> +++ b/drivers/media/platform/nxp/Makefile
> @@ -9,3 +9,4 @@ obj-$(CONFIG_VIDEO_IMX8MQ_MIPI_CSI2) += imx8mq-mipi-csi2.o
>  obj-$(CONFIG_VIDEO_IMX_MIPI_CSIS) += imx-mipi-csis.o
>  obj-$(CONFIG_VIDEO_IMX_PXP) += imx-pxp.o
>  obj-$(CONFIG_VIDEO_MX2_EMMAPRP) += mx2_emmaprp.o
> +obj-$(CONFIG_VIDEO_IMX_ASRC) += imx-asrc.o
> diff --git a/drivers/media/platform/nxp/imx-asrc.c 
> b/drivers/media/platform/nxp/imx-asrc.c
> new file mode 100644
> index ..db4d45d5ba59
> --- /dev/null
> +++ b/drivers/media/platform/nxp/imx-asrc.c
> @@ -0,0 +1,1264 @@
> +// SPDX-License-Identifier: GPL-2.0
> +//
> +// Copyright (C) 2014-2016 Freescale Semiconductor, Inc.
> +// Copyright (C) 2019-2023 NXP
> +//
> +// Freescale ASRC Memory to Memory (M2M) driver
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define V4L_CAP OUT
> +#define V4L_OUT IN
> +
> +#define ASRC_xPUT_DMA_CALLBACK(dir) \
> + (((dir) == V4L_OUT) ? asrc_input_dma_callback \
> + : asrc_output_dma_callback)
> +
> +#define DIR_STR(dir) (dir) == V4L_OUT ? "out" : "cap"
> +
> +/* Maximum output and capture buffer size */
> +#define ASRC_M2M_BUFFER_SIZE (512 * 1024)
> +
> +/* Maximum output and capture period size */
> +#define ASRC_M2M_PERIOD_SIZE (48 * 1024)
> +
> +struct asrc_pair_m2m {
> + struct fsl_asrc_pair *pair;
> + struct asrc_m2m *m2m;
> + struct v4l2_fh fh;
> + struct v4l2_ctrl_handler ctrl_handler;
> + int channels[2];
> + unsigned int sequence[2];
> + s64 src_rate_off_prev;  /* Q31.32 */
> + s64 dst_rate_off_prev;  /* Q31.32 */
> + s64 src_rate_off_cur;   /* Q31.32 */
> + s64 dst_rate_off_cur;   /* Q31.32 */
> +};
> +
> +struct asrc_m2m {
> + struct fsl_asrc_m2m_pdata pdata;
> + struct v4l2_device v4l2_dev;
> + struct v4l2_m2m_dev *m2m_dev;
> + struct video_device *dec_vdev;
> + struct mutex mlock; /* v4l2 ioctls serialization */
> + struct platform_device *pdev;
> +#ifdef CONFIG_MEDIA_CONTROLLER
> + struct media_device mdev;
> +#endif
> +};
> +
> +static u32 formats[] = {
> + V4L2_AUDIO_FMT_S8,
> + V4L2_AUDIO_FMT_S16_LE,
> + V4L2_AUDIO_FMT_U16_LE,
> + V4L2_AUDIO_FMT_S24_LE,
> + V4L2_AUDIO_FMT_S24_3LE,
> + V4L2_AUDIO_FMT_U24_LE,
> + V4L2_AUDIO_FMT_U24_3LE,
> + V4L2_AUDIO_FMT_S32_LE,
> + V4L2_AUDIO_FMT_U32_LE,
> + V4L2_AUDIO_FMT_S20_3LE,
> + V4L2_AUDIO_FMT_U20_3LE,
> + V4L2_AUDIO_FMT_FLOAT_LE,
> + V4L2_AUDIO_FMT_IEC958_SUBFRAME_LE,
> +};
> +
> +#define NUM_FORMATS ARRAY_SIZE(formats)
> +
> +static const s64 asrc_v1_m2m_rates[] = {
> + 5512, 8000, 11025, 12000, 16000,
> + 22050, 24000, 32000, 44100,
> + 48000, 64000, 88200, 96000,
> + 128000, 176400, 192000,
> +};
> +
> +static const s64 asrc_v2_m2m_rates[] = {
> + 8000, 11025, 12000, 16000,
> + 22050, 24000, 32000, 44100,
> + 48000, 64000, 88200, 96000,
> + 128000, 176400, 192000, 256000,
> + 352800, 384000, 705600, 768000,
> +};
> +
> +static u32 find_fourcc(snd_pcm_format_t format)
> +{
> + snd_pcm_format_t fmt;
> + unsigned int k;
> +
> + for (k = 0; k < 

Re: [PATCH v11 13/15] media: vivid: add fixed point test controls

2024-01-17 Thread Hans Verkuil
On 22/11/2023 08:23, Shengjiu Wang wrote:
> Add fixed point test controls, one is for Q4.16 format
> another one is for Q63 format.
> 
> Signed-off-by: Shengjiu Wang 
> ---
>  drivers/media/test-drivers/vivid/vivid-core.h |  2 ++
>  .../media/test-drivers/vivid/vivid-ctrls.c| 26 +++
>  include/media/v4l2-ctrls.h|  3 +++
>  3 files changed, 31 insertions(+)
> 
> diff --git a/drivers/media/test-drivers/vivid/vivid-core.h 
> b/drivers/media/test-drivers/vivid/vivid-core.h
> index cfb8e66083f6..f65465191bc9 100644
> --- a/drivers/media/test-drivers/vivid/vivid-core.h
> +++ b/drivers/media/test-drivers/vivid/vivid-core.h
> @@ -222,6 +222,8 @@ struct vivid_dev {
>   struct v4l2_ctrl*boolean;
>   struct v4l2_ctrl*int32;
>   struct v4l2_ctrl*int64;
> + struct v4l2_ctrl*int32_q16;
> + struct v4l2_ctrl*int64_q63;
>   struct v4l2_ctrl*menu;
>   struct v4l2_ctrl*string;
>   struct v4l2_ctrl*bitmask;
> diff --git a/drivers/media/test-drivers/vivid/vivid-ctrls.c 
> b/drivers/media/test-drivers/vivid/vivid-ctrls.c
> index f2b20e25a7a4..2444ea95b285 100644
> --- a/drivers/media/test-drivers/vivid/vivid-ctrls.c
> +++ b/drivers/media/test-drivers/vivid/vivid-ctrls.c
> @@ -38,6 +38,8 @@
>  #define VIVID_CID_U8_PIXEL_ARRAY (VIVID_CID_CUSTOM_BASE + 14)
>  #define VIVID_CID_S32_ARRAY  (VIVID_CID_CUSTOM_BASE + 15)
>  #define VIVID_CID_S64_ARRAY  (VIVID_CID_CUSTOM_BASE + 16)
> +#define VIVID_CID_INT_Q4_16  (VIVID_CID_CUSTOM_BASE + 17)
> +#define VIVID_CID_INT64_Q63  (VIVID_CID_CUSTOM_BASE + 18)
>  
>  #define VIVID_CID_VIVID_BASE (0x00f0 | 0xf000)
>  #define VIVID_CID_VIVID_CLASS(0x00f0 | 1)
> @@ -182,6 +184,28 @@ static const struct v4l2_ctrl_config vivid_ctrl_int64 = {
>   .step = 1,
>  };
>  
> +static const struct v4l2_ctrl_config vivid_ctrl_int32_q16 = {
> + .ops = _user_gen_ctrl_ops,
> + .id = VIVID_CID_INT_Q4_16,
> + .name = "Integer 32 Bits Q4.16",
> + .type = V4L2_CTRL_TYPE_INTEGER,
> + .min = v4l2_ctrl_fp_compose(-16, 0, 16),
> + .max = v4l2_ctrl_fp_compose(15, 0x, 16),
> + .step = 1,
> + .fraction_bits = 16,
> +};
> +
> +static const struct v4l2_ctrl_config vivid_ctrl_int64_q63 = {
> + .ops = _user_gen_ctrl_ops,
> + .id = VIVID_CID_INT64_Q63,
> + .name = "Integer 64 Bits Q63",
> + .type = V4L2_CTRL_TYPE_INTEGER64,
> + .min = v4l2_ctrl_fp_compose(-1, 0, 63),
> + .max = v4l2_ctrl_fp_compose(0, LLONG_MAX, 63),
> + .step = 1,
> + .fraction_bits = 63,
> +};
> +
>  static const struct v4l2_ctrl_config vivid_ctrl_u32_array = {
>   .ops = _user_gen_ctrl_ops,
>   .id = VIVID_CID_U32_ARRAY,
> @@ -1670,6 +1694,8 @@ int vivid_create_controls(struct vivid_dev *dev, bool 
> show_ccs_cap,
>   dev->button = v4l2_ctrl_new_custom(hdl_user_gen, _ctrl_button, 
> NULL);
>   dev->int32 = v4l2_ctrl_new_custom(hdl_user_gen, _ctrl_int32, 
> NULL);
>   dev->int64 = v4l2_ctrl_new_custom(hdl_user_gen, _ctrl_int64, 
> NULL);
> + dev->int32_q16 = v4l2_ctrl_new_custom(hdl_user_gen, 
> _ctrl_int32_q16, NULL);
> + dev->int64_q63 = v4l2_ctrl_new_custom(hdl_user_gen, 
> _ctrl_int64_q63, NULL);
>   dev->boolean = v4l2_ctrl_new_custom(hdl_user_gen, _ctrl_boolean, 
> NULL);
>   dev->menu = v4l2_ctrl_new_custom(hdl_user_gen, _ctrl_menu, NULL);
>   dev->string = v4l2_ctrl_new_custom(hdl_user_gen, _ctrl_string, 
> NULL);
> diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h
> index c35514c5bf88..d18fd116238b 100644
> --- a/include/media/v4l2-ctrls.h
> +++ b/include/media/v4l2-ctrls.h
> @@ -1593,4 +1593,7 @@ void v4l2_ctrl_type_op_log(const struct v4l2_ctrl 
> *ctrl);
>   */
>  int v4l2_ctrl_type_op_validate(const struct v4l2_ctrl *ctrl, union 
> v4l2_ctrl_ptr ptr);
>  
> +/* Composite function for integer and fractional bits */

This comment needs to be expanded a bit:

/*
 * Fixed point compose helper define. This helper maps to the value
 * i + f / (1 << fraction_bits).
 */

> +#define v4l2_ctrl_fp_compose(i, f, fraction_bits) (((s64)(i) << 
> fraction_bits) + (f))
> +
>  #endif

Regards,

Hans


Re: [PATCH v11 12/15] media: uapi: Add an entity type for audio resampler

2024-01-17 Thread Hans Verkuil
Some small comments:

On 22/11/2023 08:23, Shengjiu Wang wrote:
> Add and document a media entity type for audio resampler.

for -> for an

> It is MEDIA_ENT_F_PROC_AUDIO_RESAMPLER.
> 
> Signed-off-by: Shengjiu Wang 
> ---
>  Documentation/userspace-api/media/mediactl/media-types.rst | 6 ++
>  include/uapi/linux/media.h | 1 +
>  2 files changed, 7 insertions(+)
> 
> diff --git a/Documentation/userspace-api/media/mediactl/media-types.rst 
> b/Documentation/userspace-api/media/mediactl/media-types.rst
> index f0880aea41d6..abbe515dad76 100644
> --- a/Documentation/userspace-api/media/mediactl/media-types.rst
> +++ b/Documentation/userspace-api/media/mediactl/media-types.rst
> @@ -40,6 +40,7 @@ Types and flags used to represent the media graph elements
>  .. _MEDIA-ENT-F-PROC-VIDEO-ENCODER:
>  .. _MEDIA-ENT-F-PROC-VIDEO-DECODER:
>  .. _MEDIA-ENT-F-PROC-VIDEO-ISP:
> +.. _MEDIA-ENT-F-PROC-AUDIO-RESAMPLER:
>  .. _MEDIA-ENT-F-VID-MUX:
>  .. _MEDIA-ENT-F-VID-IF-BRIDGE:
>  .. _MEDIA-ENT-F-DV-DECODER:
> @@ -208,6 +209,11 @@ Types and flags used to represent the media graph 
> elements
> combination of custom V4L2 controls and IOCTLs, and parameters
> supplied in a metadata buffer.
>  
> +*  -  ``MEDIA_ENT_F_PROC_AUDIO_RESAMPLER``
> +   -  An Audio Resampler device. An entity capable of
> +   resampling a audio stream from one sample rate to another sample

a audio -> an audio

> +   rate. Must have one sink pad and at least one source pad.
> +
>  *  -  ``MEDIA_ENT_F_VID_MUX``
> - Video multiplexer. An entity capable of multiplexing must have at
>   least two sink pads and one source pad, and must pass the video
> diff --git a/include/uapi/linux/media.h b/include/uapi/linux/media.h
> index 9ff6dec7393a..a8266eaa8042 100644
> --- a/include/uapi/linux/media.h
> +++ b/include/uapi/linux/media.h
> @@ -125,6 +125,7 @@ struct media_device_info {
>  #define MEDIA_ENT_F_PROC_VIDEO_ENCODER   (MEDIA_ENT_F_BASE + 
> 0x4007)
>  #define MEDIA_ENT_F_PROC_VIDEO_DECODER   (MEDIA_ENT_F_BASE + 
> 0x4008)
>  #define MEDIA_ENT_F_PROC_VIDEO_ISP   (MEDIA_ENT_F_BASE + 0x4009)
> +#define MEDIA_ENT_F_PROC_AUDIO_RESAMPLER (MEDIA_ENT_F_BASE + 0x400a)
>  
>  /*
>   * Switch and bridge entity functions

Regards,

Hans


Re: [PATCH v11 10/15] media: uapi: Add audio rate controls support

2024-01-17 Thread Hans Verkuil
Hi Shengjiu,

Some small comments below:

On 22/11/2023 08:23, Shengjiu Wang wrote:
> Add V4L2_CID_M2M_AUDIO_SOURCE_RATE and V4L2_CID_M2M_AUDIO_DEST_RATE
> new IDs for rate control.
> 
> Add V4L2_CID_M2M_AUDIO_SOURCE_RATE_OFFSET and
> V4L2_CID_M2M_AUDIO_DEST_RATE_OFFSET for clock drift.
> 
> Signed-off-by: Shengjiu Wang 
> ---
>  .../media/v4l/ext-ctrls-audio-m2m.rst | 20 +++
>  drivers/media/v4l2-core/v4l2-ctrls-defs.c |  6 ++
>  include/uapi/linux/v4l2-controls.h|  5 +
>  3 files changed, 31 insertions(+)
> 
> diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-audio-m2m.rst 
> b/Documentation/userspace-api/media/v4l/ext-ctrls-audio-m2m.rst
> index 82d2ecedbfee..a3c06fbb91b9 100644
> --- a/Documentation/userspace-api/media/v4l/ext-ctrls-audio-m2m.rst
> +++ b/Documentation/userspace-api/media/v4l/ext-ctrls-audio-m2m.rst
> @@ -19,3 +19,23 @@ Audio M2M Control IDs
>  The Audio M2M class descriptor. Calling
>  :ref:`VIDIOC_QUERYCTRL` for this control will
>  return a description of this control class.
> +
> +.. _v4l2-audio-asrc:
> +
> +``V4L2_CID_M2M_AUDIO_SOURCE_RATE (integer menu)``
> +Sets the audio source sample rate, unit is Hz
> +
> +``V4L2_CID_M2M_AUDIO_DEST_RATE (integer menu)``
> +Sets the audio destination sample rate, unit is Hz
> +
> +``V4L2_CID_M2M_AUDIO_SOURCE_RATE_OFFSET (fixed point)``
> +Sets the offset from the audio source sample rate, unit is Hz.
> +The offset compensates for any clock drift. The actual source audio 
> sample
> +rate is the ideal source audio sample rate from
> +``V4L2_CID_M2M_AUDIO_SOURCE_RATE`` plus this fixed point offset.
> +
> +``V4L2_CID_M2M_AUDIO_DEST_RATE_OFFSET (fixed point)``
> +Sets the offset from the audio dest sample rate, unit is Hz.

dest -> destination

> +The offset compensates for any clock drift. The actual dest audio sample

Ditto.

> +rate is the ideal source audio sample rate from
> +``V4L2_CID_M2M_AUDIO_DEST_RATE`` plus this fixed point offset.
> diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c 
> b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
> index 2a85ea3dc92f..4e606d7fd971 100644
> --- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c
> +++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c
> @@ -1245,6 +1245,8 @@ const char *v4l2_ctrl_get_name(u32 id)
>  
>   /* Audio M2M controls */
>   case V4L2_CID_M2M_AUDIO_CLASS:  return "Audio M2M Controls";
> + case V4L2_CID_M2M_AUDIO_SOURCE_RATE:return "Audio Source Sample 
> Rate";
> + case V4L2_CID_M2M_AUDIO_DEST_RATE:  return "Audio Dest Sample Rate";

Dest -> Destination

>   default:
>   return NULL;
>   }
> @@ -1606,6 +1608,10 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum 
> v4l2_ctrl_type *type,
>   case V4L2_CID_COLORIMETRY_HDR10_MASTERING_DISPLAY:
>   *type = V4L2_CTRL_TYPE_HDR10_MASTERING_DISPLAY;
>   break;
> + case V4L2_CID_M2M_AUDIO_SOURCE_RATE:
> + case V4L2_CID_M2M_AUDIO_DEST_RATE:
> + *type = V4L2_CTRL_TYPE_INTEGER_MENU;
> + break;
>   default:
>   *type = V4L2_CTRL_TYPE_INTEGER;
>   break;
> diff --git a/include/uapi/linux/v4l2-controls.h 
> b/include/uapi/linux/v4l2-controls.h
> index 7d318065a33d..493b59f20a35 100644
> --- a/include/uapi/linux/v4l2-controls.h
> +++ b/include/uapi/linux/v4l2-controls.h
> @@ -3489,6 +3489,11 @@ struct v4l2_ctrl_av1_film_grain {
>  #define V4L2_CID_M2M_AUDIO_CLASS_BASE  (V4L2_CTRL_CLASS_M2M_AUDIO | 0x900)
>  #define V4L2_CID_M2M_AUDIO_CLASS   (V4L2_CTRL_CLASS_M2M_AUDIO | 1)
>  
> +#define V4L2_CID_M2M_AUDIO_SOURCE_RATE   (V4L2_CID_M2M_AUDIO_CLASS_BASE 
> + 0)
> +#define V4L2_CID_M2M_AUDIO_DEST_RATE (V4L2_CID_M2M_AUDIO_CLASS_BASE + 1)
> +#define V4L2_CID_M2M_AUDIO_SOURCE_RATE_OFFSET
> (V4L2_CID_M2M_AUDIO_CLASS_BASE + 2)
> +#define V4L2_CID_M2M_AUDIO_DEST_RATE_OFFSET  (V4L2_CID_M2M_AUDIO_CLASS_BASE 
> + 3)
> +
>  /* MPEG-compression definitions kept for backwards compatibility */
>  #ifndef __KERNEL__
>  #define V4L2_CTRL_CLASS_MPEGV4L2_CTRL_CLASS_CODEC

Regards,

Hans


[PATCH] powerpc/pasemi: Add a null pointer check to the pas_setup_mce_regs

2024-01-17 Thread Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.

Signed-off-by: Kunwu Chan 
---
 arch/powerpc/platforms/pasemi/setup.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/powerpc/platforms/pasemi/setup.c 
b/arch/powerpc/platforms/pasemi/setup.c
index 0761d98e5be3..8f98f3b5 100644
--- a/arch/powerpc/platforms/pasemi/setup.c
+++ b/arch/powerpc/platforms/pasemi/setup.c
@@ -165,6 +165,8 @@ static int __init pas_setup_mce_regs(void)
while (dev && reg < MAX_MCE_REGS) {
mce_regs[reg].name = kasprintf(GFP_KERNEL,
"mc%d_mcdebug_errsta", reg);
+   if (!mce_regs[reg].name)
+   return -ENOMEM;
mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x730);
dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, dev);
reg++;
-- 
2.39.2