zephyr/subsys
Carlo Caione e4a125b6a4 dt: Make zephyr,memory-attr a capabilities bitmask
This is the final step in making the `zephyr,memory-attr` property
actually useful.

The problem with the current implementation is that `zephyr,memory-attr`
is an enum type, this is making very difficult to use that to actually
describe the memory capabilities. The solution proposed in this PR is to
use the `zephyr,memory-attr` property as an OR-ed bitmask of memory
attributes.

With the change proposed in this PR it is possible in the DeviceTree to
mark the memory regions with a bitmask of attributes by using the
`zephyr,memory-attr` property. This property and the related memory
region can then be retrieved at run-time by leveraging a provided helper
library or the usual DT helpers.

The set of general attributes that can be specified in the property are
defined and explained in
`include/zephyr/dt-bindings/memory-attr/memory-attr.h` (the list can be
extended when needed).

For example, to mark a memory region in the DeviceTree as volatile,
non-cacheable, out-of-order:

   mem: memory@10000000 {
       compatible = "mmio-sram";
       reg = <0x10000000 0x1000>;
       zephyr,memory-attr = <( DT_MEM_VOLATILE |
			       DT_MEM_NON_CACHEABLE |
			       DT_MEM_OOO )>;
   };

The `zephyr,memory-attr` property can also be used to set
architecture-specific custom attributes that can be interpreted at run
time. This is leveraged, among other things, to create MPU regions out
of DeviceTree defined memory regions on ARM, for example:

   mem: memory@10000000 {
       compatible = "mmio-sram";
       reg = <0x10000000 0x1000>;
       zephyr,memory-region = "NOCACHE_REGION";
       zephyr,memory-attr = <( DT_ARM_MPU(ATTR_MPU_RAM_NOCACHE) )>;
   };

See `include/zephyr/dt-bindings/memory-attr/memory-attr-mpu.h` to see
how an architecture can define its own special memory attributes (in
this case ARM MPU).

The property can also be used to set custom software-specific
attributes. For example we can think of marking a memory region as
available to be used for memory allocation (not yet implemented):

   mem: memory@10000000 {
       compatible = "mmio-sram";
       reg = <0x10000000 0x1000>;
       zephyr,memory-attr = <( DT_MEM_NON_CACHEABLE |
			       DT_MEM_SW_ALLOCATABLE )>;
   };

Or maybe we can leverage the property to specify some alignment
requirements for the region:

   mem: memory@10000000 {
       compatible = "mmio-sram";
       reg = <0x10000000 0x1000>;
       zephyr,memory-attr = <( DT_MEM_CACHEABLE |
			       DT_MEM_SW_ALIGN(32) )>;
   };

The conventional and recommended way to deal and manage with memory
regions marked with attributes is by using the provided `mem-attr`
helper library by enabling `CONFIG_MEM_ATTR` (or by using the usual DT
helpers).

When this option is enabled the list of memory regions and their
attributes are compiled in a user-accessible array and a set of
functions is made available that can be used to query, probe and act on
regions and attributes, see `include/zephyr/mem_mgmt/mem_attr.h`

Note that the `zephyr,memory-attr` property is only a descriptive
property of the capabilities of the associated memory  region, but it
does not result in any actual setting for the memory to be set. The
user, code or subsystem willing to use this information to do some work
(for example creating an MPU region out of the property) must use either
the provided `mem-attr` library or the usual DeviceTree helpers to
perform the required work / setting.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-09-15 12:46:54 +02:00
..
bluetooth Bluetooth: Controller: Fix missing lazy calculation for Central ISO 2023-09-15 09:27:37 +02:00
canbus canbus: isotp: add CAN-FD support 2023-09-14 08:34:09 +02:00
console
debug debug: Set thread_info.c variables to const 2023-09-11 19:56:18 +02:00
demand_paging kernel: Modify the signature of k_mem_slab_free() 2023-09-03 18:20:59 -04:00
dfu
disk
dsp
emul emul: Don't panic if matching emul can't be found 2023-07-18 11:09:08 +00:00
fb fb: cfb: Remove unused value 2023-08-14 18:08:59 +00:00
fs nvs: replace CRC with better hash function for lookup cache 2023-09-04 18:21:20 +02:00
input drivers,subsys: fix few missing k_work_delayable_from_work 2023-08-28 10:12:21 +02:00
ipc ipc: icmsg: Dedicated workqueue for ICMSG backend 2023-09-12 10:17:27 +02:00
jwt
logging logging: swo: add Kconfig option for SWO reference frequency 2023-09-13 16:29:56 +02:00
lorawan lorawan: services: add missing init.h 2023-08-30 11:37:53 +02:00
mem_mgmt dt: Make zephyr,memory-attr a capabilities bitmask 2023-09-15 12:46:54 +02:00
mgmt kernel: Modify the signature of k_mem_slab_free() 2023-09-03 18:20:59 -04:00
modbus modbus: use macro for function code for input register 2023-08-16 14:58:47 +02:00
modem modem: pipe: Reinvoke receive ready on attach 2023-09-14 16:44:04 -05:00
net Bluetooth: Host: Amend existing L2CAP accept callbacks 2023-09-14 14:36:34 +02:00
pm kernel: move timeout_q.h to kernel/include 2023-09-12 12:55:36 -04:00
portability kernel: Modify the signature of k_mem_slab_free() 2023-09-03 18:20:59 -04:00
random random: syscalls: use zephyr_syscall_header 2023-06-17 07:57:45 -04:00
retention retention: Drop prefix/checksum code if not used 2023-08-24 20:44:02 +02:00
rtio include: always use <> for Zephyr includes 2023-09-14 13:49:58 +02:00
sd drivers: sdhc: allow bandwidth selection 2023-09-13 16:20:59 +02:00
sensing sensing: sensor_mgmt: s/device.h/init.h 2023-08-29 12:17:24 +01:00
settings settings: rename shadow variables 2023-08-22 11:39:58 +02:00
shell shell: Fix scrolling long commands in history 2023-09-13 16:26:02 +02:00
sip_svc subsystem: sip_svc: Reduce the max timeout to 1 second. 2023-09-15 09:26:49 +02:00
stats
storage storage: rename shadow variables 2023-08-22 11:39:58 +02:00
task_wdt
testsuite drivers: interrupt-controller: Add VIM Interrupt Controller support 2023-09-04 10:53:09 +02:00
timing
tracing modules: Add DFM and move Tracerecorder into percepio module 2023-09-12 10:19:37 -04:00
usb toolchain: only include <zephyr/toolchain.h> 2023-09-15 09:27:30 +02:00
zbus zbus: improve the way of storing observers 2023-08-29 10:18:55 +02:00
CMakeLists.txt dt: Make zephyr,memory-attr a capabilities bitmask 2023-09-15 12:46:54 +02:00
Kconfig dt: Make zephyr,memory-attr a capabilities bitmask 2023-09-15 12:46:54 +02:00