sun4m.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842
  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. uint64_t max_mem;
  96. const char * const default_cpu_model;
  97. uint32_t ecc_version;
  98. uint32_t iommu_version;
  99. uint16_t machine_id;
  100. uint8_t nvram_machine_id;
  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. uint64_t max_mem;
  112. const char * const default_cpu_model;
  113. uint32_t iounit_version;
  114. uint16_t machine_id;
  115. uint8_t nvram_machine_id;
  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. uint64_t max_mem;
  124. const char * const default_cpu_model;
  125. uint32_t iommu_version;
  126. uint16_t machine_id;
  127. uint8_t nvram_machine_id;
  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 sun4m_pic_info(Monitor *mon)
  195. {
  196. if (slavio_intctl)
  197. slavio_pic_info(mon, slavio_intctl);
  198. }
  199. void sun4m_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. typedef struct IDRegState {
  521. SysBusDevice busdev;
  522. MemoryRegion mem;
  523. } IDRegState;
  524. static int idreg_init1(SysBusDevice *dev)
  525. {
  526. IDRegState *s = FROM_SYSBUS(IDRegState, dev);
  527. memory_region_init_ram(&s->mem, NULL, "sun4m.idreg", sizeof(idreg_data));
  528. memory_region_set_readonly(&s->mem, true);
  529. sysbus_init_mmio_region(dev, &s->mem);
  530. return 0;
  531. }
  532. static SysBusDeviceInfo idreg_info = {
  533. .init = idreg_init1,
  534. .qdev.name = "macio_idreg",
  535. .qdev.size = sizeof(IDRegState),
  536. };
  537. static void idreg_register_devices(void)
  538. {
  539. sysbus_register_withprop(&idreg_info);
  540. }
  541. device_init(idreg_register_devices);
  542. typedef struct AFXState {
  543. SysBusDevice busdev;
  544. MemoryRegion mem;
  545. } AFXState;
  546. /* SS-5 TCX AFX register */
  547. static void afx_init(target_phys_addr_t addr)
  548. {
  549. DeviceState *dev;
  550. SysBusDevice *s;
  551. dev = qdev_create(NULL, "tcx_afx");
  552. qdev_init_nofail(dev);
  553. s = sysbus_from_qdev(dev);
  554. sysbus_mmio_map(s, 0, addr);
  555. }
  556. static int afx_init1(SysBusDevice *dev)
  557. {
  558. AFXState *s = FROM_SYSBUS(AFXState, dev);
  559. memory_region_init_ram(&s->mem, NULL, "sun4m.afx", 4);
  560. sysbus_init_mmio_region(dev, &s->mem);
  561. return 0;
  562. }
  563. static SysBusDeviceInfo afx_info = {
  564. .init = afx_init1,
  565. .qdev.name = "tcx_afx",
  566. .qdev.size = sizeof(AFXState),
  567. };
  568. static void afx_register_devices(void)
  569. {
  570. sysbus_register_withprop(&afx_info);
  571. }
  572. device_init(afx_register_devices);
  573. typedef struct PROMState {
  574. SysBusDevice busdev;
  575. MemoryRegion prom;
  576. } PROMState;
  577. /* Boot PROM (OpenBIOS) */
  578. static uint64_t translate_prom_address(void *opaque, uint64_t addr)
  579. {
  580. target_phys_addr_t *base_addr = (target_phys_addr_t *)opaque;
  581. return addr + *base_addr - PROM_VADDR;
  582. }
  583. static void prom_init(target_phys_addr_t addr, const char *bios_name)
  584. {
  585. DeviceState *dev;
  586. SysBusDevice *s;
  587. char *filename;
  588. int ret;
  589. dev = qdev_create(NULL, "openprom");
  590. qdev_init_nofail(dev);
  591. s = sysbus_from_qdev(dev);
  592. sysbus_mmio_map(s, 0, addr);
  593. /* load boot prom */
  594. if (bios_name == NULL) {
  595. bios_name = PROM_FILENAME;
  596. }
  597. filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
  598. if (filename) {
  599. ret = load_elf(filename, translate_prom_address, &addr, NULL,
  600. NULL, NULL, 1, ELF_MACHINE, 0);
  601. if (ret < 0 || ret > PROM_SIZE_MAX) {
  602. ret = load_image_targphys(filename, addr, PROM_SIZE_MAX);
  603. }
  604. g_free(filename);
  605. } else {
  606. ret = -1;
  607. }
  608. if (ret < 0 || ret > PROM_SIZE_MAX) {
  609. fprintf(stderr, "qemu: could not load prom '%s'\n", bios_name);
  610. exit(1);
  611. }
  612. }
  613. static int prom_init1(SysBusDevice *dev)
  614. {
  615. PROMState *s = FROM_SYSBUS(PROMState, dev);
  616. memory_region_init_ram(&s->prom, NULL, "sun4m.prom", PROM_SIZE_MAX);
  617. memory_region_set_readonly(&s->prom, true);
  618. sysbus_init_mmio_region(dev, &s->prom);
  619. return 0;
  620. }
  621. static SysBusDeviceInfo prom_info = {
  622. .init = prom_init1,
  623. .qdev.name = "openprom",
  624. .qdev.size = sizeof(PROMState),
  625. .qdev.props = (Property[]) {
  626. {/* end of property list */}
  627. }
  628. };
  629. static void prom_register_devices(void)
  630. {
  631. sysbus_register_withprop(&prom_info);
  632. }
  633. device_init(prom_register_devices);
  634. typedef struct RamDevice
  635. {
  636. SysBusDevice busdev;
  637. MemoryRegion ram;
  638. uint64_t size;
  639. } RamDevice;
  640. /* System RAM */
  641. static int ram_init1(SysBusDevice *dev)
  642. {
  643. RamDevice *d = FROM_SYSBUS(RamDevice, dev);
  644. memory_region_init_ram(&d->ram, NULL, "sun4m.ram", d->size);
  645. sysbus_init_mmio_region(dev, &d->ram);
  646. return 0;
  647. }
  648. static void ram_init(target_phys_addr_t addr, ram_addr_t RAM_size,
  649. uint64_t max_mem)
  650. {
  651. DeviceState *dev;
  652. SysBusDevice *s;
  653. RamDevice *d;
  654. /* allocate RAM */
  655. if ((uint64_t)RAM_size > max_mem) {
  656. fprintf(stderr,
  657. "qemu: Too much memory for this machine: %d, maximum %d\n",
  658. (unsigned int)(RAM_size / (1024 * 1024)),
  659. (unsigned int)(max_mem / (1024 * 1024)));
  660. exit(1);
  661. }
  662. dev = qdev_create(NULL, "memory");
  663. s = sysbus_from_qdev(dev);
  664. d = FROM_SYSBUS(RamDevice, s);
  665. d->size = RAM_size;
  666. qdev_init_nofail(dev);
  667. sysbus_mmio_map(s, 0, addr);
  668. }
  669. static SysBusDeviceInfo ram_info = {
  670. .init = ram_init1,
  671. .qdev.name = "memory",
  672. .qdev.size = sizeof(RamDevice),
  673. .qdev.props = (Property[]) {
  674. DEFINE_PROP_UINT64("size", RamDevice, size, 0),
  675. DEFINE_PROP_END_OF_LIST(),
  676. }
  677. };
  678. static void ram_register_devices(void)
  679. {
  680. sysbus_register_withprop(&ram_info);
  681. }
  682. device_init(ram_register_devices);
  683. static void cpu_devinit(const char *cpu_model, unsigned int id,
  684. uint64_t prom_addr, qemu_irq **cpu_irqs)
  685. {
  686. CPUState *env;
  687. env = cpu_init(cpu_model);
  688. if (!env) {
  689. fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
  690. exit(1);
  691. }
  692. cpu_sparc_set_id(env, id);
  693. if (id == 0) {
  694. qemu_register_reset(main_cpu_reset, env);
  695. } else {
  696. qemu_register_reset(secondary_cpu_reset, env);
  697. env->halted = 1;
  698. }
  699. *cpu_irqs = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
  700. env->prom_addr = prom_addr;
  701. }
  702. static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
  703. const char *boot_device,
  704. const char *kernel_filename,
  705. const char *kernel_cmdline,
  706. const char *initrd_filename, const char *cpu_model)
  707. {
  708. unsigned int i;
  709. void *iommu, *espdma, *ledma, *nvram;
  710. qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS],
  711. espdma_irq, ledma_irq;
  712. qemu_irq esp_reset, dma_enable;
  713. qemu_irq fdc_tc;
  714. qemu_irq *cpu_halt;
  715. unsigned long kernel_size;
  716. DriveInfo *fd[MAX_FD];
  717. void *fw_cfg;
  718. unsigned int num_vsimms;
  719. /* init CPUs */
  720. if (!cpu_model)
  721. cpu_model = hwdef->default_cpu_model;
  722. for(i = 0; i < smp_cpus; i++) {
  723. cpu_devinit(cpu_model, i, hwdef->slavio_base, &cpu_irqs[i]);
  724. }
  725. for (i = smp_cpus; i < MAX_CPUS; i++)
  726. cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
  727. /* set up devices */
  728. ram_init(0, RAM_size, hwdef->max_mem);
  729. /* models without ECC don't trap when missing ram is accessed */
  730. if (!hwdef->ecc_base) {
  731. empty_slot_init(RAM_size, hwdef->max_mem - RAM_size);
  732. }
  733. prom_init(hwdef->slavio_base, bios_name);
  734. slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
  735. hwdef->intctl_base + 0x10000ULL,
  736. cpu_irqs);
  737. for (i = 0; i < 32; i++) {
  738. slavio_irq[i] = qdev_get_gpio_in(slavio_intctl, i);
  739. }
  740. for (i = 0; i < MAX_CPUS; i++) {
  741. slavio_cpu_irq[i] = qdev_get_gpio_in(slavio_intctl, 32 + i);
  742. }
  743. if (hwdef->idreg_base) {
  744. idreg_init(hwdef->idreg_base);
  745. }
  746. if (hwdef->afx_base) {
  747. afx_init(hwdef->afx_base);
  748. }
  749. iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
  750. slavio_irq[30]);
  751. if (hwdef->iommu_pad_base) {
  752. /* On the real hardware (SS-5, LX) the MMU is not padded, but aliased.
  753. Software shouldn't use aliased addresses, neither should it crash
  754. when does. Using empty_slot instead of aliasing can help with
  755. debugging such accesses */
  756. empty_slot_init(hwdef->iommu_pad_base,hwdef->iommu_pad_len);
  757. }
  758. espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[18],
  759. iommu, &espdma_irq, 0);
  760. ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
  761. slavio_irq[16], iommu, &ledma_irq, 1);
  762. if (graphic_depth != 8 && graphic_depth != 24) {
  763. fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
  764. exit (1);
  765. }
  766. num_vsimms = 0;
  767. if (num_vsimms == 0) {
  768. tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
  769. graphic_depth);
  770. }
  771. for (i = num_vsimms; i < MAX_VSIMMS; i++) {
  772. /* vsimm registers probed by OBP */
  773. if (hwdef->vsimm[i].reg_base) {
  774. empty_slot_init(hwdef->vsimm[i].reg_base, 0x2000);
  775. }
  776. }
  777. if (hwdef->sx_base) {
  778. empty_slot_init(hwdef->sx_base, 0x2000);
  779. }
  780. lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
  781. nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x2000, 8);
  782. slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
  783. slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[14],
  784. display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
  785. // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
  786. // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
  787. escc_init(hwdef->serial_base, slavio_irq[15], slavio_irq[15],
  788. serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
  789. cpu_halt = qemu_allocate_irqs(cpu_halt_signal, NULL, 1);
  790. slavio_misc_init(hwdef->slavio_base, hwdef->aux1_base, hwdef->aux2_base,
  791. slavio_irq[30], fdc_tc);
  792. if (hwdef->apc_base) {
  793. apc_init(hwdef->apc_base, cpu_halt[0]);
  794. }
  795. if (hwdef->fd_base) {
  796. /* there is zero or one floppy drive */
  797. memset(fd, 0, sizeof(fd));
  798. fd[0] = drive_get(IF_FLOPPY, 0, 0);
  799. sun4m_fdctrl_init(slavio_irq[22], hwdef->fd_base, fd,
  800. &fdc_tc);
  801. }
  802. if (drive_get_max_bus(IF_SCSI) > 0) {
  803. fprintf(stderr, "qemu: too many SCSI bus\n");
  804. exit(1);
  805. }
  806. esp_init(hwdef->esp_base, 2,
  807. espdma_memory_read, espdma_memory_write,
  808. espdma, espdma_irq, &esp_reset, &dma_enable);
  809. qdev_connect_gpio_out(espdma, 0, esp_reset);
  810. qdev_connect_gpio_out(espdma, 1, dma_enable);
  811. if (hwdef->cs_base) {
  812. sysbus_create_simple("SUNW,CS4231", hwdef->cs_base,
  813. slavio_irq[5]);
  814. }
  815. if (hwdef->dbri_base) {
  816. /* ISDN chip with attached CS4215 audio codec */
  817. /* prom space */
  818. empty_slot_init(hwdef->dbri_base+0x1000, 0x30);
  819. /* reg space */
  820. empty_slot_init(hwdef->dbri_base+0x10000, 0x100);
  821. }
  822. if (hwdef->bpp_base) {
  823. /* parallel port */
  824. empty_slot_init(hwdef->bpp_base, 0x20);
  825. }
  826. kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
  827. RAM_size);
  828. nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
  829. boot_device, RAM_size, kernel_size, graphic_width,
  830. graphic_height, graphic_depth, hwdef->nvram_machine_id,
  831. "Sun4m");
  832. if (hwdef->ecc_base)
  833. ecc_init(hwdef->ecc_base, slavio_irq[28],
  834. hwdef->ecc_version);
  835. fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
  836. fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
  837. fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
  838. fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
  839. fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
  840. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
  841. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
  842. if (kernel_cmdline) {
  843. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
  844. pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
  845. fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
  846. (uint8_t*)strdup(kernel_cmdline),
  847. strlen(kernel_cmdline) + 1);
  848. fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
  849. strlen(kernel_cmdline) + 1);
  850. } else {
  851. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
  852. fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
  853. }
  854. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
  855. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
  856. fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
  857. qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
  858. }
  859. enum {
  860. ss2_id = 0,
  861. ss5_id = 32,
  862. vger_id,
  863. lx_id,
  864. ss4_id,
  865. scls_id,
  866. sbook_id,
  867. ss10_id = 64,
  868. ss20_id,
  869. ss600mp_id,
  870. ss1000_id = 96,
  871. ss2000_id,
  872. };
  873. static const struct sun4m_hwdef sun4m_hwdefs[] = {
  874. /* SS-5 */
  875. {
  876. .iommu_base = 0x10000000,
  877. .iommu_pad_base = 0x10004000,
  878. .iommu_pad_len = 0x0fffb000,
  879. .tcx_base = 0x50000000,
  880. .cs_base = 0x6c000000,
  881. .slavio_base = 0x70000000,
  882. .ms_kb_base = 0x71000000,
  883. .serial_base = 0x71100000,
  884. .nvram_base = 0x71200000,
  885. .fd_base = 0x71400000,
  886. .counter_base = 0x71d00000,
  887. .intctl_base = 0x71e00000,
  888. .idreg_base = 0x78000000,
  889. .dma_base = 0x78400000,
  890. .esp_base = 0x78800000,
  891. .le_base = 0x78c00000,
  892. .apc_base = 0x6a000000,
  893. .afx_base = 0x6e000000,
  894. .aux1_base = 0x71900000,
  895. .aux2_base = 0x71910000,
  896. .nvram_machine_id = 0x80,
  897. .machine_id = ss5_id,
  898. .iommu_version = 0x05000000,
  899. .max_mem = 0x10000000,
  900. .default_cpu_model = "Fujitsu MB86904",
  901. },
  902. /* SS-10 */
  903. {
  904. .iommu_base = 0xfe0000000ULL,
  905. .tcx_base = 0xe20000000ULL,
  906. .slavio_base = 0xff0000000ULL,
  907. .ms_kb_base = 0xff1000000ULL,
  908. .serial_base = 0xff1100000ULL,
  909. .nvram_base = 0xff1200000ULL,
  910. .fd_base = 0xff1700000ULL,
  911. .counter_base = 0xff1300000ULL,
  912. .intctl_base = 0xff1400000ULL,
  913. .idreg_base = 0xef0000000ULL,
  914. .dma_base = 0xef0400000ULL,
  915. .esp_base = 0xef0800000ULL,
  916. .le_base = 0xef0c00000ULL,
  917. .apc_base = 0xefa000000ULL, // XXX should not exist
  918. .aux1_base = 0xff1800000ULL,
  919. .aux2_base = 0xff1a01000ULL,
  920. .ecc_base = 0xf00000000ULL,
  921. .ecc_version = 0x10000000, // version 0, implementation 1
  922. .nvram_machine_id = 0x72,
  923. .machine_id = ss10_id,
  924. .iommu_version = 0x03000000,
  925. .max_mem = 0xf00000000ULL,
  926. .default_cpu_model = "TI SuperSparc II",
  927. },
  928. /* SS-600MP */
  929. {
  930. .iommu_base = 0xfe0000000ULL,
  931. .tcx_base = 0xe20000000ULL,
  932. .slavio_base = 0xff0000000ULL,
  933. .ms_kb_base = 0xff1000000ULL,
  934. .serial_base = 0xff1100000ULL,
  935. .nvram_base = 0xff1200000ULL,
  936. .counter_base = 0xff1300000ULL,
  937. .intctl_base = 0xff1400000ULL,
  938. .dma_base = 0xef0081000ULL,
  939. .esp_base = 0xef0080000ULL,
  940. .le_base = 0xef0060000ULL,
  941. .apc_base = 0xefa000000ULL, // XXX should not exist
  942. .aux1_base = 0xff1800000ULL,
  943. .aux2_base = 0xff1a01000ULL, // XXX should not exist
  944. .ecc_base = 0xf00000000ULL,
  945. .ecc_version = 0x00000000, // version 0, implementation 0
  946. .nvram_machine_id = 0x71,
  947. .machine_id = ss600mp_id,
  948. .iommu_version = 0x01000000,
  949. .max_mem = 0xf00000000ULL,
  950. .default_cpu_model = "TI SuperSparc II",
  951. },
  952. /* SS-20 */
  953. {
  954. .iommu_base = 0xfe0000000ULL,
  955. .tcx_base = 0xe20000000ULL,
  956. .slavio_base = 0xff0000000ULL,
  957. .ms_kb_base = 0xff1000000ULL,
  958. .serial_base = 0xff1100000ULL,
  959. .nvram_base = 0xff1200000ULL,
  960. .fd_base = 0xff1700000ULL,
  961. .counter_base = 0xff1300000ULL,
  962. .intctl_base = 0xff1400000ULL,
  963. .idreg_base = 0xef0000000ULL,
  964. .dma_base = 0xef0400000ULL,
  965. .esp_base = 0xef0800000ULL,
  966. .le_base = 0xef0c00000ULL,
  967. .bpp_base = 0xef4800000ULL,
  968. .apc_base = 0xefa000000ULL, // XXX should not exist
  969. .aux1_base = 0xff1800000ULL,
  970. .aux2_base = 0xff1a01000ULL,
  971. .dbri_base = 0xee0000000ULL,
  972. .sx_base = 0xf80000000ULL,
  973. .vsimm = {
  974. {
  975. .reg_base = 0x9c000000ULL,
  976. .vram_base = 0xfc000000ULL
  977. }, {
  978. .reg_base = 0x90000000ULL,
  979. .vram_base = 0xf0000000ULL
  980. }, {
  981. .reg_base = 0x94000000ULL
  982. }, {
  983. .reg_base = 0x98000000ULL
  984. }
  985. },
  986. .ecc_base = 0xf00000000ULL,
  987. .ecc_version = 0x20000000, // version 0, implementation 2
  988. .nvram_machine_id = 0x72,
  989. .machine_id = ss20_id,
  990. .iommu_version = 0x13000000,
  991. .max_mem = 0xf00000000ULL,
  992. .default_cpu_model = "TI SuperSparc II",
  993. },
  994. /* Voyager */
  995. {
  996. .iommu_base = 0x10000000,
  997. .tcx_base = 0x50000000,
  998. .slavio_base = 0x70000000,
  999. .ms_kb_base = 0x71000000,
  1000. .serial_base = 0x71100000,
  1001. .nvram_base = 0x71200000,
  1002. .fd_base = 0x71400000,
  1003. .counter_base = 0x71d00000,
  1004. .intctl_base = 0x71e00000,
  1005. .idreg_base = 0x78000000,
  1006. .dma_base = 0x78400000,
  1007. .esp_base = 0x78800000,
  1008. .le_base = 0x78c00000,
  1009. .apc_base = 0x71300000, // pmc
  1010. .aux1_base = 0x71900000,
  1011. .aux2_base = 0x71910000,
  1012. .nvram_machine_id = 0x80,
  1013. .machine_id = vger_id,
  1014. .iommu_version = 0x05000000,
  1015. .max_mem = 0x10000000,
  1016. .default_cpu_model = "Fujitsu MB86904",
  1017. },
  1018. /* LX */
  1019. {
  1020. .iommu_base = 0x10000000,
  1021. .iommu_pad_base = 0x10004000,
  1022. .iommu_pad_len = 0x0fffb000,
  1023. .tcx_base = 0x50000000,
  1024. .slavio_base = 0x70000000,
  1025. .ms_kb_base = 0x71000000,
  1026. .serial_base = 0x71100000,
  1027. .nvram_base = 0x71200000,
  1028. .fd_base = 0x71400000,
  1029. .counter_base = 0x71d00000,
  1030. .intctl_base = 0x71e00000,
  1031. .idreg_base = 0x78000000,
  1032. .dma_base = 0x78400000,
  1033. .esp_base = 0x78800000,
  1034. .le_base = 0x78c00000,
  1035. .aux1_base = 0x71900000,
  1036. .aux2_base = 0x71910000,
  1037. .nvram_machine_id = 0x80,
  1038. .machine_id = lx_id,
  1039. .iommu_version = 0x04000000,
  1040. .max_mem = 0x10000000,
  1041. .default_cpu_model = "TI MicroSparc I",
  1042. },
  1043. /* SS-4 */
  1044. {
  1045. .iommu_base = 0x10000000,
  1046. .tcx_base = 0x50000000,
  1047. .cs_base = 0x6c000000,
  1048. .slavio_base = 0x70000000,
  1049. .ms_kb_base = 0x71000000,
  1050. .serial_base = 0x71100000,
  1051. .nvram_base = 0x71200000,
  1052. .fd_base = 0x71400000,
  1053. .counter_base = 0x71d00000,
  1054. .intctl_base = 0x71e00000,
  1055. .idreg_base = 0x78000000,
  1056. .dma_base = 0x78400000,
  1057. .esp_base = 0x78800000,
  1058. .le_base = 0x78c00000,
  1059. .apc_base = 0x6a000000,
  1060. .aux1_base = 0x71900000,
  1061. .aux2_base = 0x71910000,
  1062. .nvram_machine_id = 0x80,
  1063. .machine_id = ss4_id,
  1064. .iommu_version = 0x05000000,
  1065. .max_mem = 0x10000000,
  1066. .default_cpu_model = "Fujitsu MB86904",
  1067. },
  1068. /* SPARCClassic */
  1069. {
  1070. .iommu_base = 0x10000000,
  1071. .tcx_base = 0x50000000,
  1072. .slavio_base = 0x70000000,
  1073. .ms_kb_base = 0x71000000,
  1074. .serial_base = 0x71100000,
  1075. .nvram_base = 0x71200000,
  1076. .fd_base = 0x71400000,
  1077. .counter_base = 0x71d00000,
  1078. .intctl_base = 0x71e00000,
  1079. .idreg_base = 0x78000000,
  1080. .dma_base = 0x78400000,
  1081. .esp_base = 0x78800000,
  1082. .le_base = 0x78c00000,
  1083. .apc_base = 0x6a000000,
  1084. .aux1_base = 0x71900000,
  1085. .aux2_base = 0x71910000,
  1086. .nvram_machine_id = 0x80,
  1087. .machine_id = scls_id,
  1088. .iommu_version = 0x05000000,
  1089. .max_mem = 0x10000000,
  1090. .default_cpu_model = "TI MicroSparc I",
  1091. },
  1092. /* SPARCbook */
  1093. {
  1094. .iommu_base = 0x10000000,
  1095. .tcx_base = 0x50000000, // XXX
  1096. .slavio_base = 0x70000000,
  1097. .ms_kb_base = 0x71000000,
  1098. .serial_base = 0x71100000,
  1099. .nvram_base = 0x71200000,
  1100. .fd_base = 0x71400000,
  1101. .counter_base = 0x71d00000,
  1102. .intctl_base = 0x71e00000,
  1103. .idreg_base = 0x78000000,
  1104. .dma_base = 0x78400000,
  1105. .esp_base = 0x78800000,
  1106. .le_base = 0x78c00000,
  1107. .apc_base = 0x6a000000,
  1108. .aux1_base = 0x71900000,
  1109. .aux2_base = 0x71910000,
  1110. .nvram_machine_id = 0x80,
  1111. .machine_id = sbook_id,
  1112. .iommu_version = 0x05000000,
  1113. .max_mem = 0x10000000,
  1114. .default_cpu_model = "TI MicroSparc I",
  1115. },
  1116. };
  1117. /* SPARCstation 5 hardware initialisation */
  1118. static void ss5_init(ram_addr_t RAM_size,
  1119. const char *boot_device,
  1120. const char *kernel_filename, const char *kernel_cmdline,
  1121. const char *initrd_filename, const char *cpu_model)
  1122. {
  1123. sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, kernel_filename,
  1124. kernel_cmdline, initrd_filename, cpu_model);
  1125. }
  1126. /* SPARCstation 10 hardware initialisation */
  1127. static void ss10_init(ram_addr_t RAM_size,
  1128. const char *boot_device,
  1129. const char *kernel_filename, const char *kernel_cmdline,
  1130. const char *initrd_filename, const char *cpu_model)
  1131. {
  1132. sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, kernel_filename,
  1133. kernel_cmdline, initrd_filename, cpu_model);
  1134. }
  1135. /* SPARCserver 600MP hardware initialisation */
  1136. static void ss600mp_init(ram_addr_t RAM_size,
  1137. const char *boot_device,
  1138. const char *kernel_filename,
  1139. const char *kernel_cmdline,
  1140. const char *initrd_filename, const char *cpu_model)
  1141. {
  1142. sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, kernel_filename,
  1143. kernel_cmdline, initrd_filename, cpu_model);
  1144. }
  1145. /* SPARCstation 20 hardware initialisation */
  1146. static void ss20_init(ram_addr_t RAM_size,
  1147. const char *boot_device,
  1148. const char *kernel_filename, const char *kernel_cmdline,
  1149. const char *initrd_filename, const char *cpu_model)
  1150. {
  1151. sun4m_hw_init(&sun4m_hwdefs[3], RAM_size, boot_device, kernel_filename,
  1152. kernel_cmdline, initrd_filename, cpu_model);
  1153. }
  1154. /* SPARCstation Voyager hardware initialisation */
  1155. static void vger_init(ram_addr_t RAM_size,
  1156. const char *boot_device,
  1157. const char *kernel_filename, const char *kernel_cmdline,
  1158. const char *initrd_filename, const char *cpu_model)
  1159. {
  1160. sun4m_hw_init(&sun4m_hwdefs[4], RAM_size, boot_device, kernel_filename,
  1161. kernel_cmdline, initrd_filename, cpu_model);
  1162. }
  1163. /* SPARCstation LX hardware initialisation */
  1164. static void ss_lx_init(ram_addr_t RAM_size,
  1165. const char *boot_device,
  1166. const char *kernel_filename, const char *kernel_cmdline,
  1167. const char *initrd_filename, const char *cpu_model)
  1168. {
  1169. sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, kernel_filename,
  1170. kernel_cmdline, initrd_filename, cpu_model);
  1171. }
  1172. /* SPARCstation 4 hardware initialisation */
  1173. static void ss4_init(ram_addr_t RAM_size,
  1174. const char *boot_device,
  1175. const char *kernel_filename, const char *kernel_cmdline,
  1176. const char *initrd_filename, const char *cpu_model)
  1177. {
  1178. sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, kernel_filename,
  1179. kernel_cmdline, initrd_filename, cpu_model);
  1180. }
  1181. /* SPARCClassic hardware initialisation */
  1182. static void scls_init(ram_addr_t RAM_size,
  1183. const char *boot_device,
  1184. const char *kernel_filename, const char *kernel_cmdline,
  1185. const char *initrd_filename, const char *cpu_model)
  1186. {
  1187. sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, kernel_filename,
  1188. kernel_cmdline, initrd_filename, cpu_model);
  1189. }
  1190. /* SPARCbook hardware initialisation */
  1191. static void sbook_init(ram_addr_t RAM_size,
  1192. const char *boot_device,
  1193. const char *kernel_filename, const char *kernel_cmdline,
  1194. const char *initrd_filename, const char *cpu_model)
  1195. {
  1196. sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, kernel_filename,
  1197. kernel_cmdline, initrd_filename, cpu_model);
  1198. }
  1199. static QEMUMachine ss5_machine = {
  1200. .name = "SS-5",
  1201. .desc = "Sun4m platform, SPARCstation 5",
  1202. .init = ss5_init,
  1203. .use_scsi = 1,
  1204. .is_default = 1,
  1205. };
  1206. static QEMUMachine ss10_machine = {
  1207. .name = "SS-10",
  1208. .desc = "Sun4m platform, SPARCstation 10",
  1209. .init = ss10_init,
  1210. .use_scsi = 1,
  1211. .max_cpus = 4,
  1212. };
  1213. static QEMUMachine ss600mp_machine = {
  1214. .name = "SS-600MP",
  1215. .desc = "Sun4m platform, SPARCserver 600MP",
  1216. .init = ss600mp_init,
  1217. .use_scsi = 1,
  1218. .max_cpus = 4,
  1219. };
  1220. static QEMUMachine ss20_machine = {
  1221. .name = "SS-20",
  1222. .desc = "Sun4m platform, SPARCstation 20",
  1223. .init = ss20_init,
  1224. .use_scsi = 1,
  1225. .max_cpus = 4,
  1226. };
  1227. static QEMUMachine voyager_machine = {
  1228. .name = "Voyager",
  1229. .desc = "Sun4m platform, SPARCstation Voyager",
  1230. .init = vger_init,
  1231. .use_scsi = 1,
  1232. };
  1233. static QEMUMachine ss_lx_machine = {
  1234. .name = "LX",
  1235. .desc = "Sun4m platform, SPARCstation LX",
  1236. .init = ss_lx_init,
  1237. .use_scsi = 1,
  1238. };
  1239. static QEMUMachine ss4_machine = {
  1240. .name = "SS-4",
  1241. .desc = "Sun4m platform, SPARCstation 4",
  1242. .init = ss4_init,
  1243. .use_scsi = 1,
  1244. };
  1245. static QEMUMachine scls_machine = {
  1246. .name = "SPARCClassic",
  1247. .desc = "Sun4m platform, SPARCClassic",
  1248. .init = scls_init,
  1249. .use_scsi = 1,
  1250. };
  1251. static QEMUMachine sbook_machine = {
  1252. .name = "SPARCbook",
  1253. .desc = "Sun4m platform, SPARCbook",
  1254. .init = sbook_init,
  1255. .use_scsi = 1,
  1256. };
  1257. static const struct sun4d_hwdef sun4d_hwdefs[] = {
  1258. /* SS-1000 */
  1259. {
  1260. .iounit_bases = {
  1261. 0xfe0200000ULL,
  1262. 0xfe1200000ULL,
  1263. 0xfe2200000ULL,
  1264. 0xfe3200000ULL,
  1265. -1,
  1266. },
  1267. .tcx_base = 0x820000000ULL,
  1268. .slavio_base = 0xf00000000ULL,
  1269. .ms_kb_base = 0xf00240000ULL,
  1270. .serial_base = 0xf00200000ULL,
  1271. .nvram_base = 0xf00280000ULL,
  1272. .counter_base = 0xf00300000ULL,
  1273. .espdma_base = 0x800081000ULL,
  1274. .esp_base = 0x800080000ULL,
  1275. .ledma_base = 0x800040000ULL,
  1276. .le_base = 0x800060000ULL,
  1277. .sbi_base = 0xf02800000ULL,
  1278. .nvram_machine_id = 0x80,
  1279. .machine_id = ss1000_id,
  1280. .iounit_version = 0x03000000,
  1281. .max_mem = 0xf00000000ULL,
  1282. .default_cpu_model = "TI SuperSparc II",
  1283. },
  1284. /* SS-2000 */
  1285. {
  1286. .iounit_bases = {
  1287. 0xfe0200000ULL,
  1288. 0xfe1200000ULL,
  1289. 0xfe2200000ULL,
  1290. 0xfe3200000ULL,
  1291. 0xfe4200000ULL,
  1292. },
  1293. .tcx_base = 0x820000000ULL,
  1294. .slavio_base = 0xf00000000ULL,
  1295. .ms_kb_base = 0xf00240000ULL,
  1296. .serial_base = 0xf00200000ULL,
  1297. .nvram_base = 0xf00280000ULL,
  1298. .counter_base = 0xf00300000ULL,
  1299. .espdma_base = 0x800081000ULL,
  1300. .esp_base = 0x800080000ULL,
  1301. .ledma_base = 0x800040000ULL,
  1302. .le_base = 0x800060000ULL,
  1303. .sbi_base = 0xf02800000ULL,
  1304. .nvram_machine_id = 0x80,
  1305. .machine_id = ss2000_id,
  1306. .iounit_version = 0x03000000,
  1307. .max_mem = 0xf00000000ULL,
  1308. .default_cpu_model = "TI SuperSparc II",
  1309. },
  1310. };
  1311. static DeviceState *sbi_init(target_phys_addr_t addr, qemu_irq **parent_irq)
  1312. {
  1313. DeviceState *dev;
  1314. SysBusDevice *s;
  1315. unsigned int i;
  1316. dev = qdev_create(NULL, "sbi");
  1317. qdev_init_nofail(dev);
  1318. s = sysbus_from_qdev(dev);
  1319. for (i = 0; i < MAX_CPUS; i++) {
  1320. sysbus_connect_irq(s, i, *parent_irq[i]);
  1321. }
  1322. sysbus_mmio_map(s, 0, addr);
  1323. return dev;
  1324. }
  1325. static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
  1326. const char *boot_device,
  1327. const char *kernel_filename,
  1328. const char *kernel_cmdline,
  1329. const char *initrd_filename, const char *cpu_model)
  1330. {
  1331. unsigned int i;
  1332. void *iounits[MAX_IOUNITS], *espdma, *ledma, *nvram;
  1333. qemu_irq *cpu_irqs[MAX_CPUS], sbi_irq[32], sbi_cpu_irq[MAX_CPUS],
  1334. espdma_irq, ledma_irq;
  1335. qemu_irq esp_reset, dma_enable;
  1336. unsigned long kernel_size;
  1337. void *fw_cfg;
  1338. DeviceState *dev;
  1339. /* init CPUs */
  1340. if (!cpu_model)
  1341. cpu_model = hwdef->default_cpu_model;
  1342. for(i = 0; i < smp_cpus; i++) {
  1343. cpu_devinit(cpu_model, i, hwdef->slavio_base, &cpu_irqs[i]);
  1344. }
  1345. for (i = smp_cpus; i < MAX_CPUS; i++)
  1346. cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
  1347. /* set up devices */
  1348. ram_init(0, RAM_size, hwdef->max_mem);
  1349. prom_init(hwdef->slavio_base, bios_name);
  1350. dev = sbi_init(hwdef->sbi_base, cpu_irqs);
  1351. for (i = 0; i < 32; i++) {
  1352. sbi_irq[i] = qdev_get_gpio_in(dev, i);
  1353. }
  1354. for (i = 0; i < MAX_CPUS; i++) {
  1355. sbi_cpu_irq[i] = qdev_get_gpio_in(dev, 32 + i);
  1356. }
  1357. for (i = 0; i < MAX_IOUNITS; i++)
  1358. if (hwdef->iounit_bases[i] != (target_phys_addr_t)-1)
  1359. iounits[i] = iommu_init(hwdef->iounit_bases[i],
  1360. hwdef->iounit_version,
  1361. sbi_irq[0]);
  1362. espdma = sparc32_dma_init(hwdef->espdma_base, sbi_irq[3],
  1363. iounits[0], &espdma_irq, 0);
  1364. /* should be lebuffer instead */
  1365. ledma = sparc32_dma_init(hwdef->ledma_base, sbi_irq[4],
  1366. iounits[0], &ledma_irq, 0);
  1367. if (graphic_depth != 8 && graphic_depth != 24) {
  1368. fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
  1369. exit (1);
  1370. }
  1371. tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
  1372. graphic_depth);
  1373. lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
  1374. nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0, 0x2000, 8);
  1375. slavio_timer_init_all(hwdef->counter_base, sbi_irq[10], sbi_cpu_irq, smp_cpus);
  1376. slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[12],
  1377. display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
  1378. // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
  1379. // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
  1380. escc_init(hwdef->serial_base, sbi_irq[12], sbi_irq[12],
  1381. serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
  1382. if (drive_get_max_bus(IF_SCSI) > 0) {
  1383. fprintf(stderr, "qemu: too many SCSI bus\n");
  1384. exit(1);
  1385. }
  1386. esp_init(hwdef->esp_base, 2,
  1387. espdma_memory_read, espdma_memory_write,
  1388. espdma, espdma_irq, &esp_reset, &dma_enable);
  1389. qdev_connect_gpio_out(espdma, 0, esp_reset);
  1390. qdev_connect_gpio_out(espdma, 1, dma_enable);
  1391. kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
  1392. RAM_size);
  1393. nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
  1394. boot_device, RAM_size, kernel_size, graphic_width,
  1395. graphic_height, graphic_depth, hwdef->nvram_machine_id,
  1396. "Sun4d");
  1397. fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
  1398. fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
  1399. fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
  1400. fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
  1401. fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
  1402. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
  1403. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
  1404. if (kernel_cmdline) {
  1405. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
  1406. pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
  1407. fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
  1408. (uint8_t*)strdup(kernel_cmdline),
  1409. strlen(kernel_cmdline) + 1);
  1410. } else {
  1411. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
  1412. }
  1413. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
  1414. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
  1415. fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
  1416. qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
  1417. }
  1418. /* SPARCserver 1000 hardware initialisation */
  1419. static void ss1000_init(ram_addr_t RAM_size,
  1420. const char *boot_device,
  1421. const char *kernel_filename, const char *kernel_cmdline,
  1422. const char *initrd_filename, const char *cpu_model)
  1423. {
  1424. sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, kernel_filename,
  1425. kernel_cmdline, initrd_filename, cpu_model);
  1426. }
  1427. /* SPARCcenter 2000 hardware initialisation */
  1428. static void ss2000_init(ram_addr_t RAM_size,
  1429. const char *boot_device,
  1430. const char *kernel_filename, const char *kernel_cmdline,
  1431. const char *initrd_filename, const char *cpu_model)
  1432. {
  1433. sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, kernel_filename,
  1434. kernel_cmdline, initrd_filename, cpu_model);
  1435. }
  1436. static QEMUMachine ss1000_machine = {
  1437. .name = "SS-1000",
  1438. .desc = "Sun4d platform, SPARCserver 1000",
  1439. .init = ss1000_init,
  1440. .use_scsi = 1,
  1441. .max_cpus = 8,
  1442. };
  1443. static QEMUMachine ss2000_machine = {
  1444. .name = "SS-2000",
  1445. .desc = "Sun4d platform, SPARCcenter 2000",
  1446. .init = ss2000_init,
  1447. .use_scsi = 1,
  1448. .max_cpus = 20,
  1449. };
  1450. static const struct sun4c_hwdef sun4c_hwdefs[] = {
  1451. /* SS-2 */
  1452. {
  1453. .iommu_base = 0xf8000000,
  1454. .tcx_base = 0xfe000000,
  1455. .slavio_base = 0xf6000000,
  1456. .intctl_base = 0xf5000000,
  1457. .counter_base = 0xf3000000,
  1458. .ms_kb_base = 0xf0000000,
  1459. .serial_base = 0xf1000000,
  1460. .nvram_base = 0xf2000000,
  1461. .fd_base = 0xf7200000,
  1462. .dma_base = 0xf8400000,
  1463. .esp_base = 0xf8800000,
  1464. .le_base = 0xf8c00000,
  1465. .aux1_base = 0xf7400003,
  1466. .nvram_machine_id = 0x55,
  1467. .machine_id = ss2_id,
  1468. .max_mem = 0x10000000,
  1469. .default_cpu_model = "Cypress CY7C601",
  1470. },
  1471. };
  1472. static DeviceState *sun4c_intctl_init(target_phys_addr_t addr,
  1473. qemu_irq *parent_irq)
  1474. {
  1475. DeviceState *dev;
  1476. SysBusDevice *s;
  1477. unsigned int i;
  1478. dev = qdev_create(NULL, "sun4c_intctl");
  1479. qdev_init_nofail(dev);
  1480. s = sysbus_from_qdev(dev);
  1481. for (i = 0; i < MAX_PILS; i++) {
  1482. sysbus_connect_irq(s, i, parent_irq[i]);
  1483. }
  1484. sysbus_mmio_map(s, 0, addr);
  1485. return dev;
  1486. }
  1487. static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
  1488. const char *boot_device,
  1489. const char *kernel_filename,
  1490. const char *kernel_cmdline,
  1491. const char *initrd_filename, const char *cpu_model)
  1492. {
  1493. void *iommu, *espdma, *ledma, *nvram;
  1494. qemu_irq *cpu_irqs, slavio_irq[8], espdma_irq, ledma_irq;
  1495. qemu_irq esp_reset, dma_enable;
  1496. qemu_irq fdc_tc;
  1497. unsigned long kernel_size;
  1498. DriveInfo *fd[MAX_FD];
  1499. void *fw_cfg;
  1500. DeviceState *dev;
  1501. unsigned int i;
  1502. /* init CPU */
  1503. if (!cpu_model)
  1504. cpu_model = hwdef->default_cpu_model;
  1505. cpu_devinit(cpu_model, 0, hwdef->slavio_base, &cpu_irqs);
  1506. /* set up devices */
  1507. ram_init(0, RAM_size, hwdef->max_mem);
  1508. prom_init(hwdef->slavio_base, bios_name);
  1509. dev = sun4c_intctl_init(hwdef->intctl_base, cpu_irqs);
  1510. for (i = 0; i < 8; i++) {
  1511. slavio_irq[i] = qdev_get_gpio_in(dev, i);
  1512. }
  1513. iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
  1514. slavio_irq[1]);
  1515. espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[2],
  1516. iommu, &espdma_irq, 0);
  1517. ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
  1518. slavio_irq[3], iommu, &ledma_irq, 1);
  1519. if (graphic_depth != 8 && graphic_depth != 24) {
  1520. fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
  1521. exit (1);
  1522. }
  1523. tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
  1524. graphic_depth);
  1525. lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
  1526. nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x800, 2);
  1527. slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[1],
  1528. display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
  1529. // Slavio TTYA (base+4, Linux ttyS0) is the first Qemu serial device
  1530. // Slavio TTYB (base+0, Linux ttyS1) is the second Qemu serial device
  1531. escc_init(hwdef->serial_base, slavio_irq[1],
  1532. slavio_irq[1], serial_hds[0], serial_hds[1],
  1533. ESCC_CLOCK, 1);
  1534. slavio_misc_init(0, hwdef->aux1_base, 0, slavio_irq[1], fdc_tc);
  1535. if (hwdef->fd_base != (target_phys_addr_t)-1) {
  1536. /* there is zero or one floppy drive */
  1537. memset(fd, 0, sizeof(fd));
  1538. fd[0] = drive_get(IF_FLOPPY, 0, 0);
  1539. sun4m_fdctrl_init(slavio_irq[1], hwdef->fd_base, fd,
  1540. &fdc_tc);
  1541. }
  1542. if (drive_get_max_bus(IF_SCSI) > 0) {
  1543. fprintf(stderr, "qemu: too many SCSI bus\n");
  1544. exit(1);
  1545. }
  1546. esp_init(hwdef->esp_base, 2,
  1547. espdma_memory_read, espdma_memory_write,
  1548. espdma, espdma_irq, &esp_reset, &dma_enable);
  1549. qdev_connect_gpio_out(espdma, 0, esp_reset);
  1550. qdev_connect_gpio_out(espdma, 1, dma_enable);
  1551. kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
  1552. RAM_size);
  1553. nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
  1554. boot_device, RAM_size, kernel_size, graphic_width,
  1555. graphic_height, graphic_depth, hwdef->nvram_machine_id,
  1556. "Sun4c");
  1557. fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
  1558. fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
  1559. fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
  1560. fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
  1561. fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
  1562. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
  1563. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
  1564. if (kernel_cmdline) {
  1565. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
  1566. pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
  1567. fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA,
  1568. (uint8_t*)strdup(kernel_cmdline),
  1569. strlen(kernel_cmdline) + 1);
  1570. } else {
  1571. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
  1572. }
  1573. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
  1574. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
  1575. fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
  1576. qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
  1577. }
  1578. /* SPARCstation 2 hardware initialisation */
  1579. static void ss2_init(ram_addr_t RAM_size,
  1580. const char *boot_device,
  1581. const char *kernel_filename, const char *kernel_cmdline,
  1582. const char *initrd_filename, const char *cpu_model)
  1583. {
  1584. sun4c_hw_init(&sun4c_hwdefs[0], RAM_size, boot_device, kernel_filename,
  1585. kernel_cmdline, initrd_filename, cpu_model);
  1586. }
  1587. static QEMUMachine ss2_machine = {
  1588. .name = "SS-2",
  1589. .desc = "Sun4c platform, SPARCstation 2",
  1590. .init = ss2_init,
  1591. .use_scsi = 1,
  1592. };
  1593. static void ss2_machine_init(void)
  1594. {
  1595. qemu_register_machine(&ss5_machine);
  1596. qemu_register_machine(&ss10_machine);
  1597. qemu_register_machine(&ss600mp_machine);
  1598. qemu_register_machine(&ss20_machine);
  1599. qemu_register_machine(&voyager_machine);
  1600. qemu_register_machine(&ss_lx_machine);
  1601. qemu_register_machine(&ss4_machine);
  1602. qemu_register_machine(&scls_machine);
  1603. qemu_register_machine(&sbook_machine);
  1604. qemu_register_machine(&ss1000_machine);
  1605. qemu_register_machine(&ss2000_machine);
  1606. qemu_register_machine(&ss2_machine);
  1607. }
  1608. machine_init(ss2_machine_init);