|
| 1 | +/* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | +/* |
| 3 | + * (C) Copyright 2018 Rockchip Electronics Co., Ltd |
| 4 | + * |
| 5 | + */ |
| 6 | + |
| 7 | +#ifndef __RK_ATAGS_H_ |
| 8 | +#define __RK_ATAGS_H_ |
| 9 | + |
| 10 | +/* Tag magic */ |
| 11 | +#define ATAG_CORE 0x54410001 |
| 12 | +#define ATAG_NONE 0x00000000 |
| 13 | + |
| 14 | +#define ATAG_SERIAL 0x54410050 |
| 15 | +#define ATAG_BOOTDEV 0x54410051 |
| 16 | +#define ATAG_DDR_MEM 0x54410052 |
| 17 | +#define ATAG_TOS_MEM 0x54410053 |
| 18 | + |
| 19 | +/* Tag size and offset */ |
| 20 | +#define ATAGS_SIZE (0x2000) /* 8K */ |
| 21 | +#define ATAGS_OFFSET (0x200000 - ATAGS_SIZE)/* [2M-8K, 2M] */ |
| 22 | + |
| 23 | +/* Tag sdram position!! */ |
| 24 | +#define ATAGS_PHYS_BASE (CONFIG_SYS_SDRAM_BASE + ATAGS_OFFSET) |
| 25 | + |
| 26 | +#ifndef ATAGS_PHYS_BASE |
| 27 | +"ERROR: ATAGS_PHYS_BASE is not defined!!" |
| 28 | +#endif |
| 29 | + |
| 30 | +/* tag_bootdev.devtype */ |
| 31 | +#define BOOT_TYPE_EMMC 0x0 |
| 32 | +#define BOOT_TYPE_NAND 0x1 |
| 33 | +#define BOOT_TYPE_SDCARD 0x2 |
| 34 | +#define BOOT_TYPE_SPI_NOR 0x3 |
| 35 | +#define BOOT_TYPE_SPI_NAND 0x4 |
| 36 | + |
| 37 | +/* tag_serial.m_mode */ |
| 38 | +#define SERIAL_M_MODE_M0 0x0 |
| 39 | +#define SERIAL_M_MODE_M1 0x1 |
| 40 | +#define SERIAL_M_MODE_M2 0x2 |
| 41 | + |
| 42 | +struct tag_serial { |
| 43 | + u32 version; |
| 44 | + u32 enable; |
| 45 | + u64 addr; |
| 46 | + u32 baudrate; |
| 47 | + u32 m_mode; |
| 48 | + u32 reserved[4]; |
| 49 | +} __packed; |
| 50 | + |
| 51 | +struct tag_bootdev { |
| 52 | + u32 version; |
| 53 | + u32 devtype; |
| 54 | + u32 devnum; |
| 55 | + u32 mode; |
| 56 | + u32 reserved[8]; |
| 57 | +} __packed; |
| 58 | + |
| 59 | +struct tag_ddr_mem { |
| 60 | + u32 count; |
| 61 | + u32 version; |
| 62 | + u64 bank[20]; |
| 63 | + u32 reserved[4]; |
| 64 | +} __packed; |
| 65 | + |
| 66 | +struct tag_tos_mem { |
| 67 | + u32 version; |
| 68 | + struct { |
| 69 | + char name[8]; |
| 70 | + u64 phy_addr; |
| 71 | + u32 size; |
| 72 | + u32 flags; |
| 73 | + } tee_mem; |
| 74 | + |
| 75 | + struct { |
| 76 | + char name[8]; |
| 77 | + u64 phy_addr; |
| 78 | + u32 size; |
| 79 | + u32 flags; |
| 80 | + } drm_mem; |
| 81 | + |
| 82 | + u64 reserved[8]; |
| 83 | +} __packed; |
| 84 | + |
| 85 | +struct tag_core { |
| 86 | + u32 flags; |
| 87 | + u32 pagesize; |
| 88 | + u32 rootdev; |
| 89 | +} __packed; |
| 90 | + |
| 91 | +struct tag_header { |
| 92 | + u32 size; /* bytes = size * 4 */ |
| 93 | + u32 magic; |
| 94 | +} __packed; |
| 95 | + |
| 96 | +/* Must be 4 bytes align */ |
| 97 | +struct tag { |
| 98 | + struct tag_header hdr; |
| 99 | + union { |
| 100 | + struct tag_core core; |
| 101 | + struct tag_serial serial; |
| 102 | + struct tag_bootdev bootdev; |
| 103 | + struct tag_ddr_mem ddr_mem; |
| 104 | + struct tag_tos_mem tos_mem; |
| 105 | + } u; |
| 106 | +} __aligned(4); |
| 107 | + |
| 108 | +/* |
| 109 | + * Destroy atags |
| 110 | + * |
| 111 | + * first pre-loader who creates atags must call it before atags_set_tag(), |
| 112 | + * because atags_set_tag() may detect last valid and existence ATAG_CORE |
| 113 | + * tag in memory and lead a wrong setup, that is not what we expect. |
| 114 | + */ |
| 115 | +void atags_destroy(void); |
| 116 | + |
| 117 | +/* |
| 118 | + * atags_set_tag - set tag data |
| 119 | + * |
| 120 | + * @magic: tag magic, i.e. ATAG_SERIAL, ATAG_BOOTDEV, .... |
| 121 | + * @tagdata: core data of struct, i.e. struct tag_serial/tag_bootdev ... |
| 122 | + * |
| 123 | + * return: 0 on success, others failed. |
| 124 | + */ |
| 125 | +int atags_set_tag(u32 magic, void *tagdata); |
| 126 | + |
| 127 | +/* |
| 128 | + * atags_get_tag - get tag by tag magic |
| 129 | + * |
| 130 | + * @magic: tag magic, i.e. ATAG_SERIAL, ATAG_BOOTDEV, ... |
| 131 | + * |
| 132 | + * return: NULL on failed, otherwise return the tag that we want. |
| 133 | + */ |
| 134 | +struct tag *atags_get_tag(u32 magic); |
| 135 | + |
| 136 | +/* |
| 137 | + * atags_is_available - check if atags is available, used for second or |
| 138 | + * later pre-loaders. |
| 139 | + * |
| 140 | + * return: 0 is not available, otherwise available. |
| 141 | + */ |
| 142 | +int atags_is_available(void); |
| 143 | + |
| 144 | +/* Print only one tag */ |
| 145 | +void atags_print_tag(struct tag *t); |
| 146 | + |
| 147 | +/* Print all tags */ |
| 148 | +void atags_print_all_tags(void); |
| 149 | + |
| 150 | +/* An atags example test */ |
| 151 | +void atags_test(void); |
| 152 | + |
| 153 | +#endif |
0 commit comments