Bug Summary

File:hw/arm/../exynos4210_uart.c
Location:line 333, column 5
Description:Value stored to 'frame_size' is never read

Annotated Source Code

1/*
2 * Exynos4210 UART Emulation
3 *
4 * Copyright (C) 2011 Samsung Electronics Co Ltd.
5 * Maksim Kozlov, <m.kozlov@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include "sysbus.h"
23#include "sysemu.h"
24#include "qemu-char.h"
25
26#include "exynos4210.h"
27
28#undef DEBUG_UART0
29#undef DEBUG_UART_EXTEND0
30#undef DEBUG_IRQ0
31#undef DEBUG_Rx_DATA0
32#undef DEBUG_Tx_DATA0
33
34#define DEBUG_UART0 0
35#define DEBUG_UART_EXTEND0 0
36#define DEBUG_IRQ0 0
37#define DEBUG_Rx_DATA0 0
38#define DEBUG_Tx_DATA0 0
39
40#if DEBUG_UART0
41#define PRINT_DEBUG(fmt, args...)do {} while (0) \
42 do { \
43 fprintf(stderrstderr, " [%s:%d] "fmt, __func__, __LINE__43, ##args); \
44 } while (0)
45
46#if DEBUG_UART_EXTEND0
47#define PRINT_DEBUG_EXTEND(fmt, args...)do {} while (0) \
48 do { \
49 fprintf(stderrstderr, " [%s:%d] "fmt, __func__, __LINE__49, ##args); \
50 } while (0)
51#else
52#define PRINT_DEBUG_EXTEND(fmt, args...)do {} while (0) \
53 do {} while (0)
54#endif /* EXTEND */
55
56#else
57#define PRINT_DEBUG(fmt, args...)do {} while (0) \
58 do {} while (0)
59#define PRINT_DEBUG_EXTEND(fmt, args...)do {} while (0) \
60 do {} while (0)
61#endif
62
63#define PRINT_ERROR(fmt, args...)do { fprintf(stderr, " [%s:%d] "fmt, __func__, 63, args...
); } while (0)
\
64 do { \
65 fprintf(stderrstderr, " [%s:%d] "fmt, __func__, __LINE__65, ##args); \
66 } while (0)
67
68/*
69 * Offsets for UART registers relative to SFR base address
70 * for UARTn
71 *
72 */
73#define ULCON0x0000 0x0000 /* Line Control */
74#define UCON0x0004 0x0004 /* Control */
75#define UFCON0x0008 0x0008 /* FIFO Control */
76#define UMCON0x000C 0x000C /* Modem Control */
77#define UTRSTAT0x0010 0x0010 /* Tx/Rx Status */
78#define UERSTAT0x0014 0x0014 /* UART Error Status */
79#define UFSTAT0x0018 0x0018 /* FIFO Status */
80#define UMSTAT0x001C 0x001C /* Modem Status */
81#define UTXH0x0020 0x0020 /* Transmit Buffer */
82#define URXH0x0024 0x0024 /* Receive Buffer */
83#define UBRDIV0x0028 0x0028 /* Baud Rate Divisor */
84#define UFRACVAL0x002C 0x002C /* Divisor Fractional Value */
85#define UINTP0x0030 0x0030 /* Interrupt Pending */
86#define UINTSP0x0034 0x0034 /* Interrupt Source Pending */
87#define UINTM0x0038 0x0038 /* Interrupt Mask */
88
89/*
90 * for indexing register in the uint32_t array
91 *
92 * 'reg' - register offset (see offsets definitions above)
93 *
94 */
95#define I_(reg)(reg / sizeof(uint32_t)) (reg / sizeof(uint32_t))
96
97typedef struct Exynos4210UartReg {
98 const char *name; /* the only reason is the debug output */
99 target_phys_addr_t offset;
100 uint32_t reset_value;
101} Exynos4210UartReg;
102
103static Exynos4210UartReg exynos4210_uart_regs[] = {
104 {"ULCON", ULCON0x0000, 0x00000000},
105 {"UCON", UCON0x0004, 0x00003000},
106 {"UFCON", UFCON0x0008, 0x00000000},
107 {"UMCON", UMCON0x000C, 0x00000000},
108 {"UTRSTAT", UTRSTAT0x0010, 0x00000006}, /* RO */
109 {"UERSTAT", UERSTAT0x0014, 0x00000000}, /* RO */
110 {"UFSTAT", UFSTAT0x0018, 0x00000000}, /* RO */
111 {"UMSTAT", UMSTAT0x001C, 0x00000000}, /* RO */
112 {"UTXH", UTXH0x0020, 0x5c5c5c5c}, /* WO, undefined reset value*/
113 {"URXH", URXH0x0024, 0x00000000}, /* RO */
114 {"UBRDIV", UBRDIV0x0028, 0x00000000},
115 {"UFRACVAL", UFRACVAL0x002C, 0x00000000},
116 {"UINTP", UINTP0x0030, 0x00000000},
117 {"UINTSP", UINTSP0x0034, 0x00000000},
118 {"UINTM", UINTM0x0038, 0x00000000},
119};
120
121#define EXYNOS4210_UART_REGS_MEM_SIZE0x3C 0x3C
122
123/* UART FIFO Control */
124#define UFCON_FIFO_ENABLE0x1 0x1
125#define UFCON_Rx_FIFO_RESET0x2 0x2
126#define UFCON_Tx_FIFO_RESET0x4 0x4
127#define UFCON_Tx_FIFO_TRIGGER_LEVEL_SHIFT8 8
128#define UFCON_Tx_FIFO_TRIGGER_LEVEL(7 << 8) (7 << UFCON_Tx_FIFO_TRIGGER_LEVEL_SHIFT8)
129#define UFCON_Rx_FIFO_TRIGGER_LEVEL_SHIFT4 4
130#define UFCON_Rx_FIFO_TRIGGER_LEVEL(7 << 4) (7 << UFCON_Rx_FIFO_TRIGGER_LEVEL_SHIFT4)
131
132/* Uart FIFO Status */
133#define UFSTAT_Rx_FIFO_COUNT0xff 0xff
134#define UFSTAT_Rx_FIFO_FULL0x100 0x100
135#define UFSTAT_Rx_FIFO_ERROR0x200 0x200
136#define UFSTAT_Tx_FIFO_COUNT_SHIFT16 16
137#define UFSTAT_Tx_FIFO_COUNT(0xff << 16) (0xff << UFSTAT_Tx_FIFO_COUNT_SHIFT16)
138#define UFSTAT_Tx_FIFO_FULL_SHIFT24 24
139#define UFSTAT_Tx_FIFO_FULL(1 << 24) (1 << UFSTAT_Tx_FIFO_FULL_SHIFT24)
140
141/* UART Interrupt Source Pending */
142#define UINTSP_RXD0x1 0x1 /* Receive interrupt */
143#define UINTSP_ERROR0x2 0x2 /* Error interrupt */
144#define UINTSP_TXD0x4 0x4 /* Transmit interrupt */
145#define UINTSP_MODEM0x8 0x8 /* Modem interrupt */
146
147/* UART Line Control */
148#define ULCON_IR_MODE_SHIFT6 6
149#define ULCON_PARITY_SHIFT3 3
150#define ULCON_STOP_BIT_SHIFT1 1
151
152/* UART Tx/Rx Status */
153#define UTRSTAT_TRANSMITTER_EMPTY0x4 0x4
154#define UTRSTAT_Tx_BUFFER_EMPTY0x2 0x2
155#define UTRSTAT_Rx_BUFFER_DATA_READY0x1 0x1
156
157/* UART Error Status */
158#define UERSTAT_OVERRUN0x1 0x1
159#define UERSTAT_PARITY0x2 0x2
160#define UERSTAT_FRAME0x4 0x4
161#define UERSTAT_BREAK0x8 0x8
162
163typedef struct {
164 uint8_t *data;
165 uint32_t sp, rp; /* store and retrieve pointers */
166 uint32_t size;
167} Exynos4210UartFIFO;
168
169typedef struct {
170 SysBusDevice busdev;
171 MemoryRegion iomem;
172
173 uint32_t reg[EXYNOS4210_UART_REGS_MEM_SIZE0x3C / sizeof(uint32_t)];
174 Exynos4210UartFIFO rx;
175 Exynos4210UartFIFO tx;
176
177 CharDriverState *chr;
178 qemu_irq irq;
179
180 uint32_t channel;
181
182} Exynos4210UartState;
183
184
185#if DEBUG_UART0
186/* Used only for debugging inside PRINT_DEBUG_... macros */
187static const char *exynos4210_uart_regname(target_phys_addr_t offset)
188{
189
190 int regs_number = sizeof(exynos4210_uart_regs) / sizeof(Exynos4210UartReg);
191 int i;
192
193 for (i = 0; i < regs_number; i++) {
194 if (offset == exynos4210_uart_regs[i].offset) {
195 return exynos4210_uart_regs[i].name;
196 }
197 }
198
199 return NULL((void*)0);
200}
201#endif
202
203
204static void fifo_store(Exynos4210UartFIFO *q, uint8_t ch)
205{
206 q->data[q->sp] = ch;
207 q->sp = (q->sp + 1) % q->size;
208}
209
210static uint8_t fifo_retrieve(Exynos4210UartFIFO *q)
211{
212 uint8_t ret = q->data[q->rp];
213 q->rp = (q->rp + 1) % q->size;
214 return ret;
215}
216
217static int fifo_elements_number(Exynos4210UartFIFO *q)
218{
219 if (q->sp < q->rp) {
220 return q->size - q->rp + q->sp;
221 }
222
223 return q->sp - q->rp;
224}
225
226static int fifo_empty_elements_number(Exynos4210UartFIFO *q)
227{
228 return q->size - fifo_elements_number(q);
229}
230
231static void fifo_reset(Exynos4210UartFIFO *q)
232{
233 if (q->data != NULL((void*)0)) {
234 g_free(q->data);
235 q->data = NULL((void*)0);
236 }
237
238 q->data = (uint8_t *)g_malloc0(q->size);
239
240 q->sp = 0;
241 q->rp = 0;
242}
243
244static uint32_t exynos4210_uart_Tx_FIFO_trigger_level(Exynos4210UartState *s)
245{
246 uint32_t level = 0;
247 uint32_t reg;
248
249 reg = (s->reg[I_(UFCON)(0x0008 / sizeof(uint32_t))] & UFCON_Tx_FIFO_TRIGGER_LEVEL(7 << 8)) >>
250 UFCON_Tx_FIFO_TRIGGER_LEVEL_SHIFT8;
251
252 switch (s->channel) {
253 case 0:
254 level = reg * 32;
255 break;
256 case 1:
257 case 4:
258 level = reg * 8;
259 break;
260 case 2:
261 case 3:
262 level = reg * 2;
263 break;
264 default:
265 level = 0;
266 PRINT_ERROR("Wrong UART channel number: %d\n", s->channel)do { fprintf(stderr, " [%s:%d] ""Wrong UART channel number: %d\n"
, __func__, 266, s->channel); } while (0)
;
267 }
268
269 return level;
270}
271
272static void exynos4210_uart_update_irq(Exynos4210UartState *s)
273{
274 /*
275 * The Tx interrupt is always requested if the number of data in the
276 * transmit FIFO is smaller than the trigger level.
277 */
278 if (s->reg[I_(UFCON)(0x0008 / sizeof(uint32_t))] & UFCON_FIFO_ENABLE0x1) {
279
280 uint32_t count = (s->reg[I_(UFSTAT)(0x0018 / sizeof(uint32_t))] & UFSTAT_Tx_FIFO_COUNT(0xff << 16)) >>
281 UFSTAT_Tx_FIFO_COUNT_SHIFT16;
282
283 if (count <= exynos4210_uart_Tx_FIFO_trigger_level(s)) {
284 s->reg[I_(UINTSP)(0x0034 / sizeof(uint32_t))] |= UINTSP_TXD0x4;
285 }
286 }
287
288 s->reg[I_(UINTP)(0x0030 / sizeof(uint32_t))] = s->reg[I_(UINTSP)(0x0034 / sizeof(uint32_t))] & ~s->reg[I_(UINTM)(0x0038 / sizeof(uint32_t))];
289
290 if (s->reg[I_(UINTP)(0x0030 / sizeof(uint32_t))]) {
291 qemu_irq_raise(s->irq);
292
293#if DEBUG_IRQ0
294 fprintf(stderrstderr, "UART%d: IRQ has been raised: %08x\n",
295 s->channel, s->reg[I_(UINTP)(0x0030 / sizeof(uint32_t))]);
296#endif
297
298 } else {
299 qemu_irq_lower(s->irq);
300 }
301}
302
303static void exynos4210_uart_update_parameters(Exynos4210UartState *s)
304{
305 int speed, parity, data_bits, stop_bits, frame_size;
306 QEMUSerialSetParams ssp;
307 uint64_t uclk_rate;
308
309 if (s->reg[I_(UBRDIV)(0x0028 / sizeof(uint32_t))] == 0) {
310 return;
311 }
312
313 frame_size = 1; /* start bit */
314 if (s->reg[I_(ULCON)(0x0000 / sizeof(uint32_t))] & 0x20) {
315 frame_size++; /* parity bit */
316 if (s->reg[I_(ULCON)(0x0000 / sizeof(uint32_t))] & 0x28) {
317 parity = 'E';
318 } else {
319 parity = 'O';
320 }
321 } else {
322 parity = 'N';
323 }
324
325 if (s->reg[I_(ULCON)(0x0000 / sizeof(uint32_t))] & 0x4) {
326 stop_bits = 2;
327 } else {
328 stop_bits = 1;
329 }
330
331 data_bits = (s->reg[I_(ULCON)(0x0000 / sizeof(uint32_t))] & 0x3) + 5;
332
333 frame_size += data_bits + stop_bits;
Value stored to 'frame_size' is never read
334
335 uclk_rate = 24000000;
336
337 speed = uclk_rate / ((16 * (s->reg[I_(UBRDIV)(0x0028 / sizeof(uint32_t))]) & 0xffff) +
338 (s->reg[I_(UFRACVAL)(0x002C / sizeof(uint32_t))] & 0x7) + 16);
339
340 ssp.speed = speed;
341 ssp.parity = parity;
342 ssp.data_bits = data_bits;
343 ssp.stop_bits = stop_bits;
344
345 qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_SERIAL_SET_PARAMS1, &ssp);
346
347 PRINT_DEBUG("UART%d: speed: %d, parity: %c, data: %d, stop: %d\n",do {} while (0)
348 s->channel, speed, parity, data_bits, stop_bits)do {} while (0);
349}
350
351static void exynos4210_uart_write(void *opaque, target_phys_addr_t offset,
352 uint64_t val, unsigned size)
353{
354 Exynos4210UartState *s = (Exynos4210UartState *)opaque;
355 uint8_t ch;
356
357 PRINT_DEBUG_EXTEND("UART%d: <0x%04x> %s <- 0x%08llx\n", s->channel,do {} while (0)
358 offset, exynos4210_uart_regname(offset), (long long unsigned int)val)do {} while (0);
359
360 switch (offset) {
361 case ULCON0x0000:
362 case UBRDIV0x0028:
363 case UFRACVAL0x002C:
364 s->reg[I_(offset)(offset / sizeof(uint32_t))] = val;
365 exynos4210_uart_update_parameters(s);
366 break;
367 case UFCON0x0008:
368 s->reg[I_(UFCON)(0x0008 / sizeof(uint32_t))] = val;
369 if (val & UFCON_Rx_FIFO_RESET0x2) {
370 fifo_reset(&s->rx);
371 s->reg[I_(UFCON)(0x0008 / sizeof(uint32_t))] &= ~UFCON_Rx_FIFO_RESET0x2;
372 PRINT_DEBUG("UART%d: Rx FIFO Reset\n", s->channel)do {} while (0);
373 }
374 if (val & UFCON_Tx_FIFO_RESET0x4) {
375 fifo_reset(&s->tx);
376 s->reg[I_(UFCON)(0x0008 / sizeof(uint32_t))] &= ~UFCON_Tx_FIFO_RESET0x4;
377 PRINT_DEBUG("UART%d: Tx FIFO Reset\n", s->channel)do {} while (0);
378 }
379 break;
380
381 case UTXH0x0020:
382 if (s->chr) {
383 s->reg[I_(UTRSTAT)(0x0010 / sizeof(uint32_t))] &= ~(UTRSTAT_TRANSMITTER_EMPTY0x4 |
384 UTRSTAT_Tx_BUFFER_EMPTY0x2);
385 ch = (uint8_t)val;
386 qemu_chr_fe_write(s->chr, &ch, 1);
387#if DEBUG_Tx_DATA0
388 fprintf(stderrstderr, "%c", ch);
389#endif
390 s->reg[I_(UTRSTAT)(0x0010 / sizeof(uint32_t))] |= UTRSTAT_TRANSMITTER_EMPTY0x4 |
391 UTRSTAT_Tx_BUFFER_EMPTY0x2;
392 s->reg[I_(UINTSP)(0x0034 / sizeof(uint32_t))] |= UINTSP_TXD0x4;
393 exynos4210_uart_update_irq(s);
394 }
395 break;
396
397 case UINTP0x0030:
398 s->reg[I_(UINTP)(0x0030 / sizeof(uint32_t))] &= ~val;
399 s->reg[I_(UINTSP)(0x0034 / sizeof(uint32_t))] &= ~val;
400 PRINT_DEBUG("UART%d: UINTP [%04x] have been cleared: %08x\n",do {} while (0)
401 s->channel, offset, s->reg[I_(UINTP)])do {} while (0);
402 exynos4210_uart_update_irq(s);
403 break;
404 case UTRSTAT0x0010:
405 case UERSTAT0x0014:
406 case UFSTAT0x0018:
407 case UMSTAT0x001C:
408 case URXH0x0024:
409 PRINT_DEBUG("UART%d: Trying to write into RO register: %s [%04x]\n",do {} while (0)
410 s->channel, exynos4210_uart_regname(offset), offset)do {} while (0);
411 break;
412 case UINTSP0x0034:
413 s->reg[I_(UINTSP)(0x0034 / sizeof(uint32_t))] &= ~val;
414 break;
415 case UINTM0x0038:
416 s->reg[I_(UINTM)(0x0038 / sizeof(uint32_t))] = val;
417 exynos4210_uart_update_irq(s);
418 break;
419 case UCON0x0004:
420 case UMCON0x000C:
421 default:
422 s->reg[I_(offset)(offset / sizeof(uint32_t))] = val;
423 break;
424 }
425}
426static uint64_t exynos4210_uart_read(void *opaque, target_phys_addr_t offset,
427 unsigned size)
428{
429 Exynos4210UartState *s = (Exynos4210UartState *)opaque;
430 uint32_t res;
431
432 switch (offset) {
433 case UERSTAT0x0014: /* Read Only */
434 res = s->reg[I_(UERSTAT)(0x0014 / sizeof(uint32_t))];
435 s->reg[I_(UERSTAT)(0x0014 / sizeof(uint32_t))] = 0;
436 return res;
437 case UFSTAT0x0018: /* Read Only */
438 s->reg[I_(UFSTAT)(0x0018 / sizeof(uint32_t))] = fifo_elements_number(&s->rx) & 0xff;
439 if (fifo_empty_elements_number(&s->rx) == 0) {
440 s->reg[I_(UFSTAT)(0x0018 / sizeof(uint32_t))] |= UFSTAT_Rx_FIFO_FULL0x100;
441 s->reg[I_(UFSTAT)(0x0018 / sizeof(uint32_t))] &= ~0xff;
442 }
443 return s->reg[I_(UFSTAT)(0x0018 / sizeof(uint32_t))];
444 case URXH0x0024:
445 if (s->reg[I_(UFCON)(0x0008 / sizeof(uint32_t))] & UFCON_FIFO_ENABLE0x1) {
446 if (fifo_elements_number(&s->rx)) {
447 res = fifo_retrieve(&s->rx);
448#if DEBUG_Rx_DATA0
449 fprintf(stderrstderr, "%c", res);
450#endif
451 if (!fifo_elements_number(&s->rx)) {
452 s->reg[I_(UTRSTAT)(0x0010 / sizeof(uint32_t))] &= ~UTRSTAT_Rx_BUFFER_DATA_READY0x1;
453 } else {
454 s->reg[I_(UTRSTAT)(0x0010 / sizeof(uint32_t))] |= UTRSTAT_Rx_BUFFER_DATA_READY0x1;
455 }
456 } else {
457 s->reg[I_(UINTSP)(0x0034 / sizeof(uint32_t))] |= UINTSP_ERROR0x2;
458 exynos4210_uart_update_irq(s);
459 res = 0;
460 }
461 } else {
462 s->reg[I_(UTRSTAT)(0x0010 / sizeof(uint32_t))] &= ~UTRSTAT_Rx_BUFFER_DATA_READY0x1;
463 res = s->reg[I_(URXH)(0x0024 / sizeof(uint32_t))];
464 }
465 return res;
466 case UTXH0x0020:
467 PRINT_DEBUG("UART%d: Trying to read from WO register: %s [%04x]\n",do {} while (0)
468 s->channel, exynos4210_uart_regname(offset), offset)do {} while (0);
469 break;
470 default:
471 return s->reg[I_(offset)(offset / sizeof(uint32_t))];
472 }
473
474 return 0;
475}
476
477static const MemoryRegionOps exynos4210_uart_ops = {
478 .read = exynos4210_uart_read,
479 .write = exynos4210_uart_write,
480 .endianness = DEVICE_NATIVE_ENDIAN,
481 .valid = {
482 .max_access_size = 4,
483 .unaligned = false0
484 },
485};
486
487static int exynos4210_uart_can_receive(void *opaque)
488{
489 Exynos4210UartState *s = (Exynos4210UartState *)opaque;
490
491 return fifo_empty_elements_number(&s->rx);
492}
493
494
495static void exynos4210_uart_receive(void *opaque, const uint8_t *buf, int size)
496{
497 Exynos4210UartState *s = (Exynos4210UartState *)opaque;
498 int i;
499
500 if (s->reg[I_(UFCON)(0x0008 / sizeof(uint32_t))] & UFCON_FIFO_ENABLE0x1) {
501 if (fifo_empty_elements_number(&s->rx) < size) {
502 for (i = 0; i < fifo_empty_elements_number(&s->rx); i++) {
503 fifo_store(&s->rx, buf[i]);
504 }
505 s->reg[I_(UINTSP)(0x0034 / sizeof(uint32_t))] |= UINTSP_ERROR0x2;
506 s->reg[I_(UTRSTAT)(0x0010 / sizeof(uint32_t))] |= UTRSTAT_Rx_BUFFER_DATA_READY0x1;
507 } else {
508 for (i = 0; i < size; i++) {
509 fifo_store(&s->rx, buf[i]);
510 }
511 s->reg[I_(UTRSTAT)(0x0010 / sizeof(uint32_t))] |= UTRSTAT_Rx_BUFFER_DATA_READY0x1;
512 }
513 /* XXX: Around here we maybe should check Rx trigger level */
514 s->reg[I_(UINTSP)(0x0034 / sizeof(uint32_t))] |= UINTSP_RXD0x1;
515 } else {
516 s->reg[I_(URXH)(0x0024 / sizeof(uint32_t))] = buf[0];
517 s->reg[I_(UINTSP)(0x0034 / sizeof(uint32_t))] |= UINTSP_RXD0x1;
518 s->reg[I_(UTRSTAT)(0x0010 / sizeof(uint32_t))] |= UTRSTAT_Rx_BUFFER_DATA_READY0x1;
519 }
520
521 exynos4210_uart_update_irq(s);
522}
523
524
525static void exynos4210_uart_event(void *opaque, int event)
526{
527 Exynos4210UartState *s = (Exynos4210UartState *)opaque;
528
529 if (event == CHR_EVENT_BREAK0) {
530 /* When the RxDn is held in logic 0, then a null byte is pushed into the
531 * fifo */
532 fifo_store(&s->rx, '\0');
533 s->reg[I_(UERSTAT)(0x0014 / sizeof(uint32_t))] |= UERSTAT_BREAK0x8;
534 exynos4210_uart_update_irq(s);
535 }
536}
537
538
539static void exynos4210_uart_reset(DeviceState *dev)
540{
541 Exynos4210UartState *s =
542 container_of(dev, Exynos4210UartState, busdev.qdev)({ const typeof(((Exynos4210UartState *) 0)->busdev.qdev) *
__mptr = (dev); (Exynos4210UartState *) ((char *) __mptr - __builtin_offsetof
(Exynos4210UartState, busdev.qdev));})
;
543 int regs_number = sizeof(exynos4210_uart_regs)/sizeof(Exynos4210UartReg);
544 int i;
545
546 for (i = 0; i < regs_number; i++) {
547 s->reg[I_(exynos4210_uart_regs[i].offset)(exynos4210_uart_regs[i].offset / sizeof(uint32_t))] =
548 exynos4210_uart_regs[i].reset_value;
549 }
550
551 fifo_reset(&s->rx);
552 fifo_reset(&s->tx);
553
554 PRINT_DEBUG("UART%d: Rx FIFO size: %d\n", s->channel, s->rx.size)do {} while (0);
555}
556
557static const VMStateDescription vmstate_exynos4210_uart_fifo = {
558 .name = "exynos4210.uart.fifo",
559 .version_id = 1,
560 .minimum_version_id = 1,
561 .minimum_version_id_old = 1,
562 .fields = (VMStateField[]) {
563 VMSTATE_UINT32(sp, Exynos4210UartFIFO){ .name = ("sp"), .version_id = (0), .field_exists = (((void*
)0)), .size = sizeof(uint32_t), .info = &(vmstate_info_uint32
), .flags = VMS_SINGLE, .offset = (__builtin_offsetof(Exynos4210UartFIFO
, sp) + ((uint32_t*)0 - (typeof(((Exynos4210UartFIFO *)0)->
sp)*)0)), }
,
564 VMSTATE_UINT32(rp, Exynos4210UartFIFO){ .name = ("rp"), .version_id = (0), .field_exists = (((void*
)0)), .size = sizeof(uint32_t), .info = &(vmstate_info_uint32
), .flags = VMS_SINGLE, .offset = (__builtin_offsetof(Exynos4210UartFIFO
, rp) + ((uint32_t*)0 - (typeof(((Exynos4210UartFIFO *)0)->
rp)*)0)), }
,
565 VMSTATE_VBUFFER_UINT32(data, Exynos4210UartFIFO, 1, NULL, 0, size){ .name = ("data"), .version_id = (1), .field_exists = (((void
*)0)), .size_offset = (__builtin_offsetof(Exynos4210UartFIFO,
size) + ((uint32_t*)0 - (typeof(((Exynos4210UartFIFO *)0)->
size)*)0)), .info = &vmstate_info_buffer, .flags = VMS_VBUFFER
|VMS_POINTER, .offset = __builtin_offsetof(Exynos4210UartFIFO
, data), .start = (0), }
,
566 VMSTATE_END_OF_LIST(){}
567 }
568};
569
570static const VMStateDescription vmstate_exynos4210_uart = {
571 .name = "exynos4210.uart",
572 .version_id = 1,
573 .minimum_version_id = 1,
574 .minimum_version_id_old = 1,
575 .fields = (VMStateField[]) {
576 VMSTATE_STRUCT(rx, Exynos4210UartState, 1,{ .name = ("rx"), .version_id = (1), .field_exists = (((void*
)0)), .vmsd = &(vmstate_exynos4210_uart_fifo), .size = sizeof
(Exynos4210UartFIFO), .flags = VMS_STRUCT, .offset = (__builtin_offsetof
(Exynos4210UartState, rx) + ((Exynos4210UartFIFO*)0 - (typeof
(((Exynos4210UartState *)0)->rx)*)0)), }
577 vmstate_exynos4210_uart_fifo, Exynos4210UartFIFO){ .name = ("rx"), .version_id = (1), .field_exists = (((void*
)0)), .vmsd = &(vmstate_exynos4210_uart_fifo), .size = sizeof
(Exynos4210UartFIFO), .flags = VMS_STRUCT, .offset = (__builtin_offsetof
(Exynos4210UartState, rx) + ((Exynos4210UartFIFO*)0 - (typeof
(((Exynos4210UartState *)0)->rx)*)0)), }
,
578 VMSTATE_UINT32_ARRAY(reg, Exynos4210UartState,{ .name = ("reg"), .version_id = (0), .num = (0x3C / sizeof(uint32_t
)), .info = &(vmstate_info_uint32), .size = sizeof(uint32_t
), .flags = VMS_ARRAY, .offset = (__builtin_offsetof(Exynos4210UartState
, reg) + ((uint32_t(*)[0x3C / sizeof(uint32_t)])0 - (typeof((
(Exynos4210UartState *)0)->reg)*)0)), }
579 EXYNOS4210_UART_REGS_MEM_SIZE / sizeof(uint32_t)){ .name = ("reg"), .version_id = (0), .num = (0x3C / sizeof(uint32_t
)), .info = &(vmstate_info_uint32), .size = sizeof(uint32_t
), .flags = VMS_ARRAY, .offset = (__builtin_offsetof(Exynos4210UartState
, reg) + ((uint32_t(*)[0x3C / sizeof(uint32_t)])0 - (typeof((
(Exynos4210UartState *)0)->reg)*)0)), }
,
580 VMSTATE_END_OF_LIST(){}
581 }
582};
583
584DeviceState *exynos4210_uart_create(target_phys_addr_t addr,
585 int fifo_size,
586 int channel,
587 CharDriverState *chr,
588 qemu_irq irq)
589{
590 DeviceState *dev;
591 SysBusDevice *bus;
592
593 const char chr_name[] = "serial";
594 char label[ARRAY_SIZE(chr_name)(sizeof(chr_name) / sizeof((chr_name)[0])) + 1];
595
596 dev = qdev_create(NULL((void*)0), "exynos4210.uart");
597
598 if (!chr) {
599 if (channel >= MAX_SERIAL_PORTS4) {
600 hw_error("Only %d serial ports are supported by QEMU.\n",
601 MAX_SERIAL_PORTS4);
602 }
603 chr = serial_hds[channel];
604 if (!chr) {
605 snprintf(label, ARRAY_SIZE(label)(sizeof(label) / sizeof((label)[0])), "%s%d", chr_name, channel);
606 chr = qemu_chr_new(label, "null", NULL((void*)0));
607 if (!(chr)) {
608 hw_error("Can't assign serial port to UART%d.\n", channel);
609 }
610 }
611 }
612
613 qdev_prop_set_chr(dev, "chardev", chr);
614 qdev_prop_set_uint32(dev, "channel", channel);
615 qdev_prop_set_uint32(dev, "rx-size", fifo_size);
616 qdev_prop_set_uint32(dev, "tx-size", fifo_size);
617
618 bus = sysbus_from_qdev(dev)((SysBusDevice *)(dev));
619 qdev_init_nofail(dev);
620 if (addr != (target_phys_addr_t)-1) {
621 sysbus_mmio_map(bus, 0, addr);
622 }
623 sysbus_connect_irq(bus, 0, irq);
624
625 return dev;
626}
627
628static int exynos4210_uart_init(SysBusDevice *dev)
629{
630 Exynos4210UartState *s = FROM_SYSBUS(Exynos4210UartState, dev)( __extension__ ( { char __attribute__((unused)) offset_must_be_zero
[ -__builtin_offsetof(Exynos4210UartState, busdev)]; ({ const
typeof(((Exynos4210UartState *) 0)->busdev) *__mptr = (dev
); (Exynos4210UartState *) ((char *) __mptr - __builtin_offsetof
(Exynos4210UartState, busdev));});}))
;
631
632 /* memory mapping */
633 memory_region_init_io(&s->iomem, &exynos4210_uart_ops, s, "exynos4210.uart",
634 EXYNOS4210_UART_REGS_MEM_SIZE0x3C);
635 sysbus_init_mmio(dev, &s->iomem);
636
637 sysbus_init_irq(dev, &s->irq);
638
639 qemu_chr_add_handlers(s->chr, exynos4210_uart_can_receive,
640 exynos4210_uart_receive, exynos4210_uart_event, s);
641
642 return 0;
643}
644
645static Property exynos4210_uart_properties[] = {
646 DEFINE_PROP_CHR("chardev", Exynos4210UartState, chr){ .name = ("chardev"), .info = &(qdev_prop_chr), .offset =
__builtin_offsetof(Exynos4210UartState, chr) + ((CharDriverState
**)0 - (typeof(((Exynos4210UartState *)0)->chr)*)0), }
,
647 DEFINE_PROP_UINT32("channel", Exynos4210UartState, channel, 0){ .name = ("channel"), .info = &(qdev_prop_uint32), .offset
= __builtin_offsetof(Exynos4210UartState, channel) + ((uint32_t
*)0 - (typeof(((Exynos4210UartState *)0)->channel)*)0), .qtype
= QTYPE_QINT, .defval = (uint32_t)0, }
,
648 DEFINE_PROP_UINT32("rx-size", Exynos4210UartState, rx.size, 16){ .name = ("rx-size"), .info = &(qdev_prop_uint32), .offset
= __builtin_offsetof(Exynos4210UartState, rx.size) + ((uint32_t
*)0 - (typeof(((Exynos4210UartState *)0)->rx.size)*)0), .qtype
= QTYPE_QINT, .defval = (uint32_t)16, }
,
649 DEFINE_PROP_UINT32("tx-size", Exynos4210UartState, tx.size, 16){ .name = ("tx-size"), .info = &(qdev_prop_uint32), .offset
= __builtin_offsetof(Exynos4210UartState, tx.size) + ((uint32_t
*)0 - (typeof(((Exynos4210UartState *)0)->tx.size)*)0), .qtype
= QTYPE_QINT, .defval = (uint32_t)16, }
,
650 DEFINE_PROP_END_OF_LIST(){},
651};
652
653static void exynos4210_uart_class_init(ObjectClass *klass, void *data)
654{
655 DeviceClass *dc = DEVICE_CLASS(klass)((DeviceClass *)object_class_dynamic_cast_assert(((ObjectClass
*)((klass))), ("device")))
;
656 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass)((SysBusDeviceClass *)object_class_dynamic_cast_assert(((ObjectClass
*)((klass))), ("sys-bus-device")))
;
657
658 k->init = exynos4210_uart_init;
659 dc->reset = exynos4210_uart_reset;
660 dc->props = exynos4210_uart_properties;
661 dc->vmsd = &vmstate_exynos4210_uart;
662}
663
664static TypeInfo exynos4210_uart_info = {
665 .name = "exynos4210.uart",
666 .parent = TYPE_SYS_BUS_DEVICE"sys-bus-device",
667 .instance_size = sizeof(Exynos4210UartState),
668 .class_init = exynos4210_uart_class_init,
669};
670
671static void exynos4210_uart_register(void)
672{
673 type_register_static(&exynos4210_uart_info);
674}
675
676type_init(exynos4210_uart_register)static void __attribute__((constructor)) do_qemu_init_exynos4210_uart_register
(void) { register_module_init(exynos4210_uart_register, MODULE_INIT_QOM
); }