Antony Pavlov | d91fd75 | 2013-12-17 19:42:36 +0000 | [diff] [blame] | 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 | |
Peter Maydell | 12b1672 | 2015-12-07 16:23:45 +0000 | [diff] [blame] | 26 | #include "qemu/osdep.h" |
Markus Armbruster | da34e65 | 2016-03-14 09:01:28 +0100 | [diff] [blame] | 27 | #include "qapi/error.h" |
Paolo Bonzini | 4771d75 | 2016-01-19 21:51:44 +0100 | [diff] [blame] | 28 | #include "qemu-common.h" |
| 29 | #include "cpu.h" |
Antony Pavlov | d91fd75 | 2013-12-17 19:42:36 +0000 | [diff] [blame] | 30 | #include "hw/boards.h" |
| 31 | #include "exec/address-spaces.h" |
| 32 | #include "qemu/error-report.h" |
| 33 | #include "hw/arm/digic.h" |
Antony Pavlov | 04234a3 | 2013-12-17 19:42:37 +0000 | [diff] [blame] | 34 | #include "hw/block/flash.h" |
| 35 | #include "hw/loader.h" |
| 36 | #include "sysemu/sysemu.h" |
| 37 | #include "sysemu/qtest.h" |
| 38 | |
| 39 | #define DIGIC4_ROM0_BASE 0xf0000000 |
| 40 | #define DIGIC4_ROM1_BASE 0xf8000000 |
| 41 | #define DIGIC4_ROM_MAX_SIZE 0x08000000 |
Antony Pavlov | d91fd75 | 2013-12-17 19:42:36 +0000 | [diff] [blame] | 42 | |
| 43 | typedef struct DigicBoardState { |
| 44 | DigicState *digic; |
| 45 | MemoryRegion ram; |
| 46 | } DigicBoardState; |
| 47 | |
| 48 | typedef struct DigicBoard { |
| 49 | hwaddr ram_size; |
Antony Pavlov | 04234a3 | 2013-12-17 19:42:37 +0000 | [diff] [blame] | 50 | void (*add_rom0)(DigicBoardState *, hwaddr, const char *); |
| 51 | const char *rom0_def_filename; |
| 52 | void (*add_rom1)(DigicBoardState *, hwaddr, const char *); |
| 53 | const char *rom1_def_filename; |
Antony Pavlov | d91fd75 | 2013-12-17 19:42:36 +0000 | [diff] [blame] | 54 | } DigicBoard; |
| 55 | |
| 56 | static void digic4_board_setup_ram(DigicBoardState *s, hwaddr ram_size) |
| 57 | { |
Dirk Müller | c8623c0 | 2015-04-04 14:24:38 +0200 | [diff] [blame] | 58 | memory_region_allocate_system_memory(&s->ram, NULL, "ram", ram_size); |
Antony Pavlov | d91fd75 | 2013-12-17 19:42:36 +0000 | [diff] [blame] | 59 | memory_region_add_subregion(get_system_memory(), 0, &s->ram); |
Antony Pavlov | d91fd75 | 2013-12-17 19:42:36 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static void digic4_board_init(DigicBoard *board) |
| 63 | { |
| 64 | Error *err = NULL; |
| 65 | |
| 66 | DigicBoardState *s = g_new(DigicBoardState, 1); |
| 67 | |
| 68 | s->digic = DIGIC(object_new(TYPE_DIGIC)); |
| 69 | object_property_set_bool(OBJECT(s->digic), true, "realized", &err); |
| 70 | if (err != NULL) { |
Markus Armbruster | c29b77f | 2015-12-18 16:35:14 +0100 | [diff] [blame] | 71 | error_reportf_err(err, "Couldn't realize DIGIC SoC: "); |
Antony Pavlov | d91fd75 | 2013-12-17 19:42:36 +0000 | [diff] [blame] | 72 | exit(1); |
| 73 | } |
| 74 | |
| 75 | digic4_board_setup_ram(s, board->ram_size); |
Antony Pavlov | 04234a3 | 2013-12-17 19:42:37 +0000 | [diff] [blame] | 76 | |
| 77 | if (board->add_rom0) { |
| 78 | board->add_rom0(s, DIGIC4_ROM0_BASE, board->rom0_def_filename); |
| 79 | } |
| 80 | |
| 81 | if (board->add_rom1) { |
| 82 | board->add_rom1(s, DIGIC4_ROM1_BASE, board->rom1_def_filename); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | static void digic_load_rom(DigicBoardState *s, hwaddr addr, |
| 87 | hwaddr max_size, const char *def_filename) |
| 88 | { |
| 89 | target_long rom_size; |
| 90 | const char *filename; |
| 91 | |
| 92 | if (qtest_enabled()) { |
| 93 | /* qtest runs no code so don't attempt a ROM load which |
| 94 | * could fail and result in a spurious test failure. |
| 95 | */ |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | if (bios_name) { |
| 100 | filename = bios_name; |
| 101 | } else { |
| 102 | filename = def_filename; |
| 103 | } |
| 104 | |
| 105 | if (filename) { |
| 106 | char *fn = qemu_find_file(QEMU_FILE_TYPE_BIOS, filename); |
| 107 | |
| 108 | if (!fn) { |
Gonglei | d448527 | 2015-02-25 12:22:36 +0800 | [diff] [blame] | 109 | error_report("Couldn't find rom image '%s'.", filename); |
Antony Pavlov | 04234a3 | 2013-12-17 19:42:37 +0000 | [diff] [blame] | 110 | exit(1); |
| 111 | } |
| 112 | |
| 113 | rom_size = load_image_targphys(fn, addr, max_size); |
| 114 | if (rom_size < 0 || rom_size > max_size) { |
Gonglei | d448527 | 2015-02-25 12:22:36 +0800 | [diff] [blame] | 115 | error_report("Couldn't load rom image '%s'.", filename); |
Antony Pavlov | 04234a3 | 2013-12-17 19:42:37 +0000 | [diff] [blame] | 116 | exit(1); |
| 117 | } |
Gonglei | 6e05a12 | 2015-03-05 10:58:32 +0800 | [diff] [blame] | 118 | g_free(fn); |
Antony Pavlov | 04234a3 | 2013-12-17 19:42:37 +0000 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * Samsung K8P3215UQB |
| 124 | * 64M Bit (4Mx16) Page Mode / Multi-Bank NOR Flash Memory |
| 125 | */ |
| 126 | static void digic4_add_k8p3215uqb_rom(DigicBoardState *s, hwaddr addr, |
| 127 | const char *def_filename) |
| 128 | { |
| 129 | #define FLASH_K8P3215UQB_SIZE (4 * 1024 * 1024) |
| 130 | #define FLASH_K8P3215UQB_SECTOR_SIZE (64 * 1024) |
| 131 | |
| 132 | pflash_cfi02_register(addr, NULL, "pflash", FLASH_K8P3215UQB_SIZE, |
| 133 | NULL, FLASH_K8P3215UQB_SECTOR_SIZE, |
| 134 | FLASH_K8P3215UQB_SIZE / FLASH_K8P3215UQB_SECTOR_SIZE, |
| 135 | DIGIC4_ROM_MAX_SIZE / FLASH_K8P3215UQB_SIZE, |
| 136 | 4, |
| 137 | 0x00EC, 0x007E, 0x0003, 0x0001, |
| 138 | 0x0555, 0x2aa, 0); |
| 139 | |
| 140 | digic_load_rom(s, addr, FLASH_K8P3215UQB_SIZE, def_filename); |
Antony Pavlov | d91fd75 | 2013-12-17 19:42:36 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | static DigicBoard digic4_board_canon_a1100 = { |
| 144 | .ram_size = 64 * 1024 * 1024, |
Antony Pavlov | 04234a3 | 2013-12-17 19:42:37 +0000 | [diff] [blame] | 145 | .add_rom1 = digic4_add_k8p3215uqb_rom, |
| 146 | .rom1_def_filename = "canon-a1100-rom1.bin", |
Antony Pavlov | d91fd75 | 2013-12-17 19:42:36 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
Marcel Apfelbaum | 3ef9622 | 2014-05-07 17:42:57 +0300 | [diff] [blame] | 149 | static void canon_a1100_init(MachineState *machine) |
Antony Pavlov | d91fd75 | 2013-12-17 19:42:36 +0000 | [diff] [blame] | 150 | { |
| 151 | digic4_board_init(&digic4_board_canon_a1100); |
| 152 | } |
| 153 | |
Eduardo Habkost | e264d29 | 2015-09-04 15:37:08 -0300 | [diff] [blame] | 154 | static void canon_a1100_machine_init(MachineClass *mc) |
Antony Pavlov | d91fd75 | 2013-12-17 19:42:36 +0000 | [diff] [blame] | 155 | { |
Eduardo Habkost | e264d29 | 2015-09-04 15:37:08 -0300 | [diff] [blame] | 156 | mc->desc = "Canon PowerShot A1100 IS"; |
| 157 | mc->init = &canon_a1100_init; |
Antony Pavlov | d91fd75 | 2013-12-17 19:42:36 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Eduardo Habkost | e264d29 | 2015-09-04 15:37:08 -0300 | [diff] [blame] | 160 | DEFINE_MACHINE("canon-a1100", canon_a1100_machine_init) |