]> git.proxmox.com Git - mirror_qemu.git/blame - hw/arm/digic_boards.c
include/qemu/osdep.h: Don't include qapi/error.h
[mirror_qemu.git] / hw / arm / digic_boards.c
CommitLineData
d91fd756
AP
1/*
2 * QEMU model of the Canon DIGIC boards (cameras indeed :).
3 *
4 * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com>
5 *
6 * This model is based on reverse engineering efforts
7 * made by CHDK (http://chdk.wikia.com) and
8 * Magic Lantern (http://www.magiclantern.fm) projects
9 * contributors.
10 *
11 * See docs here:
12 * http://magiclantern.wikia.com/wiki/Register_Map
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 */
25
12b16722 26#include "qemu/osdep.h"
da34e65c 27#include "qapi/error.h"
d91fd756
AP
28#include "hw/boards.h"
29#include "exec/address-spaces.h"
30#include "qemu/error-report.h"
31#include "hw/arm/digic.h"
04234a37
AP
32#include "hw/block/flash.h"
33#include "hw/loader.h"
34#include "sysemu/sysemu.h"
35#include "sysemu/qtest.h"
36
37#define DIGIC4_ROM0_BASE 0xf0000000
38#define DIGIC4_ROM1_BASE 0xf8000000
39#define DIGIC4_ROM_MAX_SIZE 0x08000000
d91fd756
AP
40
41typedef struct DigicBoardState {
42 DigicState *digic;
43 MemoryRegion ram;
44} DigicBoardState;
45
46typedef struct DigicBoard {
47 hwaddr ram_size;
04234a37
AP
48 void (*add_rom0)(DigicBoardState *, hwaddr, const char *);
49 const char *rom0_def_filename;
50 void (*add_rom1)(DigicBoardState *, hwaddr, const char *);
51 const char *rom1_def_filename;
d91fd756
AP
52} DigicBoard;
53
54static void digic4_board_setup_ram(DigicBoardState *s, hwaddr ram_size)
55{
c8623c02 56 memory_region_allocate_system_memory(&s->ram, NULL, "ram", ram_size);
d91fd756 57 memory_region_add_subregion(get_system_memory(), 0, &s->ram);
d91fd756
AP
58}
59
60static void digic4_board_init(DigicBoard *board)
61{
62 Error *err = NULL;
63
64 DigicBoardState *s = g_new(DigicBoardState, 1);
65
66 s->digic = DIGIC(object_new(TYPE_DIGIC));
67 object_property_set_bool(OBJECT(s->digic), true, "realized", &err);
68 if (err != NULL) {
c29b77f9 69 error_reportf_err(err, "Couldn't realize DIGIC SoC: ");
d91fd756
AP
70 exit(1);
71 }
72
73 digic4_board_setup_ram(s, board->ram_size);
04234a37
AP
74
75 if (board->add_rom0) {
76 board->add_rom0(s, DIGIC4_ROM0_BASE, board->rom0_def_filename);
77 }
78
79 if (board->add_rom1) {
80 board->add_rom1(s, DIGIC4_ROM1_BASE, board->rom1_def_filename);
81 }
82}
83
84static void digic_load_rom(DigicBoardState *s, hwaddr addr,
85 hwaddr max_size, const char *def_filename)
86{
87 target_long rom_size;
88 const char *filename;
89
90 if (qtest_enabled()) {
91 /* qtest runs no code so don't attempt a ROM load which
92 * could fail and result in a spurious test failure.
93 */
94 return;
95 }
96
97 if (bios_name) {
98 filename = bios_name;
99 } else {
100 filename = def_filename;
101 }
102
103 if (filename) {
104 char *fn = qemu_find_file(QEMU_FILE_TYPE_BIOS, filename);
105
106 if (!fn) {
d448527a 107 error_report("Couldn't find rom image '%s'.", filename);
04234a37
AP
108 exit(1);
109 }
110
111 rom_size = load_image_targphys(fn, addr, max_size);
112 if (rom_size < 0 || rom_size > max_size) {
d448527a 113 error_report("Couldn't load rom image '%s'.", filename);
04234a37
AP
114 exit(1);
115 }
6e05a12f 116 g_free(fn);
04234a37
AP
117 }
118}
119
120/*
121 * Samsung K8P3215UQB
122 * 64M Bit (4Mx16) Page Mode / Multi-Bank NOR Flash Memory
123 */
124static void digic4_add_k8p3215uqb_rom(DigicBoardState *s, hwaddr addr,
125 const char *def_filename)
126{
127#define FLASH_K8P3215UQB_SIZE (4 * 1024 * 1024)
128#define FLASH_K8P3215UQB_SECTOR_SIZE (64 * 1024)
129
130 pflash_cfi02_register(addr, NULL, "pflash", FLASH_K8P3215UQB_SIZE,
131 NULL, FLASH_K8P3215UQB_SECTOR_SIZE,
132 FLASH_K8P3215UQB_SIZE / FLASH_K8P3215UQB_SECTOR_SIZE,
133 DIGIC4_ROM_MAX_SIZE / FLASH_K8P3215UQB_SIZE,
134 4,
135 0x00EC, 0x007E, 0x0003, 0x0001,
136 0x0555, 0x2aa, 0);
137
138 digic_load_rom(s, addr, FLASH_K8P3215UQB_SIZE, def_filename);
d91fd756
AP
139}
140
141static DigicBoard digic4_board_canon_a1100 = {
142 .ram_size = 64 * 1024 * 1024,
04234a37
AP
143 .add_rom1 = digic4_add_k8p3215uqb_rom,
144 .rom1_def_filename = "canon-a1100-rom1.bin",
d91fd756
AP
145};
146
3ef96221 147static void canon_a1100_init(MachineState *machine)
d91fd756
AP
148{
149 digic4_board_init(&digic4_board_canon_a1100);
150}
151
e264d29d 152static void canon_a1100_machine_init(MachineClass *mc)
d91fd756 153{
e264d29d
EH
154 mc->desc = "Canon PowerShot A1100 IS";
155 mc->init = &canon_a1100_init;
d91fd756
AP
156}
157
e264d29d 158DEFINE_MACHINE("canon-a1100", canon_a1100_machine_init)