sun4m.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827
  1. /*
  2. * QEMU Sun4m & Sun4d & Sun4c System Emulator
  3. *
  4. * Copyright (c) 2003-2005 Fabrice Bellard
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. #include "sysbus.h"
  25. #include "qemu-timer.h"
  26. #include "sun4m.h"
  27. #include "nvram.h"
  28. #include "sparc32_dma.h"
  29. #include "fdc.h"
  30. #include "sysemu.h"
  31. #include "net.h"
  32. #include "boards.h"
  33. #include "firmware_abi.h"
  34. #include "esp.h"
  35. #include "pc.h"
  36. #include "isa.h"
  37. #include "fw_cfg.h"
  38. #include "escc.h"
  39. #include "empty_slot.h"
  40. #include "qdev-addr.h"
  41. #include "loader.h"
  42. #include "elf.h"
  43. #include "blockdev.h"
  44. #include "trace.h"
  45. /*
  46. * Sun4m architecture was used in the following machines:
  47. *
  48. * SPARCserver 6xxMP/xx
  49. * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15),
  50. * SPARCclassic X (4/10)
  51. * SPARCstation LX/ZX (4/30)
  52. * SPARCstation Voyager
  53. * SPARCstation 10/xx, SPARCserver 10/xx
  54. * SPARCstation 5, SPARCserver 5
  55. * SPARCstation 20/xx, SPARCserver 20
  56. * SPARCstation 4
  57. *
  58. * Sun4d architecture was used in the following machines:
  59. *
  60. * SPARCcenter 2000
  61. * SPARCserver 1000
  62. *
  63. * Sun4c architecture was used in the following machines:
  64. * SPARCstation 1/1+, SPARCserver 1/1+
  65. * SPARCstation SLC
  66. * SPARCstation IPC
  67. * SPARCstation ELC
  68. * SPARCstation IPX
  69. *
  70. * See for example: http://www.sunhelp.org/faq/sunref1.html
  71. */
  72. #define KERNEL_LOAD_ADDR 0x00004000
  73. #define CMDLINE_ADDR 0x007ff000
  74. #define INITRD_LOAD_ADDR 0x00800000
  75. #define PROM_SIZE_MAX (1024 * 1024)
  76. #define PROM_VADDR 0xffd00000
  77. #define PROM_FILENAME "openbios-sparc32"
  78. #define CFG_ADDR 0xd00000510ULL
  79. #define FW_CFG_SUN4M_DEPTH (FW_CFG_ARCH_LOCAL + 0x00)
  80. #define MAX_CPUS 16
  81. #define MAX_PILS 16
  82. #define MAX_VSIMMS 4
  83. #define ESCC_CLOCK 4915200
  84. struct sun4m_hwdef {
  85. target_phys_addr_t iommu_base, iommu_pad_base, iommu_pad_len, slavio_base;
  86. target_phys_addr_t intctl_base, counter_base, nvram_base, ms_kb_base;
  87. target_phys_addr_t serial_base, fd_base;
  88. target_phys_addr_t afx_base, idreg_base, dma_base, esp_base, le_base;
  89. target_phys_addr_t tcx_base, cs_base, apc_base, aux1_base, aux2_base;
  90. target_phys_addr_t bpp_base, dbri_base, sx_base;
  91. struct {
  92. target_phys_addr_t reg_base, vram_base;
  93. } vsimm[MAX_VSIMMS];
  94. target_phys_addr_t ecc_base;
  95. uint32_t ecc_version;
  96. uint8_t nvram_machine_id;
  97. uint16_t machine_id;
  98. uint32_t iommu_version;
  99. uint64_t max_mem;
  100. const char * const default_cpu_model;
  101. };
  102. #define MAX_IOUNITS 5
  103. struct sun4d_hwdef {
  104. target_phys_addr_t iounit_bases[MAX_IOUNITS], slavio_base;
  105. target_phys_addr_t counter_base, nvram_base, ms_kb_base;
  106. target_phys_addr_t serial_base;
  107. target_phys_addr_t espdma_base, esp_base;
  108. target_phys_addr_t ledma_base, le_base;
  109. target_phys_addr_t tcx_base;
  110. target_phys_addr_t sbi_base;
  111. uint8_t nvram_machine_id;
  112. uint16_t machine_id;
  113. uint32_t iounit_version;
  114. uint64_t max_mem;
  115. const char * const default_cpu_model;
  116. };
  117. struct sun4c_hwdef {
  118. target_phys_addr_t iommu_base, slavio_base;
  119. target_phys_addr_t intctl_base, counter_base, nvram_base, ms_kb_base;
  120. target_phys_addr_t serial_base, fd_base;
  121. target_phys_addr_t idreg_base, dma_base, esp_base, le_base;
  122. target_phys_addr_t tcx_base, aux1_base;
  123. uint8_t nvram_machine_id;
  124. uint16_t machine_id;
  125. uint32_t iommu_version;
  126. uint64_t max_mem;
  127. const char * const default_cpu_model;
  128. };
  129. int DMA_get_channel_mode (int nchan)
  130. {
  131. return 0;
  132. }
  133. int DMA_read_memory (int nchan, void *buf, int pos, int size)
  134. {
  135. return 0;
  136. }
  137. int DMA_write_memory (int nchan, void *buf, int pos, int size)
  138. {
  139. return 0;
  140. }
  141. void DMA_hold_DREQ (int nchan) {}
  142. void DMA_release_DREQ (int nchan) {}
  143. void DMA_schedule(int nchan) {}
  144. void DMA_init(int high_page_enable, qemu_irq *cpu_request_exit)
  145. {
  146. }
  147. void DMA_register_channel (int nchan,
  148. DMA_transfer_handler transfer_handler,
  149. void *opaque)
  150. {
  151. }
  152. static int fw_cfg_boot_set(void *opaque, const char *boot_device)
  153. {
  154. fw_cfg_add_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
  155. return 0;
  156. }
  157. static void nvram_init(M48t59State *nvram, uint8_t *macaddr,
  158. const char *cmdline, const char *boot_devices,
  159. ram_addr_t RAM_size, uint32_t kernel_size,
  160. int width, int height, int depth,
  161. int nvram_machine_id, const char *arch)
  162. {
  163. unsigned int i;
  164. uint32_t start, end;
  165. uint8_t image[0x1ff0];
  166. struct OpenBIOS_nvpart_v1 *part_header;
  167. memset(image, '\0', sizeof(image));
  168. start = 0;
  169. // OpenBIOS nvram variables
  170. // Variable partition
  171. part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
  172. part_header->signature = OPENBIOS_PART_SYSTEM;
  173. pstrcpy(part_header->name, sizeof(part_header->name), "system");
  174. end = start + sizeof(struct OpenBIOS_nvpart_v1);
  175. for (i = 0; i < nb_prom_envs; i++)
  176. end = OpenBIOS_set_var(image, end, prom_envs[i]);
  177. // End marker
  178. image[end++] = '\0';
  179. end = start + ((end - start + 15) & ~15);
  180. OpenBIOS_finish_partition(part_header, end - start);
  181. // free partition
  182. start = end;
  183. part_header = (struct OpenBIOS_nvpart_v1 *)&image[start];
  184. part_header->signature = OPENBIOS_PART_FREE;
  185. pstrcpy(part_header->name, sizeof(part_header->name), "free");
  186. end = 0x1fd0;
  187. OpenBIOS_finish_partition(part_header, end - start);
  188. Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr,
  189. nvram_machine_id);
  190. for (i = 0; i < sizeof(image); i++)
  191. m48t59_write(nvram, i, image[i]);
  192. }
  193. static DeviceState *slavio_intctl;
  194. void pic_info(Monitor *mon)
  195. {
  196. if (slavio_intctl)
  197. slavio_pic_info(mon, slavio_intctl);
  198. }
  199. void irq_info(Monitor *mon)
  200. {
  201. if (slavio_intctl)
  202. slavio_irq_info(mon, slavio_intctl);
  203. }
  204. void cpu_check_irqs(CPUState *env)
  205. {
  206. if (env->pil_in && (env->interrupt_index == 0 ||
  207. (env->interrupt_index & ~15) == TT_EXTINT)) {
  208. unsigned int i;
  209. for (i = 15; i > 0; i--) {
  210. if (env->pil_in & (1 << i)) {
  211. int old_interrupt = env->interrupt_index;
  212. env->interrupt_index = TT_EXTINT | i;
  213. if (old_interrupt != env->interrupt_index) {
  214. trace_sun4m_cpu_interrupt(i);
  215. cpu_interrupt(env, CPU_INTERRUPT_HARD);
  216. }
  217. break;
  218. }
  219. }
  220. } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) {
  221. trace_sun4m_cpu_reset_interrupt(env->interrupt_index & 15);
  222. env->interrupt_index = 0;
  223. cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
  224. }
  225. }
  226. static void cpu_kick_irq(CPUState *env)
  227. {
  228. env->halted = 0;
  229. cpu_check_irqs(env);
  230. qemu_cpu_kick(env);
  231. }
  232. static void cpu_set_irq(void *opaque, int irq, int level)
  233. {
  234. CPUState *env = opaque;
  235. if (level) {
  236. trace_sun4m_cpu_set_irq_raise(irq);
  237. env->pil_in |= 1 << irq;
  238. cpu_kick_irq(env);
  239. } else {
  240. trace_sun4m_cpu_set_irq_lower(irq);
  241. env->pil_in &= ~(1 << irq);
  242. cpu_check_irqs(env);
  243. }
  244. }
  245. static void dummy_cpu_set_irq(void *opaque, int irq, int level)
  246. {
  247. }
  248. static void main_cpu_reset(void *opaque)
  249. {
  250. CPUState *env = opaque;
  251. cpu_reset(env);
  252. env->halted = 0;
  253. }
  254. static void secondary_cpu_reset(void *opaque)
  255. {
  256. CPUState *env = opaque;
  257. cpu_reset(env);
  258. env->halted = 1;
  259. }
  260. static void cpu_halt_signal(void *opaque, int irq, int level)
  261. {
  262. if (level && cpu_single_env)
  263. cpu_interrupt(cpu_single_env, CPU_INTERRUPT_HALT);
  264. }
  265. static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
  266. {
  267. return addr - 0xf0000000ULL;
  268. }
  269. static unsigned long sun4m_load_kernel(const char *kernel_filename,
  270. const char *initrd_filename,
  271. ram_addr_t RAM_size)
  272. {
  273. int linux_boot;
  274. unsigned int i;
  275. long initrd_size, kernel_size;
  276. uint8_t *ptr;
  277. linux_boot = (kernel_filename != NULL);
  278. kernel_size = 0;
  279. if (linux_boot) {
  280. int bswap_needed;
  281. #ifdef BSWAP_NEEDED
  282. bswap_needed = 1;
  283. #else
  284. bswap_needed = 0;
  285. #endif
  286. kernel_size = load_elf(kernel_filename, translate_kernel_address, NULL,
  287. NULL, NULL, NULL, 1, ELF_MACHINE, 0);
  288. if (kernel_size < 0)
  289. kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
  290. RAM_size - KERNEL_LOAD_ADDR, bswap_needed,
  291. TARGET_PAGE_SIZE);
  292. if (kernel_size < 0)
  293. kernel_size = load_image_targphys(kernel_filename,
  294. KERNEL_LOAD_ADDR,
  295. RAM_size - KERNEL_LOAD_ADDR);
  296. if (kernel_size < 0) {
  297. fprintf(stderr, "qemu: could not load kernel '%s'\n",
  298. kernel_filename);
  299. exit(1);
  300. }
  301. /* load initrd */
  302. initrd_size = 0;
  303. if (initrd_filename) {
  304. initrd_size = load_image_targphys(initrd_filename,
  305. INITRD_LOAD_ADDR,
  306. RAM_size - INITRD_LOAD_ADDR);
  307. if (initrd_size < 0) {
  308. fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
  309. initrd_filename);
  310. exit(1);
  311. }
  312. }
  313. if (initrd_size > 0) {
  314. for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
  315. ptr = rom_ptr(KERNEL_LOAD_ADDR + i);
  316. if (ldl_p(ptr) == 0x48647253) { // HdrS
  317. stl_p(ptr + 16, INITRD_LOAD_ADDR);
  318. stl_p(ptr + 20, initrd_size);
  319. break;
  320. }
  321. }
  322. }
  323. }
  324. return kernel_size;
  325. }
  326. static void *iommu_init(target_phys_addr_t addr, uint32_t version, qemu_irq irq)
  327. {
  328. DeviceState *dev;
  329. SysBusDevice *s;
  330. dev = qdev_create(NULL, "iommu");
  331. qdev_prop_set_uint32(dev, "version", version);
  332. qdev_init_nofail(dev);
  333. s = sysbus_from_qdev(dev);
  334. sysbus_connect_irq(s, 0, irq);
  335. sysbus_mmio_map(s, 0, addr);
  336. return s;
  337. }
  338. static void *sparc32_dma_init(target_phys_addr_t daddr, qemu_irq parent_irq,
  339. void *iommu, qemu_irq *dev_irq, int is_ledma)
  340. {
  341. DeviceState *dev;
  342. SysBusDevice *s;
  343. dev = qdev_create(NULL, "sparc32_dma");
  344. qdev_prop_set_ptr(dev, "iommu_opaque", iommu);
  345. qdev_prop_set_uint32(dev, "is_ledma", is_ledma);
  346. qdev_init_nofail(dev);
  347. s = sysbus_from_qdev(dev);
  348. sysbus_connect_irq(s, 0, parent_irq);
  349. *dev_irq = qdev_get_gpio_in(dev, 0);
  350. sysbus_mmio_map(s, 0, daddr);
  351. return s;
  352. }
  353. static void lance_init(NICInfo *nd, target_phys_addr_t leaddr,
  354. void *dma_opaque, qemu_irq irq)
  355. {
  356. DeviceState *dev;
  357. SysBusDevice *s;
  358. qemu_irq reset;
  359. qemu_check_nic_model(&nd_table[0], "lance");
  360. dev = qdev_create(NULL, "lance");
  361. qdev_set_nic_properties(dev, nd);
  362. qdev_prop_set_ptr(dev, "dma", dma_opaque);
  363. qdev_init_nofail(dev);
  364. s = sysbus_from_qdev(dev);
  365. sysbus_mmio_map(s, 0, leaddr);
  366. sysbus_connect_irq(s, 0, irq);
  367. reset = qdev_get_gpio_in(dev, 0);
  368. qdev_connect_gpio_out(dma_opaque, 0, reset);
  369. }
  370. static DeviceState *slavio_intctl_init(target_phys_addr_t addr,
  371. target_phys_addr_t addrg,
  372. qemu_irq **parent_irq)
  373. {
  374. DeviceState *dev;
  375. SysBusDevice *s;
  376. unsigned int i, j;
  377. dev = qdev_create(NULL, "slavio_intctl");
  378. qdev_init_nofail(dev);
  379. s = sysbus_from_qdev(dev);
  380. for (i = 0; i < MAX_CPUS; i++) {
  381. for (j = 0; j < MAX_PILS; j++) {
  382. sysbus_connect_irq(s, i * MAX_PILS + j, parent_irq[i][j]);
  383. }
  384. }
  385. sysbus_mmio_map(s, 0, addrg);
  386. for (i = 0; i < MAX_CPUS; i++) {
  387. sysbus_mmio_map(s, i + 1, addr + i * TARGET_PAGE_SIZE);
  388. }
  389. return dev;
  390. }
  391. #define SYS_TIMER_OFFSET 0x10000ULL
  392. #define CPU_TIMER_OFFSET(cpu) (0x1000ULL * cpu)
  393. static void slavio_timer_init_all(target_phys_addr_t addr, qemu_irq master_irq,
  394. qemu_irq *cpu_irqs, unsigned int num_cpus)
  395. {
  396. DeviceState *dev;
  397. SysBusDevice *s;
  398. unsigned int i;
  399. dev = qdev_create(NULL, "slavio_timer");
  400. qdev_prop_set_uint32(dev, "num_cpus", num_cpus);
  401. qdev_init_nofail(dev);
  402. s = sysbus_from_qdev(dev);
  403. sysbus_connect_irq(s, 0, master_irq);
  404. sysbus_mmio_map(s, 0, addr + SYS_TIMER_OFFSET);
  405. for (i = 0; i < MAX_CPUS; i++) {
  406. sysbus_mmio_map(s, i + 1, addr + (target_phys_addr_t)CPU_TIMER_OFFSET(i));
  407. sysbus_connect_irq(s, i + 1, cpu_irqs[i]);
  408. }
  409. }
  410. #define MISC_LEDS 0x01600000
  411. #define MISC_CFG 0x01800000
  412. #define MISC_DIAG 0x01a00000
  413. #define MISC_MDM 0x01b00000
  414. #define MISC_SYS 0x01f00000
  415. static void slavio_misc_init(target_phys_addr_t base,
  416. target_phys_addr_t aux1_base,
  417. target_phys_addr_t aux2_base, qemu_irq irq,
  418. qemu_irq fdc_tc)
  419. {
  420. DeviceState *dev;
  421. SysBusDevice *s;
  422. dev = qdev_create(NULL, "slavio_misc");
  423. qdev_init_nofail(dev);
  424. s = sysbus_from_qdev(dev);
  425. if (base) {
  426. /* 8 bit registers */
  427. /* Slavio control */
  428. sysbus_mmio_map(s, 0, base + MISC_CFG);
  429. /* Diagnostics */
  430. sysbus_mmio_map(s, 1, base + MISC_DIAG);
  431. /* Modem control */
  432. sysbus_mmio_map(s, 2, base + MISC_MDM);
  433. /* 16 bit registers */
  434. /* ss600mp diag LEDs */
  435. sysbus_mmio_map(s, 3, base + MISC_LEDS);
  436. /* 32 bit registers */
  437. /* System control */
  438. sysbus_mmio_map(s, 4, base + MISC_SYS);
  439. }
  440. if (aux1_base) {
  441. /* AUX 1 (Misc System Functions) */
  442. sysbus_mmio_map(s, 5, aux1_base);
  443. }
  444. if (aux2_base) {
  445. /* AUX 2 (Software Powerdown Control) */
  446. sysbus_mmio_map(s, 6, aux2_base);
  447. }
  448. sysbus_connect_irq(s, 0, irq);
  449. sysbus_connect_irq(s, 1, fdc_tc);
  450. qemu_system_powerdown = qdev_get_gpio_in(dev, 0);
  451. }
  452. static void ecc_init(target_phys_addr_t base, qemu_irq irq, uint32_t version)
  453. {
  454. DeviceState *dev;
  455. SysBusDevice *s;
  456. dev = qdev_create(NULL, "eccmemctl");
  457. qdev_prop_set_uint32(dev, "version", version);
  458. qdev_init_nofail(dev);
  459. s = sysbus_from_qdev(dev);
  460. sysbus_connect_irq(s, 0, irq);
  461. sysbus_mmio_map(s, 0, base);
  462. if (version == 0) { // SS-600MP only
  463. sysbus_mmio_map(s, 1, base + 0x1000);
  464. }
  465. }
  466. static void apc_init(target_phys_addr_t power_base, qemu_irq cpu_halt)
  467. {
  468. DeviceState *dev;
  469. SysBusDevice *s;
  470. dev = qdev_create(NULL, "apc");
  471. qdev_init_nofail(dev);
  472. s = sysbus_from_qdev(dev);
  473. /* Power management (APC) XXX: not a Slavio device */
  474. sysbus_mmio_map(s, 0, power_base);
  475. sysbus_connect_irq(s, 0, cpu_halt);
  476. }
  477. static void tcx_init(target_phys_addr_t addr, int vram_size, int width,
  478. int height, int depth)
  479. {
  480. DeviceState *dev;
  481. SysBusDevice *s;
  482. dev = qdev_create(NULL, "SUNW,tcx");
  483. qdev_prop_set_taddr(dev, "addr", addr);
  484. qdev_prop_set_uint32(dev, "vram_size", vram_size);
  485. qdev_prop_set_uint16(dev, "width", width);
  486. qdev_prop_set_uint16(dev, "height", height);
  487. qdev_prop_set_uint16(dev, "depth", depth);
  488. qdev_init_nofail(dev);
  489. s = sysbus_from_qdev(dev);
  490. /* 8-bit plane */
  491. sysbus_mmio_map(s, 0, addr + 0x00800000ULL);
  492. /* DAC */
  493. sysbus_mmio_map(s, 1, addr + 0x00200000ULL);
  494. /* TEC (dummy) */
  495. sysbus_mmio_map(s, 2, addr + 0x00700000ULL);
  496. /* THC 24 bit: NetBSD writes here even with 8-bit display: dummy */
  497. sysbus_mmio_map(s, 3, addr + 0x00301000ULL);
  498. if (depth == 24) {
  499. /* 24-bit plane */
  500. sysbus_mmio_map(s, 4, addr + 0x02000000ULL);
  501. /* Control plane */
  502. sysbus_mmio_map(s, 5, addr + 0x0a000000ULL);
  503. } else {
  504. /* THC 8 bit (dummy) */
  505. sysbus_mmio_map(s, 4, addr + 0x00300000ULL);
  506. }
  507. }
  508. /* NCR89C100/MACIO Internal ID register */
  509. static const uint8_t idreg_data[] = { 0xfe, 0x81, 0x01, 0x03 };
  510. static void idreg_init(target_phys_addr_t addr)
  511. {
  512. DeviceState *dev;
  513. SysBusDevice *s;
  514. dev = qdev_create(NULL, "macio_idreg");
  515. qdev_init_nofail(dev);
  516. s = sysbus_from_qdev(dev);
  517. sysbus_mmio_map(s, 0, addr);
  518. cpu_physical_memory_write_rom(addr, idreg_data, sizeof(idreg_data));
  519. }
  520. static int idreg_init1(SysBusDevice *dev)
  521. {
  522. ram_addr_t idreg_offset;
  523. idreg_offset = qemu_ram_alloc(NULL, "sun4m.idreg", sizeof(idreg_data));
  524. sysbus_init_mmio(dev, sizeof(idreg_data), idreg_offset | IO_MEM_ROM);
  525. return 0;
  526. }
  527. static SysBusDeviceInfo idreg_info = {
  528. .init = idreg_init1,
  529. .qdev.name = "macio_idreg",
  530. .qdev.size = sizeof(SysBusDevice),
  531. };
  532. static void idreg_register_devices(void)
  533. {
  534. sysbus_register_withprop(&idreg_info);
  535. }
  536. device_init(idreg_register_devices);
  537. /* SS-5 TCX AFX register */
  538. static void afx_init(target_phys_addr_t addr)
  539. {
  540. DeviceState *dev;
  541. SysBusDevice *s;
  542. dev = qdev_create(NULL, "tcx_afx");
  543. qdev_init_nofail(dev);
  544. s = sysbus_from_qdev(dev);
  545. sysbus_mmio_map(s, 0, addr);
  546. }
  547. static int afx_init1(SysBusDevice *dev)
  548. {
  549. ram_addr_t afx_offset;
  550. afx_offset = qemu_ram_alloc(NULL, "sun4m.afx", 4);
  551. sysbus_init_mmio(dev, 4, afx_offset | IO_MEM_RAM);
  552. return 0;
  553. }
  554. static SysBusDeviceInfo afx_info = {
  555. .init = afx_init1,
  556. .qdev.name = "tcx_afx",
  557. .qdev.size = sizeof(SysBusDevice),
  558. };
  559. static void afx_register_devices(void)
  560. {
  561. sysbus_register_withprop(&afx_info);
  562. }
  563. device_init(afx_register_devices);
  564. /* Boot PROM (OpenBIOS) */
  565. static uint64_t translate_prom_address(void *opaque, uint64_t addr)
  566. {
  567. target_phys_addr_t *base_addr = (target_phys_addr_t *)opaque;
  568. return addr + *base_addr - PROM_VADDR;
  569. }
  570. static void prom_init(target_phys_addr_t addr, const char *bios_name)
  571. {
  572. DeviceState *dev;
  573. SysBusDevice *s;
  574. char *filename;
  575. int ret;
  576. dev = qdev_create(NULL, "openprom");
  577. qdev_init_nofail(dev);
  578. s = sysbus_from_qdev(dev);
  579. sysbus_mmio_map(s, 0, addr);
  580. /* load boot prom */
  581. if (bios_name == NULL) {
  582. bios_name = PROM_FILENAME;
  583. }
  584. filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
  585. if (filename) {
  586. ret = load_elf(filename, translate_prom_address, &addr, NULL,
  587. NULL, NULL, 1, ELF_MACHINE, 0);
  588. if (ret < 0 || ret > PROM_SIZE_MAX) {
  589. ret = load_image_targphys(filename, addr, PROM_SIZE_MAX);
  590. }
  591. qemu_free(filename);
  592. } else {
  593. ret = -1;
  594. }
  595. if (ret < 0 || ret > PROM_SIZE_MAX) {
  596. fprintf(stderr, "qemu: could not load prom '%s'\n", bios_name);
  597. exit(1);
  598. }
  599. }
  600. static int prom_init1(SysBusDevice *dev)
  601. {
  602. ram_addr_t prom_offset;
  603. prom_offset = qemu_ram_alloc(NULL, "sun4m.prom", PROM_SIZE_MAX);
  604. sysbus_init_mmio(dev, PROM_SIZE_MAX, prom_offset | IO_MEM_ROM);
  605. return 0;
  606. }
  607. static SysBusDeviceInfo prom_info = {
  608. .init = prom_init1,
  609. .qdev.name = "openprom",
  610. .qdev.size = sizeof(SysBusDevice),
  611. .qdev.props = (Property[]) {
  612. {/* end of property list */}
  613. }
  614. };
  615. static void prom_register_devices(void)
  616. {
  617. sysbus_register_withprop(&prom_info);
  618. }
  619. device_init(prom_register_devices);
  620. typedef struct RamDevice
  621. {
  622. SysBusDevice busdev;
  623. uint64_t size;
  624. } RamDevice;
  625. /* System RAM */
  626. static int ram_init1(SysBusDevice *dev)
  627. {
  628. ram_addr_t RAM_size, ram_offset;
  629. RamDevice *d = FROM_SYSBUS(RamDevice, dev);
  630. RAM_size = d->size;
  631. ram_offset = qemu_ram_alloc(NULL, "sun4m.ram", RAM_size);
  632. sysbus_init_mmio(dev, RAM_size, ram_offset);
  633. return 0;
  634. }
  635. static void ram_init(target_phys_addr_t addr, ram_addr_t RAM_size,
  636. uint64_t max_mem)
  637. {
  638. DeviceState *dev;
  639. SysBusDevice *s;
  640. RamDevice *d;
  641. /* allocate RAM */
  642. if ((uint64_t)RAM_size > max_mem) {
  643. fprintf(stderr,
  644. "qemu: Too much memory for this machine: %d, maximum %d\n",
  645. (unsigned int)(RAM_size / (1024 * 1024)),
  646. (unsigned int)(max_mem / (1024 * 1024)));
  647. exit(1);
  648. }
  649. dev = qdev_create(NULL, "memory");
  650. s = sysbus_from_qdev(dev);
  651. d = FROM_SYSBUS(RamDevice, s);
  652. d->size = RAM_size;
  653. qdev_init_nofail(dev);
  654. sysbus_mmio_map(s, 0, addr);
  655. }
  656. static SysBusDeviceInfo ram_info = {
  657. .init = ram_init1,
  658. .qdev.name = "memory",
  659. .qdev.size = sizeof(RamDevice),
  660. .qdev.props = (Property[]) {
  661. DEFINE_PROP_UINT64("size", RamDevice, size, 0),
  662. DEFINE_PROP_END_OF_LIST(),
  663. }
  664. };
  665. static void ram_register_devices(void)
  666. {
  667. sysbus_register_withprop(&ram_info);
  668. }
  669. device_init(ram_register_devices);
  670. static void cpu_devinit(const char *cpu_model, unsigned int id,
  671. uint64_t prom_addr, qemu_irq **cpu_irqs)
  672. {
  673. CPUState *env;
  674. env = cpu_init(cpu_model);
  675. if (!env) {
  676. fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
  677. exit(1);
  678. }
  679. cpu_sparc_set_id(env, id);
  680. if (id == 0) {
  681. qemu_register_reset(main_cpu_reset, env);
  682. } else {
  683. qemu_register_reset(secondary_cpu_reset, env);
  684. env->halted = 1;
  685. }
  686. *cpu_irqs = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
  687. env->prom_addr = prom_addr;
  688. }
  689. static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
  690. const char *boot_device,
  691. const char *kernel_filename,
  692. const char *kernel_cmdline,
  693. const char *initrd_filename, const char *cpu_model)
  694. {
  695. unsigned int i;
  696. void *iommu, *espdma, *ledma, *nvram;
  697. qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS],
  698. espdma_irq, ledma_irq;
  699. qemu_irq esp_reset, dma_enable;
  700. qemu_irq fdc_tc;
  701. qemu_irq *cpu_halt;
  702. unsigned long kernel_size;
  703. DriveInfo *fd[MAX_FD];
  704. void *fw_cfg;
  705. unsigned int num_vsimms;
  706. /* init CPUs */
  707. if (!cpu_model)
  708. cpu_model = hwdef->default_cpu_model;
  709. for(i = 0; i < smp_cpus; i++) {
  710. cpu_devinit(cpu_model, i, hwdef->slavio_base, &cpu_irqs[i]);
  711. }
  712. for (i = smp_cpus; i < MAX_CPUS; i++)
  713. cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
  714. /* set up devices */
  715. ram_init(0, RAM_size, hwdef->max_mem);
  716. /* models without ECC don't trap when missing ram is accessed */
  717. if (!hwdef->ecc_base) {
  718. empty_slot_init(RAM_size, hwdef->max_mem - RAM_size);
  719. }
  720. prom_init(hwdef->slavio_base, bios_name);
  721. slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
  722. hwdef->intctl_base + 0x10000ULL,
  723. cpu_irqs);
  724. for (i = 0; i < 32; i++) {
  725. slavio_irq[i] = qdev_get_gpio_in(slavio_intctl, i);
  726. }
  727. for (i = 0; i < MAX_CPUS; i++) {
  728. slavio_cpu_irq[i] = qdev_get_gpio_in(slavio_intctl, 32 + i);
  729. }
  730. if (hwdef->idreg_base) {
  731. idreg_init(hwdef->idreg_base);
  732. }
  733. if (hwdef->afx_base) {
  734. afx_init(hwdef->afx_base);
  735. }
  736. iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
  737. slavio_irq[30]);
  738. if (hwdef->iommu_pad_base) {
  739. /* On the real hardware (SS-5, LX) the MMU is not padded, but aliased.
  740. Software shouldn't use aliased addresses, neither should it crash
  741. when does. Using empty_slot instead of aliasing can help with
  742. debugging such accesses */
  743. empty_slot_init(hwdef->iommu_pad_base,hwdef->iommu_pad_len);
  744. }
  745. espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[18],
  746. iommu, &espdma_irq, 0);
  747. ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
  748. slavio_irq[16], iommu, &ledma_irq, 1);
  749. if (graphic_depth != 8 && graphic_depth != 24) {
  750. fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
  751. exit (1);
  752. }
  753. num_vsimms = 0;
  754. if (num_vsimms == 0) {
  755. tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
  756. graphic_depth);
  757. }
  758. for (i = num_vsimms; i < MAX_VSIMMS; i++) {
  759. /* vsimm registers probed by OBP */
  760. if (hwdef->vsimm[i].reg_base) {
  761. empty_slot_init(hwdef->vsimm[i].reg_base, 0x2000);
  762. }
  763. }
  764. if (hwdef->sx_base) {
  765. empty_slot_init(hwdef->sx_base, 0x2000);
  766. }
  767. lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
  768. nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x2000, 8);
  769. slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
  770. slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[14],
  771. display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
  772. // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
  773. // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
  774. escc_init(hwdef->serial_base, slavio_irq[15], slavio_irq[15],
  775. serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
  776. cpu_halt = qemu_allocate_irqs(cpu_halt_signal, NULL, 1);
  777. slavio_misc_init(hwdef->slavio_base, hwdef->aux1_base, hwdef->aux2_base,
  778. slavio_irq[30], fdc_tc);
  779. if (hwdef->apc_base) {
  780. apc_init(hwdef->apc_base, cpu_halt[0]);
  781. }
  782. if (hwdef->fd_base) {
  783. /* there is zero or one floppy drive */
  784. memset(fd, 0, sizeof(fd));
  785. fd[0] = drive_get(IF_FLOPPY, 0, 0);
  786. sun4m_fdctrl_init(slavio_irq[22], hwdef->fd_base, fd,
  787. &fdc_tc);
  788. }
  789. if (drive_get_max_bus(IF_SCSI) > 0) {
  790. fprintf(stderr, "qemu: too many SCSI bus\n");
  791. exit(1);
  792. }
  793. esp_init(hwdef->esp_base, 2,
  794. espdma_memory_read, espdma_memory_write,
  795. espdma, espdma_irq, &esp_reset, &dma_enable);
  796. qdev_connect_gpio_out(espdma, 0, esp_reset);
  797. qdev_connect_gpio_out(espdma, 1, dma_enable);
  798. if (hwdef->cs_base) {
  799. sysbus_create_simple("SUNW,CS4231", hwdef->cs_base,
  800. slavio_irq[5]);
  801. }
  802. if (hwdef->dbri_base) {
  803. /* ISDN chip with attached CS4215 audio codec */
  804. /* prom space */
  805. empty_slot_init(hwdef->dbri_base+0x1000, 0x30);
  806. /* reg space */
  807. empty_slot_init(hwdef->dbri_base+0x10000, 0x100);
  808. }
  809. if (hwdef->bpp_base) {
  810. /* parallel port */
  811. empty_slot_init(hwdef->bpp_base, 0x20);
  812. }
  813. kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
  814. RAM_size);
  815. nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
  816. boot_device, RAM_size, kernel_size, graphic_width,
  817. graphic_height, graphic_depth, hwdef->nvram_machine_id,
  818. "Sun4m");
  819. if (hwdef->ecc_base)
  820. ecc_init(hwdef->ecc_base, slavio_irq[28],
  821. hwdef->ecc_version);
  822. fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
  823. fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
  824. fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
  825. fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
  826. fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
  827. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
  828. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
  829. if (kernel_cmdline) {
  830. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
  831. pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
  832. fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
  833. (uint8_t*)strdup(kernel_cmdline),
  834. strlen(kernel_cmdline) + 1);
  835. fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
  836. strlen(kernel_cmdline) + 1);
  837. } else {
  838. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
  839. fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
  840. }
  841. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
  842. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
  843. fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
  844. qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
  845. }
  846. enum {
  847. ss2_id = 0,
  848. ss5_id = 32,
  849. vger_id,
  850. lx_id,
  851. ss4_id,
  852. scls_id,
  853. sbook_id,
  854. ss10_id = 64,
  855. ss20_id,
  856. ss600mp_id,
  857. ss1000_id = 96,
  858. ss2000_id,
  859. };
  860. static const struct sun4m_hwdef sun4m_hwdefs[] = {
  861. /* SS-5 */
  862. {
  863. .iommu_base = 0x10000000,
  864. .iommu_pad_base = 0x10004000,
  865. .iommu_pad_len = 0x0fffb000,
  866. .tcx_base = 0x50000000,
  867. .cs_base = 0x6c000000,
  868. .slavio_base = 0x70000000,
  869. .ms_kb_base = 0x71000000,
  870. .serial_base = 0x71100000,
  871. .nvram_base = 0x71200000,
  872. .fd_base = 0x71400000,
  873. .counter_base = 0x71d00000,
  874. .intctl_base = 0x71e00000,
  875. .idreg_base = 0x78000000,
  876. .dma_base = 0x78400000,
  877. .esp_base = 0x78800000,
  878. .le_base = 0x78c00000,
  879. .apc_base = 0x6a000000,
  880. .afx_base = 0x6e000000,
  881. .aux1_base = 0x71900000,
  882. .aux2_base = 0x71910000,
  883. .nvram_machine_id = 0x80,
  884. .machine_id = ss5_id,
  885. .iommu_version = 0x05000000,
  886. .max_mem = 0x10000000,
  887. .default_cpu_model = "Fujitsu MB86904",
  888. },
  889. /* SS-10 */
  890. {
  891. .iommu_base = 0xfe0000000ULL,
  892. .tcx_base = 0xe20000000ULL,
  893. .slavio_base = 0xff0000000ULL,
  894. .ms_kb_base = 0xff1000000ULL,
  895. .serial_base = 0xff1100000ULL,
  896. .nvram_base = 0xff1200000ULL,
  897. .fd_base = 0xff1700000ULL,
  898. .counter_base = 0xff1300000ULL,
  899. .intctl_base = 0xff1400000ULL,
  900. .idreg_base = 0xef0000000ULL,
  901. .dma_base = 0xef0400000ULL,
  902. .esp_base = 0xef0800000ULL,
  903. .le_base = 0xef0c00000ULL,
  904. .apc_base = 0xefa000000ULL, // XXX should not exist
  905. .aux1_base = 0xff1800000ULL,
  906. .aux2_base = 0xff1a01000ULL,
  907. .ecc_base = 0xf00000000ULL,
  908. .ecc_version = 0x10000000, // version 0, implementation 1
  909. .nvram_machine_id = 0x72,
  910. .machine_id = ss10_id,
  911. .iommu_version = 0x03000000,
  912. .max_mem = 0xf00000000ULL,
  913. .default_cpu_model = "TI SuperSparc II",
  914. },
  915. /* SS-600MP */
  916. {
  917. .iommu_base = 0xfe0000000ULL,
  918. .tcx_base = 0xe20000000ULL,
  919. .slavio_base = 0xff0000000ULL,
  920. .ms_kb_base = 0xff1000000ULL,
  921. .serial_base = 0xff1100000ULL,
  922. .nvram_base = 0xff1200000ULL,
  923. .counter_base = 0xff1300000ULL,
  924. .intctl_base = 0xff1400000ULL,
  925. .dma_base = 0xef0081000ULL,
  926. .esp_base = 0xef0080000ULL,
  927. .le_base = 0xef0060000ULL,
  928. .apc_base = 0xefa000000ULL, // XXX should not exist
  929. .aux1_base = 0xff1800000ULL,
  930. .aux2_base = 0xff1a01000ULL, // XXX should not exist
  931. .ecc_base = 0xf00000000ULL,
  932. .ecc_version = 0x00000000, // version 0, implementation 0
  933. .nvram_machine_id = 0x71,
  934. .machine_id = ss600mp_id,
  935. .iommu_version = 0x01000000,
  936. .max_mem = 0xf00000000ULL,
  937. .default_cpu_model = "TI SuperSparc II",
  938. },
  939. /* SS-20 */
  940. {
  941. .iommu_base = 0xfe0000000ULL,
  942. .tcx_base = 0xe20000000ULL,
  943. .slavio_base = 0xff0000000ULL,
  944. .ms_kb_base = 0xff1000000ULL,
  945. .serial_base = 0xff1100000ULL,
  946. .nvram_base = 0xff1200000ULL,
  947. .fd_base = 0xff1700000ULL,
  948. .counter_base = 0xff1300000ULL,
  949. .intctl_base = 0xff1400000ULL,
  950. .idreg_base = 0xef0000000ULL,
  951. .dma_base = 0xef0400000ULL,
  952. .esp_base = 0xef0800000ULL,
  953. .le_base = 0xef0c00000ULL,
  954. .bpp_base = 0xef4800000ULL,
  955. .apc_base = 0xefa000000ULL, // XXX should not exist
  956. .aux1_base = 0xff1800000ULL,
  957. .aux2_base = 0xff1a01000ULL,
  958. .dbri_base = 0xee0000000ULL,
  959. .sx_base = 0xf80000000ULL,
  960. .vsimm = {
  961. {
  962. .reg_base = 0x9c000000ULL,
  963. .vram_base = 0xfc000000ULL
  964. }, {
  965. .reg_base = 0x90000000ULL,
  966. .vram_base = 0xf0000000ULL
  967. }, {
  968. .reg_base = 0x94000000ULL
  969. }, {
  970. .reg_base = 0x98000000ULL
  971. }
  972. },
  973. .ecc_base = 0xf00000000ULL,
  974. .ecc_version = 0x20000000, // version 0, implementation 2
  975. .nvram_machine_id = 0x72,
  976. .machine_id = ss20_id,
  977. .iommu_version = 0x13000000,
  978. .max_mem = 0xf00000000ULL,
  979. .default_cpu_model = "TI SuperSparc II",
  980. },
  981. /* Voyager */
  982. {
  983. .iommu_base = 0x10000000,
  984. .tcx_base = 0x50000000,
  985. .slavio_base = 0x70000000,
  986. .ms_kb_base = 0x71000000,
  987. .serial_base = 0x71100000,
  988. .nvram_base = 0x71200000,
  989. .fd_base = 0x71400000,
  990. .counter_base = 0x71d00000,
  991. .intctl_base = 0x71e00000,
  992. .idreg_base = 0x78000000,
  993. .dma_base = 0x78400000,
  994. .esp_base = 0x78800000,
  995. .le_base = 0x78c00000,
  996. .apc_base = 0x71300000, // pmc
  997. .aux1_base = 0x71900000,
  998. .aux2_base = 0x71910000,
  999. .nvram_machine_id = 0x80,
  1000. .machine_id = vger_id,
  1001. .iommu_version = 0x05000000,
  1002. .max_mem = 0x10000000,
  1003. .default_cpu_model = "Fujitsu MB86904",
  1004. },
  1005. /* LX */
  1006. {
  1007. .iommu_base = 0x10000000,
  1008. .iommu_pad_base = 0x10004000,
  1009. .iommu_pad_len = 0x0fffb000,
  1010. .tcx_base = 0x50000000,
  1011. .slavio_base = 0x70000000,
  1012. .ms_kb_base = 0x71000000,
  1013. .serial_base = 0x71100000,
  1014. .nvram_base = 0x71200000,
  1015. .fd_base = 0x71400000,
  1016. .counter_base = 0x71d00000,
  1017. .intctl_base = 0x71e00000,
  1018. .idreg_base = 0x78000000,
  1019. .dma_base = 0x78400000,
  1020. .esp_base = 0x78800000,
  1021. .le_base = 0x78c00000,
  1022. .aux1_base = 0x71900000,
  1023. .aux2_base = 0x71910000,
  1024. .nvram_machine_id = 0x80,
  1025. .machine_id = lx_id,
  1026. .iommu_version = 0x04000000,
  1027. .max_mem = 0x10000000,
  1028. .default_cpu_model = "TI MicroSparc I",
  1029. },
  1030. /* SS-4 */
  1031. {
  1032. .iommu_base = 0x10000000,
  1033. .tcx_base = 0x50000000,
  1034. .cs_base = 0x6c000000,
  1035. .slavio_base = 0x70000000,
  1036. .ms_kb_base = 0x71000000,
  1037. .serial_base = 0x71100000,
  1038. .nvram_base = 0x71200000,
  1039. .fd_base = 0x71400000,
  1040. .counter_base = 0x71d00000,
  1041. .intctl_base = 0x71e00000,
  1042. .idreg_base = 0x78000000,
  1043. .dma_base = 0x78400000,
  1044. .esp_base = 0x78800000,
  1045. .le_base = 0x78c00000,
  1046. .apc_base = 0x6a000000,
  1047. .aux1_base = 0x71900000,
  1048. .aux2_base = 0x71910000,
  1049. .nvram_machine_id = 0x80,
  1050. .machine_id = ss4_id,
  1051. .iommu_version = 0x05000000,
  1052. .max_mem = 0x10000000,
  1053. .default_cpu_model = "Fujitsu MB86904",
  1054. },
  1055. /* SPARCClassic */
  1056. {
  1057. .iommu_base = 0x10000000,
  1058. .tcx_base = 0x50000000,
  1059. .slavio_base = 0x70000000,
  1060. .ms_kb_base = 0x71000000,
  1061. .serial_base = 0x71100000,
  1062. .nvram_base = 0x71200000,
  1063. .fd_base = 0x71400000,
  1064. .counter_base = 0x71d00000,
  1065. .intctl_base = 0x71e00000,
  1066. .idreg_base = 0x78000000,
  1067. .dma_base = 0x78400000,
  1068. .esp_base = 0x78800000,
  1069. .le_base = 0x78c00000,
  1070. .apc_base = 0x6a000000,
  1071. .aux1_base = 0x71900000,
  1072. .aux2_base = 0x71910000,
  1073. .nvram_machine_id = 0x80,
  1074. .machine_id = scls_id,
  1075. .iommu_version = 0x05000000,
  1076. .max_mem = 0x10000000,
  1077. .default_cpu_model = "TI MicroSparc I",
  1078. },
  1079. /* SPARCbook */
  1080. {
  1081. .iommu_base = 0x10000000,
  1082. .tcx_base = 0x50000000, // XXX
  1083. .slavio_base = 0x70000000,
  1084. .ms_kb_base = 0x71000000,
  1085. .serial_base = 0x71100000,
  1086. .nvram_base = 0x71200000,
  1087. .fd_base = 0x71400000,
  1088. .counter_base = 0x71d00000,
  1089. .intctl_base = 0x71e00000,
  1090. .idreg_base = 0x78000000,
  1091. .dma_base = 0x78400000,
  1092. .esp_base = 0x78800000,
  1093. .le_base = 0x78c00000,
  1094. .apc_base = 0x6a000000,
  1095. .aux1_base = 0x71900000,
  1096. .aux2_base = 0x71910000,
  1097. .nvram_machine_id = 0x80,
  1098. .machine_id = sbook_id,
  1099. .iommu_version = 0x05000000,
  1100. .max_mem = 0x10000000,
  1101. .default_cpu_model = "TI MicroSparc I",
  1102. },
  1103. };
  1104. /* SPARCstation 5 hardware initialisation */
  1105. static void ss5_init(ram_addr_t RAM_size,
  1106. const char *boot_device,
  1107. const char *kernel_filename, const char *kernel_cmdline,
  1108. const char *initrd_filename, const char *cpu_model)
  1109. {
  1110. sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, kernel_filename,
  1111. kernel_cmdline, initrd_filename, cpu_model);
  1112. }
  1113. /* SPARCstation 10 hardware initialisation */
  1114. static void ss10_init(ram_addr_t RAM_size,
  1115. const char *boot_device,
  1116. const char *kernel_filename, const char *kernel_cmdline,
  1117. const char *initrd_filename, const char *cpu_model)
  1118. {
  1119. sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, kernel_filename,
  1120. kernel_cmdline, initrd_filename, cpu_model);
  1121. }
  1122. /* SPARCserver 600MP hardware initialisation */
  1123. static void ss600mp_init(ram_addr_t RAM_size,
  1124. const char *boot_device,
  1125. const char *kernel_filename,
  1126. const char *kernel_cmdline,
  1127. const char *initrd_filename, const char *cpu_model)
  1128. {
  1129. sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, kernel_filename,
  1130. kernel_cmdline, initrd_filename, cpu_model);
  1131. }
  1132. /* SPARCstation 20 hardware initialisation */
  1133. static void ss20_init(ram_addr_t RAM_size,
  1134. const char *boot_device,
  1135. const char *kernel_filename, const char *kernel_cmdline,
  1136. const char *initrd_filename, const char *cpu_model)
  1137. {
  1138. sun4m_hw_init(&sun4m_hwdefs[3], RAM_size, boot_device, kernel_filename,
  1139. kernel_cmdline, initrd_filename, cpu_model);
  1140. }
  1141. /* SPARCstation Voyager hardware initialisation */
  1142. static void vger_init(ram_addr_t RAM_size,
  1143. const char *boot_device,
  1144. const char *kernel_filename, const char *kernel_cmdline,
  1145. const char *initrd_filename, const char *cpu_model)
  1146. {
  1147. sun4m_hw_init(&sun4m_hwdefs[4], RAM_size, boot_device, kernel_filename,
  1148. kernel_cmdline, initrd_filename, cpu_model);
  1149. }
  1150. /* SPARCstation LX hardware initialisation */
  1151. static void ss_lx_init(ram_addr_t RAM_size,
  1152. const char *boot_device,
  1153. const char *kernel_filename, const char *kernel_cmdline,
  1154. const char *initrd_filename, const char *cpu_model)
  1155. {
  1156. sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, kernel_filename,
  1157. kernel_cmdline, initrd_filename, cpu_model);
  1158. }
  1159. /* SPARCstation 4 hardware initialisation */
  1160. static void ss4_init(ram_addr_t RAM_size,
  1161. const char *boot_device,
  1162. const char *kernel_filename, const char *kernel_cmdline,
  1163. const char *initrd_filename, const char *cpu_model)
  1164. {
  1165. sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, kernel_filename,
  1166. kernel_cmdline, initrd_filename, cpu_model);
  1167. }
  1168. /* SPARCClassic hardware initialisation */
  1169. static void scls_init(ram_addr_t RAM_size,
  1170. const char *boot_device,
  1171. const char *kernel_filename, const char *kernel_cmdline,
  1172. const char *initrd_filename, const char *cpu_model)
  1173. {
  1174. sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, kernel_filename,
  1175. kernel_cmdline, initrd_filename, cpu_model);
  1176. }
  1177. /* SPARCbook hardware initialisation */
  1178. static void sbook_init(ram_addr_t RAM_size,
  1179. const char *boot_device,
  1180. const char *kernel_filename, const char *kernel_cmdline,
  1181. const char *initrd_filename, const char *cpu_model)
  1182. {
  1183. sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, kernel_filename,
  1184. kernel_cmdline, initrd_filename, cpu_model);
  1185. }
  1186. static QEMUMachine ss5_machine = {
  1187. .name = "SS-5",
  1188. .desc = "Sun4m platform, SPARCstation 5",
  1189. .init = ss5_init,
  1190. .use_scsi = 1,
  1191. .is_default = 1,
  1192. };
  1193. static QEMUMachine ss10_machine = {
  1194. .name = "SS-10",
  1195. .desc = "Sun4m platform, SPARCstation 10",
  1196. .init = ss10_init,
  1197. .use_scsi = 1,
  1198. .max_cpus = 4,
  1199. };
  1200. static QEMUMachine ss600mp_machine = {
  1201. .name = "SS-600MP",
  1202. .desc = "Sun4m platform, SPARCserver 600MP",
  1203. .init = ss600mp_init,
  1204. .use_scsi = 1,
  1205. .max_cpus = 4,
  1206. };
  1207. static QEMUMachine ss20_machine = {
  1208. .name = "SS-20",
  1209. .desc = "Sun4m platform, SPARCstation 20",
  1210. .init = ss20_init,
  1211. .use_scsi = 1,
  1212. .max_cpus = 4,
  1213. };
  1214. static QEMUMachine voyager_machine = {
  1215. .name = "Voyager",
  1216. .desc = "Sun4m platform, SPARCstation Voyager",
  1217. .init = vger_init,
  1218. .use_scsi = 1,
  1219. };
  1220. static QEMUMachine ss_lx_machine = {
  1221. .name = "LX",
  1222. .desc = "Sun4m platform, SPARCstation LX",
  1223. .init = ss_lx_init,
  1224. .use_scsi = 1,
  1225. };
  1226. static QEMUMachine ss4_machine = {
  1227. .name = "SS-4",
  1228. .desc = "Sun4m platform, SPARCstation 4",
  1229. .init = ss4_init,
  1230. .use_scsi = 1,
  1231. };
  1232. static QEMUMachine scls_machine = {
  1233. .name = "SPARCClassic",
  1234. .desc = "Sun4m platform, SPARCClassic",
  1235. .init = scls_init,
  1236. .use_scsi = 1,
  1237. };
  1238. static QEMUMachine sbook_machine = {
  1239. .name = "SPARCbook",
  1240. .desc = "Sun4m platform, SPARCbook",
  1241. .init = sbook_init,
  1242. .use_scsi = 1,
  1243. };
  1244. static const struct sun4d_hwdef sun4d_hwdefs[] = {
  1245. /* SS-1000 */
  1246. {
  1247. .iounit_bases = {
  1248. 0xfe0200000ULL,
  1249. 0xfe1200000ULL,
  1250. 0xfe2200000ULL,
  1251. 0xfe3200000ULL,
  1252. -1,
  1253. },
  1254. .tcx_base = 0x820000000ULL,
  1255. .slavio_base = 0xf00000000ULL,
  1256. .ms_kb_base = 0xf00240000ULL,
  1257. .serial_base = 0xf00200000ULL,
  1258. .nvram_base = 0xf00280000ULL,
  1259. .counter_base = 0xf00300000ULL,
  1260. .espdma_base = 0x800081000ULL,
  1261. .esp_base = 0x800080000ULL,
  1262. .ledma_base = 0x800040000ULL,
  1263. .le_base = 0x800060000ULL,
  1264. .sbi_base = 0xf02800000ULL,
  1265. .nvram_machine_id = 0x80,
  1266. .machine_id = ss1000_id,
  1267. .iounit_version = 0x03000000,
  1268. .max_mem = 0xf00000000ULL,
  1269. .default_cpu_model = "TI SuperSparc II",
  1270. },
  1271. /* SS-2000 */
  1272. {
  1273. .iounit_bases = {
  1274. 0xfe0200000ULL,
  1275. 0xfe1200000ULL,
  1276. 0xfe2200000ULL,
  1277. 0xfe3200000ULL,
  1278. 0xfe4200000ULL,
  1279. },
  1280. .tcx_base = 0x820000000ULL,
  1281. .slavio_base = 0xf00000000ULL,
  1282. .ms_kb_base = 0xf00240000ULL,
  1283. .serial_base = 0xf00200000ULL,
  1284. .nvram_base = 0xf00280000ULL,
  1285. .counter_base = 0xf00300000ULL,
  1286. .espdma_base = 0x800081000ULL,
  1287. .esp_base = 0x800080000ULL,
  1288. .ledma_base = 0x800040000ULL,
  1289. .le_base = 0x800060000ULL,
  1290. .sbi_base = 0xf02800000ULL,
  1291. .nvram_machine_id = 0x80,
  1292. .machine_id = ss2000_id,
  1293. .iounit_version = 0x03000000,
  1294. .max_mem = 0xf00000000ULL,
  1295. .default_cpu_model = "TI SuperSparc II",
  1296. },
  1297. };
  1298. static DeviceState *sbi_init(target_phys_addr_t addr, qemu_irq **parent_irq)
  1299. {
  1300. DeviceState *dev;
  1301. SysBusDevice *s;
  1302. unsigned int i;
  1303. dev = qdev_create(NULL, "sbi");
  1304. qdev_init_nofail(dev);
  1305. s = sysbus_from_qdev(dev);
  1306. for (i = 0; i < MAX_CPUS; i++) {
  1307. sysbus_connect_irq(s, i, *parent_irq[i]);
  1308. }
  1309. sysbus_mmio_map(s, 0, addr);
  1310. return dev;
  1311. }
  1312. static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
  1313. const char *boot_device,
  1314. const char *kernel_filename,
  1315. const char *kernel_cmdline,
  1316. const char *initrd_filename, const char *cpu_model)
  1317. {
  1318. unsigned int i;
  1319. void *iounits[MAX_IOUNITS], *espdma, *ledma, *nvram;
  1320. qemu_irq *cpu_irqs[MAX_CPUS], sbi_irq[32], sbi_cpu_irq[MAX_CPUS],
  1321. espdma_irq, ledma_irq;
  1322. qemu_irq esp_reset, dma_enable;
  1323. unsigned long kernel_size;
  1324. void *fw_cfg;
  1325. DeviceState *dev;
  1326. /* init CPUs */
  1327. if (!cpu_model)
  1328. cpu_model = hwdef->default_cpu_model;
  1329. for(i = 0; i < smp_cpus; i++) {
  1330. cpu_devinit(cpu_model, i, hwdef->slavio_base, &cpu_irqs[i]);
  1331. }
  1332. for (i = smp_cpus; i < MAX_CPUS; i++)
  1333. cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
  1334. /* set up devices */
  1335. ram_init(0, RAM_size, hwdef->max_mem);
  1336. prom_init(hwdef->slavio_base, bios_name);
  1337. dev = sbi_init(hwdef->sbi_base, cpu_irqs);
  1338. for (i = 0; i < 32; i++) {
  1339. sbi_irq[i] = qdev_get_gpio_in(dev, i);
  1340. }
  1341. for (i = 0; i < MAX_CPUS; i++) {
  1342. sbi_cpu_irq[i] = qdev_get_gpio_in(dev, 32 + i);
  1343. }
  1344. for (i = 0; i < MAX_IOUNITS; i++)
  1345. if (hwdef->iounit_bases[i] != (target_phys_addr_t)-1)
  1346. iounits[i] = iommu_init(hwdef->iounit_bases[i],
  1347. hwdef->iounit_version,
  1348. sbi_irq[0]);
  1349. espdma = sparc32_dma_init(hwdef->espdma_base, sbi_irq[3],
  1350. iounits[0], &espdma_irq, 0);
  1351. /* should be lebuffer instead */
  1352. ledma = sparc32_dma_init(hwdef->ledma_base, sbi_irq[4],
  1353. iounits[0], &ledma_irq, 0);
  1354. if (graphic_depth != 8 && graphic_depth != 24) {
  1355. fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
  1356. exit (1);
  1357. }
  1358. tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
  1359. graphic_depth);
  1360. lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
  1361. nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0, 0x2000, 8);
  1362. slavio_timer_init_all(hwdef->counter_base, sbi_irq[10], sbi_cpu_irq, smp_cpus);
  1363. slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[12],
  1364. display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
  1365. // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
  1366. // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
  1367. escc_init(hwdef->serial_base, sbi_irq[12], sbi_irq[12],
  1368. serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
  1369. if (drive_get_max_bus(IF_SCSI) > 0) {
  1370. fprintf(stderr, "qemu: too many SCSI bus\n");
  1371. exit(1);
  1372. }
  1373. esp_init(hwdef->esp_base, 2,
  1374. espdma_memory_read, espdma_memory_write,
  1375. espdma, espdma_irq, &esp_reset, &dma_enable);
  1376. qdev_connect_gpio_out(espdma, 0, esp_reset);
  1377. qdev_connect_gpio_out(espdma, 1, dma_enable);
  1378. kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
  1379. RAM_size);
  1380. nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
  1381. boot_device, RAM_size, kernel_size, graphic_width,
  1382. graphic_height, graphic_depth, hwdef->nvram_machine_id,
  1383. "Sun4d");
  1384. fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
  1385. fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
  1386. fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
  1387. fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
  1388. fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
  1389. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
  1390. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
  1391. if (kernel_cmdline) {
  1392. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
  1393. pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
  1394. fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
  1395. (uint8_t*)strdup(kernel_cmdline),
  1396. strlen(kernel_cmdline) + 1);
  1397. } else {
  1398. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
  1399. }
  1400. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
  1401. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
  1402. fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
  1403. qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
  1404. }
  1405. /* SPARCserver 1000 hardware initialisation */
  1406. static void ss1000_init(ram_addr_t RAM_size,
  1407. const char *boot_device,
  1408. const char *kernel_filename, const char *kernel_cmdline,
  1409. const char *initrd_filename, const char *cpu_model)
  1410. {
  1411. sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, kernel_filename,
  1412. kernel_cmdline, initrd_filename, cpu_model);
  1413. }
  1414. /* SPARCcenter 2000 hardware initialisation */
  1415. static void ss2000_init(ram_addr_t RAM_size,
  1416. const char *boot_device,
  1417. const char *kernel_filename, const char *kernel_cmdline,
  1418. const char *initrd_filename, const char *cpu_model)
  1419. {
  1420. sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, kernel_filename,
  1421. kernel_cmdline, initrd_filename, cpu_model);
  1422. }
  1423. static QEMUMachine ss1000_machine = {
  1424. .name = "SS-1000",
  1425. .desc = "Sun4d platform, SPARCserver 1000",
  1426. .init = ss1000_init,
  1427. .use_scsi = 1,
  1428. .max_cpus = 8,
  1429. };
  1430. static QEMUMachine ss2000_machine = {
  1431. .name = "SS-2000",
  1432. .desc = "Sun4d platform, SPARCcenter 2000",
  1433. .init = ss2000_init,
  1434. .use_scsi = 1,
  1435. .max_cpus = 20,
  1436. };
  1437. static const struct sun4c_hwdef sun4c_hwdefs[] = {
  1438. /* SS-2 */
  1439. {
  1440. .iommu_base = 0xf8000000,
  1441. .tcx_base = 0xfe000000,
  1442. .slavio_base = 0xf6000000,
  1443. .intctl_base = 0xf5000000,
  1444. .counter_base = 0xf3000000,
  1445. .ms_kb_base = 0xf0000000,
  1446. .serial_base = 0xf1000000,
  1447. .nvram_base = 0xf2000000,
  1448. .fd_base = 0xf7200000,
  1449. .dma_base = 0xf8400000,
  1450. .esp_base = 0xf8800000,
  1451. .le_base = 0xf8c00000,
  1452. .aux1_base = 0xf7400003,
  1453. .nvram_machine_id = 0x55,
  1454. .machine_id = ss2_id,
  1455. .max_mem = 0x10000000,
  1456. .default_cpu_model = "Cypress CY7C601",
  1457. },
  1458. };
  1459. static DeviceState *sun4c_intctl_init(target_phys_addr_t addr,
  1460. qemu_irq *parent_irq)
  1461. {
  1462. DeviceState *dev;
  1463. SysBusDevice *s;
  1464. unsigned int i;
  1465. dev = qdev_create(NULL, "sun4c_intctl");
  1466. qdev_init_nofail(dev);
  1467. s = sysbus_from_qdev(dev);
  1468. for (i = 0; i < MAX_PILS; i++) {
  1469. sysbus_connect_irq(s, i, parent_irq[i]);
  1470. }
  1471. sysbus_mmio_map(s, 0, addr);
  1472. return dev;
  1473. }
  1474. static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
  1475. const char *boot_device,
  1476. const char *kernel_filename,
  1477. const char *kernel_cmdline,
  1478. const char *initrd_filename, const char *cpu_model)
  1479. {
  1480. void *iommu, *espdma, *ledma, *nvram;
  1481. qemu_irq *cpu_irqs, slavio_irq[8], espdma_irq, ledma_irq;
  1482. qemu_irq esp_reset, dma_enable;
  1483. qemu_irq fdc_tc;
  1484. unsigned long kernel_size;
  1485. DriveInfo *fd[MAX_FD];
  1486. void *fw_cfg;
  1487. DeviceState *dev;
  1488. unsigned int i;
  1489. /* init CPU */
  1490. if (!cpu_model)
  1491. cpu_model = hwdef->default_cpu_model;
  1492. cpu_devinit(cpu_model, 0, hwdef->slavio_base, &cpu_irqs);
  1493. /* set up devices */
  1494. ram_init(0, RAM_size, hwdef->max_mem);
  1495. prom_init(hwdef->slavio_base, bios_name);
  1496. dev = sun4c_intctl_init(hwdef->intctl_base, cpu_irqs);
  1497. for (i = 0; i < 8; i++) {
  1498. slavio_irq[i] = qdev_get_gpio_in(dev, i);
  1499. }
  1500. iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
  1501. slavio_irq[1]);
  1502. espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[2],
  1503. iommu, &espdma_irq, 0);
  1504. ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
  1505. slavio_irq[3], iommu, &ledma_irq, 1);
  1506. if (graphic_depth != 8 && graphic_depth != 24) {
  1507. fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
  1508. exit (1);
  1509. }
  1510. tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
  1511. graphic_depth);
  1512. lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
  1513. nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x800, 2);
  1514. slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[1],
  1515. display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
  1516. // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
  1517. // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
  1518. escc_init(hwdef->serial_base, slavio_irq[1],
  1519. slavio_irq[1], serial_hds[0], serial_hds[1],
  1520. ESCC_CLOCK, 1);
  1521. slavio_misc_init(0, hwdef->aux1_base, 0, slavio_irq[1], fdc_tc);
  1522. if (hwdef->fd_base != (target_phys_addr_t)-1) {
  1523. /* there is zero or one floppy drive */
  1524. memset(fd, 0, sizeof(fd));
  1525. fd[0] = drive_get(IF_FLOPPY, 0, 0);
  1526. sun4m_fdctrl_init(slavio_irq[1], hwdef->fd_base, fd,
  1527. &fdc_tc);
  1528. }
  1529. if (drive_get_max_bus(IF_SCSI) > 0) {
  1530. fprintf(stderr, "qemu: too many SCSI bus\n");
  1531. exit(1);
  1532. }
  1533. esp_init(hwdef->esp_base, 2,
  1534. espdma_memory_read, espdma_memory_write,
  1535. espdma, espdma_irq, &esp_reset, &dma_enable);
  1536. qdev_connect_gpio_out(espdma, 0, esp_reset);
  1537. qdev_connect_gpio_out(espdma, 1, dma_enable);
  1538. kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
  1539. RAM_size);
  1540. nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
  1541. boot_device, RAM_size, kernel_size, graphic_width,
  1542. graphic_height, graphic_depth, hwdef->nvram_machine_id,
  1543. "Sun4c");
  1544. fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
  1545. fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
  1546. fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
  1547. fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
  1548. fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
  1549. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
  1550. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
  1551. if (kernel_cmdline) {
  1552. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
  1553. pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
  1554. fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
  1555. (uint8_t*)strdup(kernel_cmdline),
  1556. strlen(kernel_cmdline) + 1);
  1557. } else {
  1558. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
  1559. }
  1560. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
  1561. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
  1562. fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
  1563. qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
  1564. }
  1565. /* SPARCstation 2 hardware initialisation */
  1566. static void ss2_init(ram_addr_t RAM_size,
  1567. const char *boot_device,
  1568. const char *kernel_filename, const char *kernel_cmdline,
  1569. const char *initrd_filename, const char *cpu_model)
  1570. {
  1571. sun4c_hw_init(&sun4c_hwdefs[0], RAM_size, boot_device, kernel_filename,
  1572. kernel_cmdline, initrd_filename, cpu_model);
  1573. }
  1574. static QEMUMachine ss2_machine = {
  1575. .name = "SS-2",
  1576. .desc = "Sun4c platform, SPARCstation 2",
  1577. .init = ss2_init,
  1578. .use_scsi = 1,
  1579. };
  1580. static void ss2_machine_init(void)
  1581. {
  1582. qemu_register_machine(&ss5_machine);
  1583. qemu_register_machine(&ss10_machine);
  1584. qemu_register_machine(&ss600mp_machine);
  1585. qemu_register_machine(&ss20_machine);
  1586. qemu_register_machine(&voyager_machine);
  1587. qemu_register_machine(&ss_lx_machine);
  1588. qemu_register_machine(&ss4_machine);
  1589. qemu_register_machine(&scls_machine);
  1590. qemu_register_machine(&sbook_machine);
  1591. qemu_register_machine(&ss1000_machine);
  1592. qemu_register_machine(&ss2000_machine);
  1593. qemu_register_machine(&ss2_machine);
  1594. }
  1595. machine_init(ss2_machine_init);