1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#ifndef QEMU_HW_LM32_HWSETUP_H
26#define QEMU_HW_LM32_HWSETUP_H
27
28#include "qemu-common.h"
29#include "hw/loader.h"
30
31typedef struct {
32 void *data;
33 void *ptr;
34} HWSetup;
35
36enum hwsetup_tag {
37 HWSETUP_TAG_EOL = 0,
38 HWSETUP_TAG_CPU = 1,
39 HWSETUP_TAG_ASRAM = 2,
40 HWSETUP_TAG_FLASH = 3,
41 HWSETUP_TAG_SDRAM = 4,
42 HWSETUP_TAG_OCM = 5,
43 HWSETUP_TAG_DDR_SDRAM = 6,
44 HWSETUP_TAG_DDR2_SDRAM = 7,
45 HWSETUP_TAG_TIMER = 8,
46 HWSETUP_TAG_UART = 9,
47 HWSETUP_TAG_GPIO = 10,
48 HWSETUP_TAG_TRISPEEDMAC = 11,
49 HWSETUP_TAG_I2CM = 12,
50 HWSETUP_TAG_LEDS = 13,
51 HWSETUP_TAG_7SEG = 14,
52 HWSETUP_TAG_SPI_S = 15,
53 HWSETUP_TAG_SPI_M = 16,
54};
55
56static inline HWSetup *hwsetup_init(void)
57{
58 HWSetup *hw;
59
60 hw = g_malloc(sizeof(HWSetup));
61 hw->data = g_malloc0(TARGET_PAGE_SIZE);
62 hw->ptr = hw->data;
63
64 return hw;
65}
66
67static inline void hwsetup_free(HWSetup *hw)
68{
69 g_free(hw->data);
70 g_free(hw);
71}
72
73static inline void hwsetup_create_rom(HWSetup *hw,
74 hwaddr base)
75{
76 rom_add_blob("hwsetup", hw->data, TARGET_PAGE_SIZE, base, NULL, NULL, NULL);
77}
78
79static inline void hwsetup_add_u8(HWSetup *hw, uint8_t u)
80{
81 stb_p(hw->ptr, u);
82 hw->ptr += 1;
83}
84
85static inline void hwsetup_add_u32(HWSetup *hw, uint32_t u)
86{
87 stl_p(hw->ptr, u);
88 hw->ptr += 4;
89}
90
91static inline void hwsetup_add_tag(HWSetup *hw, enum hwsetup_tag t)
92{
93 stl_p(hw->ptr, t);
94 hw->ptr += 4;
95}
96
97static inline void hwsetup_add_str(HWSetup *hw, const char *str)
98{
99 pstrcpy(hw->ptr, 32, str);
100 hw->ptr += 32;
101}
102
103static inline void hwsetup_add_trailer(HWSetup *hw)
104{
105 hwsetup_add_u32(hw, 8);
106 hwsetup_add_tag(hw, HWSETUP_TAG_EOL);
107}
108
109static inline void hwsetup_add_cpu(HWSetup *hw,
110 const char *name, uint32_t frequency)
111{
112 hwsetup_add_u32(hw, 44);
113 hwsetup_add_tag(hw, HWSETUP_TAG_CPU);
114 hwsetup_add_str(hw, name);
115 hwsetup_add_u32(hw, frequency);
116}
117
118static inline void hwsetup_add_flash(HWSetup *hw,
119 const char *name, uint32_t base, uint32_t size)
120{
121 hwsetup_add_u32(hw, 52);
122 hwsetup_add_tag(hw, HWSETUP_TAG_FLASH);
123 hwsetup_add_str(hw, name);
124 hwsetup_add_u32(hw, base);
125 hwsetup_add_u32(hw, size);
126 hwsetup_add_u8(hw, 8);
127 hwsetup_add_u8(hw, 8);
128 hwsetup_add_u8(hw, 25);
129 hwsetup_add_u8(hw, 32);
130}
131
132static inline void hwsetup_add_ddr_sdram(HWSetup *hw,
133 const char *name, uint32_t base, uint32_t size)
134{
135 hwsetup_add_u32(hw, 48);
136 hwsetup_add_tag(hw, HWSETUP_TAG_DDR_SDRAM);
137 hwsetup_add_str(hw, name);
138 hwsetup_add_u32(hw, base);
139 hwsetup_add_u32(hw, size);
140}
141
142static inline void hwsetup_add_timer(HWSetup *hw,
143 const char *name, uint32_t base, uint32_t irq)
144{
145 hwsetup_add_u32(hw, 56);
146 hwsetup_add_tag(hw, HWSETUP_TAG_TIMER);
147 hwsetup_add_str(hw, name);
148 hwsetup_add_u32(hw, base);
149 hwsetup_add_u8(hw, 1);
150 hwsetup_add_u8(hw, 1);
151 hwsetup_add_u8(hw, 1);
152 hwsetup_add_u8(hw, 32);
153 hwsetup_add_u32(hw, 20);
154 hwsetup_add_u8(hw, irq);
155 hwsetup_add_u8(hw, 0);
156 hwsetup_add_u8(hw, 0);
157 hwsetup_add_u8(hw, 0);
158}
159
160static inline void hwsetup_add_uart(HWSetup *hw,
161 const char *name, uint32_t base, uint32_t irq)
162{
163 hwsetup_add_u32(hw, 56);
164 hwsetup_add_tag(hw, HWSETUP_TAG_UART);
165 hwsetup_add_str(hw, name);
166 hwsetup_add_u32(hw, base);
167 hwsetup_add_u32(hw, 115200);
168 hwsetup_add_u8(hw, 8);
169 hwsetup_add_u8(hw, 1);
170 hwsetup_add_u8(hw, 1);
171 hwsetup_add_u8(hw, 1);
172 hwsetup_add_u8(hw, 1);
173 hwsetup_add_u8(hw, 4);
174 hwsetup_add_u8(hw, 4);
175 hwsetup_add_u8(hw, irq);
176}
177
178#endif
179