1 /*
2 * Copyright (c) 2020 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Definitions and helper macros for managing driver memory-mapped
7 * input/output (MMIO) regions appropriately in either RAM or ROM.
8 *
9 * In most cases drivers will just want to include device.h, but
10 * including this separately may be needed for arch-level driver code
11 * which uses the DEVICE_MMIO_TOPLEVEL variants and including the
12 * main device.h would introduce header dependency loops due to that
13 * header's reliance on kernel.h.
14 */
15 #ifndef ZEPHYR_INCLUDE_SYS_DEVICE_MMIO_H
16 #define ZEPHYR_INCLUDE_SYS_DEVICE_MMIO_H
17
18 #include <toolchain/common.h>
19 #include <linker/sections.h>
20
21 /**
22 * @defgroup device-mmio Device memory-mapped IO management
23 * @ingroup device-model
24 * @{
25 */
26
27 /* Storing MMIO addresses in RAM is a system-wide decision based on
28 * configuration. This is just used to simplify some other definitions.
29 *
30 * If we have an MMU enabled, all physical MMIO regions must be mapped into
31 * the kernel's virtual address space at runtime, this is a hard requirement.
32 *
33 * If we have PCIE enabled, this does mean that non-PCIE drivers may waste
34 * a bit of RAM, but systems with PCI express are not RAM constrained.
35 */
36 #if defined(CONFIG_MMU) || defined(CONFIG_PCIE)
37 #define DEVICE_MMIO_IS_IN_RAM
38 #endif
39
40 #ifndef _ASMLANGUAGE
41 #include <stdint.h>
42 #include <stddef.h>
43 #include <sys/mem_manage.h>
44 #include <sys/sys_io.h>
45
46 #ifdef DEVICE_MMIO_IS_IN_RAM
47 /* Store the physical address and size from DTS, we'll memory
48 * map into the virtual address space at runtime. This is not applicable
49 * to PCIe devices, which must query the bus for BAR information.
50 */
51 struct z_device_mmio_rom {
52 /** MMIO physical address */
53 uintptr_t phys_addr;
54
55 /** MMIO region size */
56 size_t size;
57 };
58
59 #define Z_DEVICE_MMIO_ROM_INITIALIZER(node_id) \
60 { \
61 .phys_addr = DT_REG_ADDR(node_id), \
62 .size = DT_REG_SIZE(node_id) \
63 }
64
65 /**
66 * Set linear address for device MMIO access
67 *
68 * This function sets the `virt_addr` parameter to the correct linear
69 * address for the MMIO region.
70 *
71 * If the MMU is enabled, mappings may be created in the page tables.
72 *
73 * Normally, only a caching mode needs to be set for the 'flags' parameter.
74 * The mapped linear address will have read-write access to supervisor mode.
75 *
76 * @see k_map()
77 *
78 * @param virt_addr [out] Output linear address storage location, most
79 * users will want some DEVICE_MMIO_RAM_PTR() value
80 * @param phys_addr Physical address base of the MMIO region
81 * @param size Size of the MMIO region
82 * @param flags Caching mode and access flags, see K_MEM_CACHE_* and
83 * K_MEM_PERM_* macros
84 */
85 __boot_func
device_map(mm_reg_t * virt_addr,uintptr_t phys_addr,size_t size,uint32_t flags)86 static inline void device_map(mm_reg_t *virt_addr, uintptr_t phys_addr,
87 size_t size, uint32_t flags)
88 {
89 #ifdef CONFIG_MMU
90 /* Pass along flags and add that we want supervisor mode
91 * read-write access.
92 */
93 z_phys_map((uint8_t **)virt_addr, phys_addr, size,
94 flags | K_MEM_PERM_RW);
95 #else
96 ARG_UNUSED(size);
97 ARG_UNUSED(flags);
98
99 *virt_addr = phys_addr;
100 #endif /* CONFIG_MMU */
101 }
102 #else
103 /* No MMU or PCIe. Just store the address from DTS and treat as a linear
104 * address
105 */
106 struct z_device_mmio_rom {
107 /** MMIO linear address */
108 mm_reg_t addr;
109 };
110
111 #define Z_DEVICE_MMIO_ROM_INITIALIZER(node_id) \
112 { \
113 .addr = DT_REG_ADDR(node_id) \
114 }
115 #endif /* DEVICE_MMIO_IS_IN_RAM */
116 #endif /* !_ASMLANGUAGE */
117 /** @} */
118
119 /**
120 * @defgroup device-mmio-single Single MMIO region macros
121 * @ingroup device-mmio
122 *
123 * For drivers which need to manage just one MMIO region, the most common
124 * case.
125 *
126 * @{
127 */
128
129 /**
130 * @def DEVICE_MMIO_RAM
131 *
132 * Declare storage for MMIO information within a device's dev_data struct.
133 *
134 * This gets accessed by the DEVICE_MMIO_MAP() and DEVICE_MMIO_GET() macros.
135 *
136 * Depending on configuration, no memory may be reserved at all.
137 * This must be the first member of the data struct.
138 *
139 * There must be a corresponding DEVICE_MMIO_ROM in config_info if the
140 * physical address is known at build time, but may be omitted if not (such
141 * as with PCIe)
142 *
143 * Example for a driver named "foo":
144 *
145 * struct foo_driver_data {
146 * DEVICE_MMIO_RAM;
147 * int wibble;
148 * ...
149 * }
150 *
151 * No build-time initialization of this memory is necessary; it
152 * will be set up in the init function by DEVICE_MMIO_MAP().
153 *
154 * A pointer to this memory may be obtained with DEVICE_MMIO_RAM_PTR().
155 */
156 #ifdef DEVICE_MMIO_IS_IN_RAM
157 #define DEVICE_MMIO_RAM mm_reg_t _mmio
158 #else
159 #define DEVICE_MMIO_RAM
160 #endif
161
162 #ifdef DEVICE_MMIO_IS_IN_RAM
163 /**
164 * @def DEVICE_MMIO_RAM_PTR(device)
165 *
166 * Return a pointer to the RAM-based storage area for a device's MMIO
167 * address.
168 *
169 * This is useful for the target MMIO address location when using
170 * device_map() directly.
171 *
172 * @param device device node_id object
173 * @retval mm_reg_t pointer to storage location
174 */
175 #define DEVICE_MMIO_RAM_PTR(device) (mm_reg_t *)((device)->data)
176 #endif /* DEVICE_MMIO_IS_IN_RAM */
177
178 /**
179 * @def DEVICE_MMIO_ROM
180 *
181 * @brief Declare storage for MMIO data within a device's config struct
182 *
183 * This gets accessed by DEVICE_MMIO_MAP() and DEVICE_MMIO_GET() macros.
184 *
185 * What gets stored here varies considerably by configuration.
186 * This must be the first member of the config struct. There must be
187 * a corresponding DEVICE_MMIO_RAM in data.
188 *
189 * This storage is not used if the device is PCIe and may be omitted.
190 *
191 * This should be initialized at build time with information from DTS
192 * using DEVICE_MMIO_ROM_INIT().
193 *
194 * A pointer to this memory may be obtained with DEVICE_MMIO_ROM_PTR().
195 *
196 * Example for a driver named "foo":
197 *
198 * struct foo_config {
199 * DEVICE_MMIO_ROM;
200 * int baz;
201 * ...
202 * }
203 *
204 * @see DEVICE_MMIO_ROM_INIT()
205 */
206 #define DEVICE_MMIO_ROM struct z_device_mmio_rom _mmio
207
208 /**
209 * @def DEVICE_MMIO_ROM_PTR(dev)
210 *
211 * Return a pointer to the ROM-based storage area for a device's MMIO
212 * information. This macro will not work properly if the ROM storage
213 * was omitted from the config struct declaration, and should not
214 * be used in this case.
215 *
216 * @param dev device instance object
217 * @retval struct device_mmio_rom * pointer to storage location
218 */
219 #define DEVICE_MMIO_ROM_PTR(dev) \
220 ((struct z_device_mmio_rom *)((dev)->config))
221
222 /**
223 * @def DEVICE_MMIO_ROM_INIT(node_id)
224 *
225 * @brief Initialize a DEVICE_MMIO_ROM member
226 *
227 * Initialize MMIO-related information within a specific instance of
228 * a device config struct, using information from DTS.
229 *
230 * Example for a driver belonging to the "foo" subsystem:
231 *
232 * struct foo_config my_config = {
233 * DEVICE_MMIO_ROM_INIT(DT_DRV_INST(...)),
234 * .baz = 2;
235 * ...
236 * }
237 *
238 * @see DEVICE_MMIO_ROM()
239 *
240 * @param node_id DTS node_id
241 */
242 #define DEVICE_MMIO_ROM_INIT(node_id) \
243 ._mmio = Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
244
245 /**
246 * @def DEVICE_MMIO_MAP(device, flags)
247 *
248 * @brief Map MMIO memory into the address space
249 *
250 * This is not intended for PCIe devices; these must be probed at runtime
251 * and you will want to make a device_map() call directly, using
252 * DEVICE_MMIO_RAM_PTR() as the target virtual address location.
253 *
254 * The flags argument is currently used for caching mode, which should be
255 * one of the DEVICE_CACHE_* macros. Unused bits are reserved for future
256 * expansion.
257 *
258 * @param dev Device object instance
259 * @param flags cache mode flags
260 */
261 #ifdef DEVICE_MMIO_IS_IN_RAM
262 #define DEVICE_MMIO_MAP(dev, flags) \
263 device_map(DEVICE_MMIO_RAM_PTR(dev), \
264 DEVICE_MMIO_ROM_PTR(dev)->phys_addr, \
265 DEVICE_MMIO_ROM_PTR(dev)->size, \
266 (flags))
267 #else
268 #define DEVICE_MMIO_MAP(dev, flags) do { } while (0)
269 #endif
270
271 /**
272 * @def DEVICE_MMIO_GET(dev)
273 *
274 * @brief Obtain the MMIO address for a device
275 *
276 * For most microcontrollers MMIO addresses can be fixed values known at
277 * build time, and we can store this in device->config, residing in ROM.
278 *
279 * However, some devices can only know their MMIO addresses at runtime,
280 * because they need to be memory-mapped into the address space, enumerated
281 * from PCI, or both.
282 *
283 * This macro returns the linear address of the driver's MMIO region.
284 * This is for drivers which have exactly one MMIO region.
285 * A call must have been made to device_map() in the driver init function.
286 *
287 * @param dev Device object
288 * @return mm_reg_t linear address of the MMIO region
289 */
290 #ifdef DEVICE_MMIO_IS_IN_RAM
291 #define DEVICE_MMIO_GET(dev) (*DEVICE_MMIO_RAM_PTR(dev))
292 #else
293 #define DEVICE_MMIO_GET(dev) (DEVICE_MMIO_ROM_PTR(dev)->addr)
294 #endif
295 /** @} */
296
297 /**
298 * @defgroup device-mmio-named Named MMIO region macros
299 * @ingroup device-mmio
300 *
301 * For drivers which need to manage multiple MMIO regions, which will
302 * be referenced by name.
303 *
304 * @{
305 */
306
307 /**
308 * @def DEVICE_MMIO_NAMED_RAM(name)
309 *
310 * @brief Declare storage for MMIO data within a device's dev_data struct
311 *
312 * This gets accessed by the DEVICE_MMIO_NAMED_MAP() and
313 * DEVICE_MMIO_NAMED_GET() macros.
314 *
315 * Depending on configuration, no memory may be reserved at all.
316 * Multiple named regions may be declared.
317 *
318 * There must be a corresponding DEVICE_MMIO_ROM in config if the
319 * physical address is known at build time, but may be omitted if not (such
320 * as with PCIe.
321 *
322 * Example for a driver named "foo":
323 *
324 * struct foo_driver_data {
325 * int blarg;
326 * DEVICE_MMIO_NAMED_RAM(corge);
327 * DEVICE_MMIO_NAMED_RAM(grault);
328 * int wibble;
329 * ...
330 * }
331 *
332 * No build-time initialization of this memory is necessary; it
333 * will be set up in the init function by DEVICE_MMIO_NAMED_MAP().
334 *
335 * @param name Member name to use to store within dev_data.
336 */
337 #ifdef DEVICE_MMIO_IS_IN_RAM
338 #define DEVICE_MMIO_NAMED_RAM(name) mm_reg_t name
339 #else
340 #define DEVICE_MMIO_NAMED_RAM(name)
341 #endif /* DEVICE_MMIO_IS_IN_RAM */
342
343 #ifdef DEVICE_MMIO_IS_IN_RAM
344 /**
345 * @def DEVICE_MMIO_NAMED_RAM_PTR(dev, name)
346 *
347 * @brief Return a pointer to the RAM storage for a device's named MMIO address
348 *
349 * This macro requires that the macro DEV_DATA is locally defined and returns
350 * a properly typed pointer to the particular dev_data struct for this driver.
351 *
352 * @param dev device instance object
353 * @param name Member name within dev_data
354 * @retval mm_reg_t pointer to storage location
355 */
356 #define DEVICE_MMIO_NAMED_RAM_PTR(dev, name) \
357 (&(DEV_DATA(dev)->name))
358 #endif /* DEVICE_MMIO_IS_IN_RAM */
359
360 /**
361 * @def DEVICE_MMIO_NAMED_ROM(name)
362 *
363 * @brief Declare storage for MMIO data within a device's config struct.
364 *
365 * This gets accessed by DEVICE_MMIO_NAMED_MAP() and
366 * DEVICE_MMIO_NAMED_GET() macros.
367 *
368 * What gets stored here varies considerably by configuration. Multiple named
369 * regions may be declared. There must be corresponding entries in the dev_data
370 * struct.
371 *
372 * This storage is not used if the device is PCIe and may be omitted.
373 *
374 * If used, this must be initialized at build time with information from DTS
375 * using DEVICE_MMIO_NAMED_ROM_INIT()
376 *
377 * A pointer to this memory may be obtained with DEVICE_MMIO_NAMED_ROM_PTR().
378 *
379 * Example for a driver named "foo":
380 *
381 * struct foo_config {
382 * int bar;
383 * DEVICE_MMIO_NAMED_ROM(corge);
384 * DEVICE_MMIO_NAMED_ROM(grault);
385 * int baz;
386 * ...
387 * }
388 *
389 * @see DEVICE_MMIO_NAMED_ROM_INIT()
390 *
391 * @param name Member name to store within config
392 */
393 #define DEVICE_MMIO_NAMED_ROM(name) struct z_device_mmio_rom name
394
395 /**
396 * @def DEVICE_MMIO_NAMED_ROM_PTR(dev, name)
397 *
398 * Return a pointer to the ROM-based storage area for a device's MMIO
399 * information.
400 *
401 * This macro requires that the macro DEV_CFG is locally defined and returns
402 * a properly typed pointer to the particular config struct for this
403 * driver.
404 *
405 * @param dev device instance object
406 * @param name Member name within config
407 * @retval struct device_mmio_rom * pointer to storage location
408 */
409 #define DEVICE_MMIO_NAMED_ROM_PTR(dev, name) (&(DEV_CFG(dev)->name))
410
411 /**
412 * @def DEVICE_MMIO_NAMED_ROM_INIT(name, node_id)
413 *
414 * @brief Initialize a named DEVICE_MMIO_NAMED_ROM member
415 *
416 * Initialize MMIO-related information within a specific instance of
417 * a device config struct, using information from DTS.
418 *
419 * Example for an instance of a driver belonging to the "foo" subsystem
420 * that will have two regions named 'corge' and 'grault':
421 *
422 * struct foo_config my_config = {
423 * bar = 7;
424 * DEVICE_MMIO_NAMED_ROM_INIT(corge, DT_DRV_INST(...));
425 * DEVICE_MMIO_NAMED_ROM_INIT(grault, DT_DRV_INST(...));
426 * baz = 2;
427 * ...
428 * }
429 *
430 * @see DEVICE_MMIO_NAMED_ROM()
431 *
432 * @param name Member name within config for the MMIO region
433 * @param node_id DTS node identifier
434 */
435 #define DEVICE_MMIO_NAMED_ROM_INIT(name, node_id) \
436 .name = Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
437
438 /**
439 * @def DEVICE_MMIO_NAMED_MAP(dev, name, flags)
440 *
441 * @brief Set up memory for a named MMIO region
442 *
443 * This performs the necessary PCI probing and/or MMU virtual memory mapping
444 * such that DEVICE_MMIO_GET(name) returns a suitable linear memory address
445 * for the MMIO region.
446 *
447 * If such operations are not required by the target hardware, this expands
448 * to nothing.
449 *
450 * This should be called from the driver's init function, once for each
451 * MMIO region that needs to be mapped.
452 *
453 * This macro requires that the macros DEV_DATA and DEV_CFG are locally
454 * defined and return properly typed pointers to the particular dev_data
455 * and config structs for this driver.
456 *
457 * The flags argument is currently used for caching mode, which should be
458 * one of the DEVICE_CACHE_* macros. Unused bits are reserved for future
459 * expansion.
460 *
461 * @param dev Device object
462 * @param name Member name for MMIO information, as declared with
463 * DEVICE_MMIO_NAMED_RAM/DEVICE_MMIO_NAMED_ROM
464 * @param flags One of the DEVICE_CACHE_* caching modes
465 */
466 #ifdef DEVICE_MMIO_IS_IN_RAM
467 #define DEVICE_MMIO_NAMED_MAP(dev, name, flags) \
468 device_map(DEVICE_MMIO_NAMED_RAM_PTR((dev), name), \
469 (DEVICE_MMIO_NAMED_ROM_PTR((dev), name)->phys_addr), \
470 (DEVICE_MMIO_NAMED_ROM_PTR((dev), name)->size), \
471 (flags))
472 #else
473 #define DEVICE_MMIO_NAMED_MAP(dev, name, flags) do { } while (0)
474 #endif
475
476 /**
477 * @def DEVICE_MMIO_NAMED_GET(dev, name)
478 *
479 * @brief Obtain a named MMIO address for a device
480 *
481 * This macro returns the MMIO base address for a named region from the
482 * appropriate place within the device object's linked data structures.
483 *
484 * This is for drivers which have multiple MMIO regions.
485 *
486 * This macro requires that the macros DEV_DATA and DEV_CFG are locally
487 * defined and return properly typed pointers to the particular dev_data
488 * and config structs for this driver.
489 *
490 * @see DEVICE_MMIO_GET
491 *
492 * @param dev Device object
493 * @param name Member name for MMIO information, as declared with
494 * DEVICE_MMIO_NAMED_RAM/DEVICE_MMIO_NAMED_ROM
495 * @return mm_reg_t linear address of the MMIO region
496 */
497 #ifdef DEVICE_MMIO_IS_IN_RAM
498 #define DEVICE_MMIO_NAMED_GET(dev, name) \
499 (*DEVICE_MMIO_NAMED_RAM_PTR((dev), name))
500 #else
501 #define DEVICE_MMIO_NAMED_GET(dev, name) \
502 ((DEVICE_MMIO_NAMED_ROM_PTR((dev), name))->addr)
503 #endif /* DEVICE_MMIO_IS_IN_RAM */
504
505 /** @} */
506
507 /**
508 * @defgroup device-mmio-toplevel Top-level MMIO region macros
509 * @ingroup device-mmio
510 *
511 * For drivers which do not use Zephyr's driver model and do not
512 * associate struct device with a driver instance. Top-level storage
513 * is used instead, with either global or static scope.
514 *
515 * This is often useful for interrupt controller and timer drivers.
516 *
517 * Currently PCIe devices are not well-supported with this set of macros.
518 * Either use Zephyr's driver model for these kinds of devices, or
519 * manage memory manually with calls to device_map().
520 *
521 * @{
522 */
523
524 #define Z_TOPLEVEL_ROM_NAME(name) _CONCAT(z_mmio_rom__, name)
525 #define Z_TOPLEVEL_RAM_NAME(name) _CONCAT(z_mmio_ram__, name)
526
527 /**
528 * @def DEVICE_MMIO_TOPLEVEL(name, node_id)
529 *
530 * @brief Declare top-level storage for MMIO information, global scope
531 *
532 * This is intended for drivers which do not use Zephyr's driver model
533 * of config/dev_data linked to a struct device.
534 *
535 * Instead, this is a top-level declaration for the driver's C file.
536 * The scope of this declaration is global and may be referenced by
537 * other C files, using DEVICE_MMIO_TOPLEVEL_DECLARE.
538 *
539 * @param name Base symbol name
540 * @param node_id Device-tree node identifier for this region
541 */
542 #ifdef DEVICE_MMIO_IS_IN_RAM
543 #define DEVICE_MMIO_TOPLEVEL(name, node_id) \
544 __pinned_bss \
545 mm_reg_t Z_TOPLEVEL_RAM_NAME(name); \
546 __pinned_rodata \
547 const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name) = \
548 Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
549 #else
550 #define DEVICE_MMIO_TOPLEVEL(name, node_id) \
551 __pinned_rodata \
552 const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name) = \
553 Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
554 #endif /* DEVICE_MMIO_IS_IN_RAM */
555
556 /**
557 * @def DEVICE_MMIO_TOPLEVEL_DECLARE(name)
558 *
559 * Provide an extern reference to a top-level MMIO region
560 *
561 * If a top-level MMIO region defined with DEVICE_MMIO_DEFINE needs to be
562 * referenced from other C files, this macro provides the necessary extern
563 * definitions.
564 *
565 * @see DEVICE_MMIO_TOPLEVEL
566 *
567 * @param name Name of the top-level MMIO region
568 */
569
570 #ifdef DEVICE_MMIO_IS_IN_RAM
571 #define DEVICE_MMIO_TOPLEVEL_DECLARE(name) \
572 extern mm_reg_t Z_TOPLEVEL_RAM_NAME(name); \
573 extern const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name)
574 #else
575 #define DEVICE_MMIO_TOPLEVEL_DECLARE(name) \
576 extern const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name)
577 #endif /* DEVICE_MMIO_IS_IN_RAM */
578
579 /**
580 * @def DEVICE_MMIO_TOPLEVEL_STATIC(name, node_id)
581 *
582 * @brief Declare top-level storage for MMIO information, static scope
583 *
584 * This is intended for drivers which do not use Zephyr's driver model
585 * of config/dev_data linked to a struct device.
586 *
587 * Instead, this is a top-level declaration for the driver's C file.
588 * The scope of this declaration is static.
589 *
590 * @param name Name of the top-level MMIO region
591 * @param node_id Device-tree node identifier for this region
592 */
593 #ifdef DEVICE_MMIO_IS_IN_RAM
594 #define DEVICE_MMIO_TOPLEVEL_STATIC(name, node_id) \
595 __pinned_bss \
596 static mm_reg_t Z_TOPLEVEL_RAM_NAME(name); \
597 __pinned_rodata \
598 static const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name) = \
599 Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
600 #else
601 #define DEVICE_MMIO_TOPLEVEL_STATIC(name, node_id) \
602 __pinned_rodata \
603 static const struct z_device_mmio_rom Z_TOPLEVEL_ROM_NAME(name) = \
604 Z_DEVICE_MMIO_ROM_INITIALIZER(node_id)
605 #endif /* DEVICE_MMIO_IS_IN_RAM */
606
607 #ifdef DEVICE_MMIO_IS_IN_RAM
608 /**
609 * @def DEVICE_MMIO_TOPLEVEL_RAM_PTR(name)
610 *
611 * @brief Return a pointer to the RAM storage for a device's toplevel MMIO
612 * address.
613 *
614 * @param name Name of toplevel MMIO region
615 * @retval mm_reg_t pointer to storage location
616 */
617 #define DEVICE_MMIO_TOPLEVEL_RAM_PTR(name) &Z_TOPLEVEL_RAM_NAME(name)
618 #endif /* DEVICE_MMIO_IS_IN_RAM */
619
620 /**
621 * @def DEVICE_MMIO_TOPLEVEL_ROM_PTR(name)
622 *
623 * Return a pointer to the ROM-based storage area for a toplevel MMIO region.
624 *
625 * @param name MMIO region name
626 * @retval struct device_mmio_rom * pointer to storage location
627 */
628 #define DEVICE_MMIO_TOPLEVEL_ROM_PTR(name) &Z_TOPLEVEL_ROM_NAME(name)
629
630 /**
631 * @def DEVICE_MMIO_TOPLEVEL_MAP(name, flags)
632 *
633 * @brief Set up memory for a driver'sMMIO region
634 *
635 * This performs the necessary MMU virtual memory mapping
636 * such that DEVICE_MMIO_GET() returns a suitable linear memory address
637 * for the MMIO region.
638 *
639 * If such operations are not required by the target hardware, this expands
640 * to nothing.
641 *
642 * This should be called once from the driver's init function.
643 *
644 * The flags argument is currently used for caching mode, which should be
645 * one of the DEVICE_CACHE_* macros. Unused bits are reserved for future
646 * expansion.
647 *
648 * @param name Name of the top-level MMIO region
649 * @param flags One of the DEVICE_CACHE_* caching modes
650 */
651 #ifdef DEVICE_MMIO_IS_IN_RAM
652 #define DEVICE_MMIO_TOPLEVEL_MAP(name, flags) \
653 device_map(&Z_TOPLEVEL_RAM_NAME(name), \
654 Z_TOPLEVEL_ROM_NAME(name).phys_addr, \
655 Z_TOPLEVEL_ROM_NAME(name).size, flags)
656 #else
657 #define DEVICE_MMIO_TOPLEVEL_MAP(name, flags) do { } while (0)
658 #endif
659
660 /**
661 * @def DEVICE_MMIO_TOPLEVEL_GET(name)
662 *
663 * @brief Obtain the MMIO address for a device declared top-level
664 *
665 * @see DEVICE_MMIO_GET
666 *
667 * @param name Name of the top-level MMIO region
668 * @return mm_reg_t linear address of the MMIO region
669 */
670 #ifdef DEVICE_MMIO_IS_IN_RAM
671 #define DEVICE_MMIO_TOPLEVEL_GET(name) \
672 ((mm_reg_t)Z_TOPLEVEL_RAM_NAME(name))
673 #else
674 #define DEVICE_MMIO_TOPLEVEL_GET(name) \
675 ((mm_reg_t)Z_TOPLEVEL_ROM_NAME(name).addr)
676 #endif
677 /** @} */
678
679 #endif /* ZEPHYR_INCLUDE_SYS_DEVICE_MMIO_H */
680