kernel/dma: Support platform-specific default CMA sizes
cover kernel/dma: Support platform-specific default CMA sizes
This is an RFC patch set that adds support for configuring a default CMA size, depending on the platform.
At SUSE, our ARM installer image runs on a variety of platforms. One of these, the Raspberry Pi 3, requires CMA to be allocated on order to provide graphics output. Currently this can be done with the kernel's cma command- line parameter, or with a compile-time setting. The cma parameter requires user intervention during boot. Using a compile-time constant affects all platforms. So both options are undesireable.
This patch set adds a data structure and look-up code to select a default CMA size, depending on the device's model name. The kernel's cma parameter or a compile-time setting take precedence of the per-device default.
For the Raspberry Pi 3, the CMA allocator now reserves 64 MiB (out of 1 GiB) by default. We found that this is enough memory to run a graphics installer or a simple desktop environment under X11.
Thomas Zimmermann (2):
kernel/dma: Support device-specific CMA defaults kernel/dma: Default to 64 MiB of contiguous memory on Raspberry Pi 3
kernel/dma/contiguous.c | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
Signature · 1 line
2.20.1
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/2 kernel/dma: Support device-specific CMA defaults
Some devices require contiguous memory to be configured at boot time. While this should be specified by the device's firmware, such as a device-tree file, not all devices do so correctly. One example is the Raspberry Pi, which requires CMA memory for its VC4 graphics unit.
This patch adds the necessary infrastructure to initialize CMA with device- specific values. Initially the default is selected from the machine name, as provided by device tree.
--- kernel/dma/contiguous.c | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+)
kernel/dma/contiguous.c +58 -0
@@ -23,6 +23,8 @@#include <linux/sizes.h> #include <linux/dma-contiguous.h> #include <linux/cma.h> +#include <linux/bsearch.h> +#include <linux/of_fdt.h> #ifdef CONFIG_CMA_SIZE_MBYTES #define CMA_SIZE_MBYTES CONFIG_CMA_SIZE_MBYTES
@@ -30,6 +32,54 @@#define CMA_SIZE_MBYTES 0#endif +struct cma_default { +union { +const char *machine_name; + } key; +phys_addr_t selected_size; +phys_addr_t selected_base; +phys_addr_t selected_limit; +}; + +#define DECLARE_CMA_MACHINE_DEFAULT (machine_name_, selected_size_, \ + selected_base_, selected_limit_) \ + { \ + .key = { \ + .machine_name = machine_name_, \ + }, \ + .selected_size = (selected_size_), \ + .selected_base = (selected_base_), \ + .selected_limit = (selected_limit_) \ + } + +/* CMA defaults for various devices, keep this sorted by .machine_name. +*/ +static const struct cma_default __initdata cma_machine_defaults[] = { +}; + +static int __init cmp_machine_name (const void *key,const void *elt) +{ +const struct cma_default *lhs = key; +const struct cma_default *rhs = elt; + +return strcmp (lhs->key.machine_name, rhs->key.machine_name); +} + +static const struct cma_default *__init cma_get_default (void ) +{ +struct cma_default key; + +memset (&key,0 ,sizeof (key)); + key.key.machine_name =of_flat_dt_get_machine_name (); +if (!key.key.machine_name) +return NULL ; + +return bsearch (&key, cma_machine_defaults, +ARRAY_SIZE (cma_machine_defaults), +sizeof (cma_machine_defaults[0 ]), + cmp_machine_name); +} +struct cma *dma_contiguous_default_area;/*
@@ -129,6 +179,14 @@ void __init dma_contiguous_reserve(phys_addr_t limit)#elif defined(CONFIG_CMA_SIZE_SEL_MAX ) selected_size =max (size_bytes,cma_early_percent_memory ());#endif +if (!selected_size) { +const struct cma_default *def =cma_get_default (); +if (def) { + selected_size = def->selected_size; + selected_base = def->selected_base; + selected_limit = def->selected_limit; + } + } }if (selected_size && !dma_contiguous_default_area) {
Signature · 1 line
2.20.1
PATCH 2/2 kernel/dma: Default to 64 MiB of contiguous memory on Raspberry Pi 3
In reply to a message not in the archiveBy default, reserve 64 MiB of contiguous memory for use with the Raspberry Pi 3's VideoCore IV graphics unit.
--- kernel/dma/contiguous.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/dma/contiguous.c +4 -0
@@ -55,6 +55,10 @@ struct cma_default {/* CMA defaults for various devices, keep this sorted by .machine_name. */ static const struct cma_default __initdata cma_machine_defaults[] = { +/* Reserve 64 MiB for the VC4 graphics unit on Raspberry Pi 3. This +* should be enough memory to run fbcon and a simple desktop. */ +DECLARE_CMA_MACHINE_DEFAULT ("Raspberry Pi 3 Model B Rev 1.2" , +64 *1024 *1024 ,0 ,0 ) };static int __init cmp_machine_name (const void *key,const void *elt)
Signature · 1 line
2.20.1
Hi Thomas,
Quoted 10 lines · Thomas Zimmermann
This is an RFC patch set that adds support for configuring a default CMA size, depending on the platform.
At SUSE, our ARM installer image runs on a variety of platforms. One of these, the Raspberry Pi 3, requires CMA to be allocated on order to provide graphics output. Currently this can be done with the kernel's cma command- line parameter, or with a compile-time setting. The cma parameter requires user intervention during boot. Using a compile-time constant affects all platforms. So both options are undesireable.
Quoted 3 lines
This patch set adds a data structure and look-up code to select a default CMA size, depending on the device's model name. The kernel's cma parameter or a compile-time setting take precedence of the per-device default.
Is there some issue with specifying a board-specific default CMA region via the existing DT binding[1]? I assume there are no ACPI concerns in this particular case.
Robin.
[1] Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt
Quoted 11 lines
For the Raspberry Pi 3, the CMA allocator now reserves 64 MiB (out of 1 GiB) by default. We found that this is enough memory to run a graphics installer or a simple desktop environment under X11.
Thomas Zimmermann (2):
kernel/dma: Support device-specific CMA defaults kernel/dma: Default to 64 MiB of contiguous memory on Raspberry Pi 3kernel/dma/contiguous.c | 62 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)
A message that is not in the archive (sent off-list or not yet received): fe3f4ae9-6a51-0b50-09e9-6c7f52e530d3-5wv7dgnIgG8@public.gmane.org
Quoted 13 lines · On Mon, 4 Mar 2019 12:01:29 +0000 Robin Murphy…
Hi Thomas,
Quoted 10 lines · Thomas Zimmermann
This is an RFC patch set that adds support for configuring a default CMA size, depending on the platform.
At SUSE, our ARM installer image runs on a variety of platforms. One of these, the Raspberry Pi 3, requires CMA to be allocated on order to provide graphics output. Currently this can be done with the kernel's cma command- line parameter, or with a compile-time setting. The cma parameter requires user intervention during boot. Using a compile-time constant affects all platforms. So both options are undesireable.
Quoted 7 lines
Quoted 3 lines
This patch set adds a data structure and look-up code to select a default CMA size, depending on the device's model name. The kernel's cma parameter or a compile-time setting take precedence of the per-device default.
Is there some issue with specifying a board-specific default CMA region via the existing DT binding[1]? I assume there are no ACPI concerns in this particular case.
Indeed.
Thomas, did you have a look how the installer gets booted on the Raspberry Pi? Are we simply using the pre-installed bootloader in this scenario?
Petr T
Quoted 17 lines
Robin.
[1]
Documentation/devicetree/bindings/reserved-memory/reserved-memory.txtQuoted 12 lines
For the Raspberry Pi 3, the CMA allocator now reserves 64 MiB (out of 1 GiB) by default. We found that this is enough memory to run a graphics installer or a simple desktop environment under X11.
Thomas Zimmermann (2):
kernel/dma: Support device-specific CMA defaults kernel/dma: Default to 64 MiB of contiguous memory on Raspberry
Pi 3kernel/dma/contiguous.c | 62+++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+)