2
0

sun4m.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936
  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/sysemu.h"
  31. #include "net/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 "sysemu/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. hwaddr iommu_base, iommu_pad_base, iommu_pad_len, slavio_base;
  86. hwaddr intctl_base, counter_base, nvram_base, ms_kb_base;
  87. hwaddr serial_base, fd_base;
  88. hwaddr afx_base, idreg_base, dma_base, esp_base, le_base;
  89. hwaddr tcx_base, cs_base, apc_base, aux1_base, aux2_base;
  90. hwaddr bpp_base, dbri_base, sx_base;
  91. struct {
  92. hwaddr reg_base, vram_base;
  93. } vsimm[MAX_VSIMMS];
  94. hwaddr 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. hwaddr iounit_bases[MAX_IOUNITS], slavio_base;
  105. hwaddr counter_base, nvram_base, ms_kb_base;
  106. hwaddr serial_base;
  107. hwaddr espdma_base, esp_base;
  108. hwaddr ledma_base, le_base;
  109. hwaddr tcx_base;
  110. hwaddr 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. hwaddr iommu_base, slavio_base;
  119. hwaddr intctl_base, counter_base, nvram_base, ms_kb_base;
  120. hwaddr serial_base, fd_base;
  121. hwaddr idreg_base, dma_base, esp_base, le_base;
  122. hwaddr 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, const QDict *qdict)
  195. {
  196. if (slavio_intctl)
  197. slavio_pic_info(mon, slavio_intctl);
  198. }
  199. void sun4m_irq_info(Monitor *mon, const QDict *qdict)
  200. {
  201. if (slavio_intctl)
  202. slavio_irq_info(mon, slavio_intctl);
  203. }
  204. void cpu_check_irqs(CPUSPARCState *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(SPARCCPU *cpu)
  227. {
  228. CPUSPARCState *env = &cpu->env;
  229. env->halted = 0;
  230. cpu_check_irqs(env);
  231. qemu_cpu_kick(CPU(cpu));
  232. }
  233. static void cpu_set_irq(void *opaque, int irq, int level)
  234. {
  235. SPARCCPU *cpu = opaque;
  236. CPUSPARCState *env = &cpu->env;
  237. if (level) {
  238. trace_sun4m_cpu_set_irq_raise(irq);
  239. env->pil_in |= 1 << irq;
  240. cpu_kick_irq(cpu);
  241. } else {
  242. trace_sun4m_cpu_set_irq_lower(irq);
  243. env->pil_in &= ~(1 << irq);
  244. cpu_check_irqs(env);
  245. }
  246. }
  247. static void dummy_cpu_set_irq(void *opaque, int irq, int level)
  248. {
  249. }
  250. static void main_cpu_reset(void *opaque)
  251. {
  252. SPARCCPU *cpu = opaque;
  253. CPUSPARCState *env = &cpu->env;
  254. cpu_reset(CPU(cpu));
  255. env->halted = 0;
  256. }
  257. static void secondary_cpu_reset(void *opaque)
  258. {
  259. SPARCCPU *cpu = opaque;
  260. CPUSPARCState *env = &cpu->env;
  261. cpu_reset(CPU(cpu));
  262. env->halted = 1;
  263. }
  264. static void cpu_halt_signal(void *opaque, int irq, int level)
  265. {
  266. if (level && cpu_single_env)
  267. cpu_interrupt(cpu_single_env, CPU_INTERRUPT_HALT);
  268. }
  269. static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
  270. {
  271. return addr - 0xf0000000ULL;
  272. }
  273. static unsigned long sun4m_load_kernel(const char *kernel_filename,
  274. const char *initrd_filename,
  275. ram_addr_t RAM_size)
  276. {
  277. int linux_boot;
  278. unsigned int i;
  279. long initrd_size, kernel_size;
  280. uint8_t *ptr;
  281. linux_boot = (kernel_filename != NULL);
  282. kernel_size = 0;
  283. if (linux_boot) {
  284. int bswap_needed;
  285. #ifdef BSWAP_NEEDED
  286. bswap_needed = 1;
  287. #else
  288. bswap_needed = 0;
  289. #endif
  290. kernel_size = load_elf(kernel_filename, translate_kernel_address, NULL,
  291. NULL, NULL, NULL, 1, ELF_MACHINE, 0);
  292. if (kernel_size < 0)
  293. kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
  294. RAM_size - KERNEL_LOAD_ADDR, bswap_needed,
  295. TARGET_PAGE_SIZE);
  296. if (kernel_size < 0)
  297. kernel_size = load_image_targphys(kernel_filename,
  298. KERNEL_LOAD_ADDR,
  299. RAM_size - KERNEL_LOAD_ADDR);
  300. if (kernel_size < 0) {
  301. fprintf(stderr, "qemu: could not load kernel '%s'\n",
  302. kernel_filename);
  303. exit(1);
  304. }
  305. /* load initrd */
  306. initrd_size = 0;
  307. if (initrd_filename) {
  308. initrd_size = load_image_targphys(initrd_filename,
  309. INITRD_LOAD_ADDR,
  310. RAM_size - INITRD_LOAD_ADDR);
  311. if (initrd_size < 0) {
  312. fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
  313. initrd_filename);
  314. exit(1);
  315. }
  316. }
  317. if (initrd_size > 0) {
  318. for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
  319. ptr = rom_ptr(KERNEL_LOAD_ADDR + i);
  320. if (ldl_p(ptr) == 0x48647253) { // HdrS
  321. stl_p(ptr + 16, INITRD_LOAD_ADDR);
  322. stl_p(ptr + 20, initrd_size);
  323. break;
  324. }
  325. }
  326. }
  327. }
  328. return kernel_size;
  329. }
  330. static void *iommu_init(hwaddr addr, uint32_t version, qemu_irq irq)
  331. {
  332. DeviceState *dev;
  333. SysBusDevice *s;
  334. dev = qdev_create(NULL, "iommu");
  335. qdev_prop_set_uint32(dev, "version", version);
  336. qdev_init_nofail(dev);
  337. s = SYS_BUS_DEVICE(dev);
  338. sysbus_connect_irq(s, 0, irq);
  339. sysbus_mmio_map(s, 0, addr);
  340. return s;
  341. }
  342. static void *sparc32_dma_init(hwaddr daddr, qemu_irq parent_irq,
  343. void *iommu, qemu_irq *dev_irq, int is_ledma)
  344. {
  345. DeviceState *dev;
  346. SysBusDevice *s;
  347. dev = qdev_create(NULL, "sparc32_dma");
  348. qdev_prop_set_ptr(dev, "iommu_opaque", iommu);
  349. qdev_prop_set_uint32(dev, "is_ledma", is_ledma);
  350. qdev_init_nofail(dev);
  351. s = SYS_BUS_DEVICE(dev);
  352. sysbus_connect_irq(s, 0, parent_irq);
  353. *dev_irq = qdev_get_gpio_in(dev, 0);
  354. sysbus_mmio_map(s, 0, daddr);
  355. return s;
  356. }
  357. static void lance_init(NICInfo *nd, hwaddr leaddr,
  358. void *dma_opaque, qemu_irq irq)
  359. {
  360. DeviceState *dev;
  361. SysBusDevice *s;
  362. qemu_irq reset;
  363. qemu_check_nic_model(&nd_table[0], "lance");
  364. dev = qdev_create(NULL, "lance");
  365. qdev_set_nic_properties(dev, nd);
  366. qdev_prop_set_ptr(dev, "dma", dma_opaque);
  367. qdev_init_nofail(dev);
  368. s = SYS_BUS_DEVICE(dev);
  369. sysbus_mmio_map(s, 0, leaddr);
  370. sysbus_connect_irq(s, 0, irq);
  371. reset = qdev_get_gpio_in(dev, 0);
  372. qdev_connect_gpio_out(dma_opaque, 0, reset);
  373. }
  374. static DeviceState *slavio_intctl_init(hwaddr addr,
  375. hwaddr addrg,
  376. qemu_irq **parent_irq)
  377. {
  378. DeviceState *dev;
  379. SysBusDevice *s;
  380. unsigned int i, j;
  381. dev = qdev_create(NULL, "slavio_intctl");
  382. qdev_init_nofail(dev);
  383. s = SYS_BUS_DEVICE(dev);
  384. for (i = 0; i < MAX_CPUS; i++) {
  385. for (j = 0; j < MAX_PILS; j++) {
  386. sysbus_connect_irq(s, i * MAX_PILS + j, parent_irq[i][j]);
  387. }
  388. }
  389. sysbus_mmio_map(s, 0, addrg);
  390. for (i = 0; i < MAX_CPUS; i++) {
  391. sysbus_mmio_map(s, i + 1, addr + i * TARGET_PAGE_SIZE);
  392. }
  393. return dev;
  394. }
  395. #define SYS_TIMER_OFFSET 0x10000ULL
  396. #define CPU_TIMER_OFFSET(cpu) (0x1000ULL * cpu)
  397. static void slavio_timer_init_all(hwaddr addr, qemu_irq master_irq,
  398. qemu_irq *cpu_irqs, unsigned int num_cpus)
  399. {
  400. DeviceState *dev;
  401. SysBusDevice *s;
  402. unsigned int i;
  403. dev = qdev_create(NULL, "slavio_timer");
  404. qdev_prop_set_uint32(dev, "num_cpus", num_cpus);
  405. qdev_init_nofail(dev);
  406. s = SYS_BUS_DEVICE(dev);
  407. sysbus_connect_irq(s, 0, master_irq);
  408. sysbus_mmio_map(s, 0, addr + SYS_TIMER_OFFSET);
  409. for (i = 0; i < MAX_CPUS; i++) {
  410. sysbus_mmio_map(s, i + 1, addr + (hwaddr)CPU_TIMER_OFFSET(i));
  411. sysbus_connect_irq(s, i + 1, cpu_irqs[i]);
  412. }
  413. }
  414. static qemu_irq slavio_system_powerdown;
  415. static void slavio_powerdown_req(Notifier *n, void *opaque)
  416. {
  417. qemu_irq_raise(slavio_system_powerdown);
  418. }
  419. static Notifier slavio_system_powerdown_notifier = {
  420. .notify = slavio_powerdown_req
  421. };
  422. #define MISC_LEDS 0x01600000
  423. #define MISC_CFG 0x01800000
  424. #define MISC_DIAG 0x01a00000
  425. #define MISC_MDM 0x01b00000
  426. #define MISC_SYS 0x01f00000
  427. static void slavio_misc_init(hwaddr base,
  428. hwaddr aux1_base,
  429. hwaddr aux2_base, qemu_irq irq,
  430. qemu_irq fdc_tc)
  431. {
  432. DeviceState *dev;
  433. SysBusDevice *s;
  434. dev = qdev_create(NULL, "slavio_misc");
  435. qdev_init_nofail(dev);
  436. s = SYS_BUS_DEVICE(dev);
  437. if (base) {
  438. /* 8 bit registers */
  439. /* Slavio control */
  440. sysbus_mmio_map(s, 0, base + MISC_CFG);
  441. /* Diagnostics */
  442. sysbus_mmio_map(s, 1, base + MISC_DIAG);
  443. /* Modem control */
  444. sysbus_mmio_map(s, 2, base + MISC_MDM);
  445. /* 16 bit registers */
  446. /* ss600mp diag LEDs */
  447. sysbus_mmio_map(s, 3, base + MISC_LEDS);
  448. /* 32 bit registers */
  449. /* System control */
  450. sysbus_mmio_map(s, 4, base + MISC_SYS);
  451. }
  452. if (aux1_base) {
  453. /* AUX 1 (Misc System Functions) */
  454. sysbus_mmio_map(s, 5, aux1_base);
  455. }
  456. if (aux2_base) {
  457. /* AUX 2 (Software Powerdown Control) */
  458. sysbus_mmio_map(s, 6, aux2_base);
  459. }
  460. sysbus_connect_irq(s, 0, irq);
  461. sysbus_connect_irq(s, 1, fdc_tc);
  462. slavio_system_powerdown = qdev_get_gpio_in(dev, 0);
  463. qemu_register_powerdown_notifier(&slavio_system_powerdown_notifier);
  464. }
  465. static void ecc_init(hwaddr base, qemu_irq irq, uint32_t version)
  466. {
  467. DeviceState *dev;
  468. SysBusDevice *s;
  469. dev = qdev_create(NULL, "eccmemctl");
  470. qdev_prop_set_uint32(dev, "version", version);
  471. qdev_init_nofail(dev);
  472. s = SYS_BUS_DEVICE(dev);
  473. sysbus_connect_irq(s, 0, irq);
  474. sysbus_mmio_map(s, 0, base);
  475. if (version == 0) { // SS-600MP only
  476. sysbus_mmio_map(s, 1, base + 0x1000);
  477. }
  478. }
  479. static void apc_init(hwaddr power_base, qemu_irq cpu_halt)
  480. {
  481. DeviceState *dev;
  482. SysBusDevice *s;
  483. dev = qdev_create(NULL, "apc");
  484. qdev_init_nofail(dev);
  485. s = SYS_BUS_DEVICE(dev);
  486. /* Power management (APC) XXX: not a Slavio device */
  487. sysbus_mmio_map(s, 0, power_base);
  488. sysbus_connect_irq(s, 0, cpu_halt);
  489. }
  490. static void tcx_init(hwaddr addr, int vram_size, int width,
  491. int height, int depth)
  492. {
  493. DeviceState *dev;
  494. SysBusDevice *s;
  495. dev = qdev_create(NULL, "SUNW,tcx");
  496. qdev_prop_set_taddr(dev, "addr", addr);
  497. qdev_prop_set_uint32(dev, "vram_size", vram_size);
  498. qdev_prop_set_uint16(dev, "width", width);
  499. qdev_prop_set_uint16(dev, "height", height);
  500. qdev_prop_set_uint16(dev, "depth", depth);
  501. qdev_init_nofail(dev);
  502. s = SYS_BUS_DEVICE(dev);
  503. /* 8-bit plane */
  504. sysbus_mmio_map(s, 0, addr + 0x00800000ULL);
  505. /* DAC */
  506. sysbus_mmio_map(s, 1, addr + 0x00200000ULL);
  507. /* TEC (dummy) */
  508. sysbus_mmio_map(s, 2, addr + 0x00700000ULL);
  509. /* THC 24 bit: NetBSD writes here even with 8-bit display: dummy */
  510. sysbus_mmio_map(s, 3, addr + 0x00301000ULL);
  511. if (depth == 24) {
  512. /* 24-bit plane */
  513. sysbus_mmio_map(s, 4, addr + 0x02000000ULL);
  514. /* Control plane */
  515. sysbus_mmio_map(s, 5, addr + 0x0a000000ULL);
  516. } else {
  517. /* THC 8 bit (dummy) */
  518. sysbus_mmio_map(s, 4, addr + 0x00300000ULL);
  519. }
  520. }
  521. /* NCR89C100/MACIO Internal ID register */
  522. static const uint8_t idreg_data[] = { 0xfe, 0x81, 0x01, 0x03 };
  523. static void idreg_init(hwaddr addr)
  524. {
  525. DeviceState *dev;
  526. SysBusDevice *s;
  527. dev = qdev_create(NULL, "macio_idreg");
  528. qdev_init_nofail(dev);
  529. s = SYS_BUS_DEVICE(dev);
  530. sysbus_mmio_map(s, 0, addr);
  531. cpu_physical_memory_write_rom(addr, idreg_data, sizeof(idreg_data));
  532. }
  533. typedef struct IDRegState {
  534. SysBusDevice busdev;
  535. MemoryRegion mem;
  536. } IDRegState;
  537. static int idreg_init1(SysBusDevice *dev)
  538. {
  539. IDRegState *s = FROM_SYSBUS(IDRegState, dev);
  540. memory_region_init_ram(&s->mem, "sun4m.idreg", sizeof(idreg_data));
  541. vmstate_register_ram_global(&s->mem);
  542. memory_region_set_readonly(&s->mem, true);
  543. sysbus_init_mmio(dev, &s->mem);
  544. return 0;
  545. }
  546. static void idreg_class_init(ObjectClass *klass, void *data)
  547. {
  548. SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
  549. k->init = idreg_init1;
  550. }
  551. static const TypeInfo idreg_info = {
  552. .name = "macio_idreg",
  553. .parent = TYPE_SYS_BUS_DEVICE,
  554. .instance_size = sizeof(IDRegState),
  555. .class_init = idreg_class_init,
  556. };
  557. typedef struct AFXState {
  558. SysBusDevice busdev;
  559. MemoryRegion mem;
  560. } AFXState;
  561. /* SS-5 TCX AFX register */
  562. static void afx_init(hwaddr addr)
  563. {
  564. DeviceState *dev;
  565. SysBusDevice *s;
  566. dev = qdev_create(NULL, "tcx_afx");
  567. qdev_init_nofail(dev);
  568. s = SYS_BUS_DEVICE(dev);
  569. sysbus_mmio_map(s, 0, addr);
  570. }
  571. static int afx_init1(SysBusDevice *dev)
  572. {
  573. AFXState *s = FROM_SYSBUS(AFXState, dev);
  574. memory_region_init_ram(&s->mem, "sun4m.afx", 4);
  575. vmstate_register_ram_global(&s->mem);
  576. sysbus_init_mmio(dev, &s->mem);
  577. return 0;
  578. }
  579. static void afx_class_init(ObjectClass *klass, void *data)
  580. {
  581. SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
  582. k->init = afx_init1;
  583. }
  584. static const TypeInfo afx_info = {
  585. .name = "tcx_afx",
  586. .parent = TYPE_SYS_BUS_DEVICE,
  587. .instance_size = sizeof(AFXState),
  588. .class_init = afx_class_init,
  589. };
  590. typedef struct PROMState {
  591. SysBusDevice busdev;
  592. MemoryRegion prom;
  593. } PROMState;
  594. /* Boot PROM (OpenBIOS) */
  595. static uint64_t translate_prom_address(void *opaque, uint64_t addr)
  596. {
  597. hwaddr *base_addr = (hwaddr *)opaque;
  598. return addr + *base_addr - PROM_VADDR;
  599. }
  600. static void prom_init(hwaddr addr, const char *bios_name)
  601. {
  602. DeviceState *dev;
  603. SysBusDevice *s;
  604. char *filename;
  605. int ret;
  606. dev = qdev_create(NULL, "openprom");
  607. qdev_init_nofail(dev);
  608. s = SYS_BUS_DEVICE(dev);
  609. sysbus_mmio_map(s, 0, addr);
  610. /* load boot prom */
  611. if (bios_name == NULL) {
  612. bios_name = PROM_FILENAME;
  613. }
  614. filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
  615. if (filename) {
  616. ret = load_elf(filename, translate_prom_address, &addr, NULL,
  617. NULL, NULL, 1, ELF_MACHINE, 0);
  618. if (ret < 0 || ret > PROM_SIZE_MAX) {
  619. ret = load_image_targphys(filename, addr, PROM_SIZE_MAX);
  620. }
  621. g_free(filename);
  622. } else {
  623. ret = -1;
  624. }
  625. if (ret < 0 || ret > PROM_SIZE_MAX) {
  626. fprintf(stderr, "qemu: could not load prom '%s'\n", bios_name);
  627. exit(1);
  628. }
  629. }
  630. static int prom_init1(SysBusDevice *dev)
  631. {
  632. PROMState *s = FROM_SYSBUS(PROMState, dev);
  633. memory_region_init_ram(&s->prom, "sun4m.prom", PROM_SIZE_MAX);
  634. vmstate_register_ram_global(&s->prom);
  635. memory_region_set_readonly(&s->prom, true);
  636. sysbus_init_mmio(dev, &s->prom);
  637. return 0;
  638. }
  639. static Property prom_properties[] = {
  640. {/* end of property list */},
  641. };
  642. static void prom_class_init(ObjectClass *klass, void *data)
  643. {
  644. DeviceClass *dc = DEVICE_CLASS(klass);
  645. SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
  646. k->init = prom_init1;
  647. dc->props = prom_properties;
  648. }
  649. static const TypeInfo prom_info = {
  650. .name = "openprom",
  651. .parent = TYPE_SYS_BUS_DEVICE,
  652. .instance_size = sizeof(PROMState),
  653. .class_init = prom_class_init,
  654. };
  655. typedef struct RamDevice
  656. {
  657. SysBusDevice busdev;
  658. MemoryRegion ram;
  659. uint64_t size;
  660. } RamDevice;
  661. /* System RAM */
  662. static int ram_init1(SysBusDevice *dev)
  663. {
  664. RamDevice *d = FROM_SYSBUS(RamDevice, dev);
  665. memory_region_init_ram(&d->ram, "sun4m.ram", d->size);
  666. vmstate_register_ram_global(&d->ram);
  667. sysbus_init_mmio(dev, &d->ram);
  668. return 0;
  669. }
  670. static void ram_init(hwaddr addr, ram_addr_t RAM_size,
  671. uint64_t max_mem)
  672. {
  673. DeviceState *dev;
  674. SysBusDevice *s;
  675. RamDevice *d;
  676. /* allocate RAM */
  677. if ((uint64_t)RAM_size > max_mem) {
  678. fprintf(stderr,
  679. "qemu: Too much memory for this machine: %d, maximum %d\n",
  680. (unsigned int)(RAM_size / (1024 * 1024)),
  681. (unsigned int)(max_mem / (1024 * 1024)));
  682. exit(1);
  683. }
  684. dev = qdev_create(NULL, "memory");
  685. s = SYS_BUS_DEVICE(dev);
  686. d = FROM_SYSBUS(RamDevice, s);
  687. d->size = RAM_size;
  688. qdev_init_nofail(dev);
  689. sysbus_mmio_map(s, 0, addr);
  690. }
  691. static Property ram_properties[] = {
  692. DEFINE_PROP_UINT64("size", RamDevice, size, 0),
  693. DEFINE_PROP_END_OF_LIST(),
  694. };
  695. static void ram_class_init(ObjectClass *klass, void *data)
  696. {
  697. DeviceClass *dc = DEVICE_CLASS(klass);
  698. SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
  699. k->init = ram_init1;
  700. dc->props = ram_properties;
  701. }
  702. static const TypeInfo ram_info = {
  703. .name = "memory",
  704. .parent = TYPE_SYS_BUS_DEVICE,
  705. .instance_size = sizeof(RamDevice),
  706. .class_init = ram_class_init,
  707. };
  708. static void cpu_devinit(const char *cpu_model, unsigned int id,
  709. uint64_t prom_addr, qemu_irq **cpu_irqs)
  710. {
  711. SPARCCPU *cpu;
  712. CPUSPARCState *env;
  713. cpu = cpu_sparc_init(cpu_model);
  714. if (cpu == NULL) {
  715. fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
  716. exit(1);
  717. }
  718. env = &cpu->env;
  719. cpu_sparc_set_id(env, id);
  720. if (id == 0) {
  721. qemu_register_reset(main_cpu_reset, cpu);
  722. } else {
  723. qemu_register_reset(secondary_cpu_reset, cpu);
  724. env->halted = 1;
  725. }
  726. *cpu_irqs = qemu_allocate_irqs(cpu_set_irq, cpu, MAX_PILS);
  727. env->prom_addr = prom_addr;
  728. }
  729. static void dummy_fdc_tc(void *opaque, int irq, int level)
  730. {
  731. }
  732. static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
  733. const char *boot_device,
  734. const char *kernel_filename,
  735. const char *kernel_cmdline,
  736. const char *initrd_filename, const char *cpu_model)
  737. {
  738. unsigned int i;
  739. void *iommu, *espdma, *ledma, *nvram;
  740. qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS],
  741. espdma_irq, ledma_irq;
  742. qemu_irq esp_reset, dma_enable;
  743. qemu_irq fdc_tc;
  744. qemu_irq *cpu_halt;
  745. unsigned long kernel_size;
  746. DriveInfo *fd[MAX_FD];
  747. void *fw_cfg;
  748. unsigned int num_vsimms;
  749. /* init CPUs */
  750. if (!cpu_model)
  751. cpu_model = hwdef->default_cpu_model;
  752. for(i = 0; i < smp_cpus; i++) {
  753. cpu_devinit(cpu_model, i, hwdef->slavio_base, &cpu_irqs[i]);
  754. }
  755. for (i = smp_cpus; i < MAX_CPUS; i++)
  756. cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
  757. /* set up devices */
  758. ram_init(0, RAM_size, hwdef->max_mem);
  759. /* models without ECC don't trap when missing ram is accessed */
  760. if (!hwdef->ecc_base) {
  761. empty_slot_init(RAM_size, hwdef->max_mem - RAM_size);
  762. }
  763. prom_init(hwdef->slavio_base, bios_name);
  764. slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
  765. hwdef->intctl_base + 0x10000ULL,
  766. cpu_irqs);
  767. for (i = 0; i < 32; i++) {
  768. slavio_irq[i] = qdev_get_gpio_in(slavio_intctl, i);
  769. }
  770. for (i = 0; i < MAX_CPUS; i++) {
  771. slavio_cpu_irq[i] = qdev_get_gpio_in(slavio_intctl, 32 + i);
  772. }
  773. if (hwdef->idreg_base) {
  774. idreg_init(hwdef->idreg_base);
  775. }
  776. if (hwdef->afx_base) {
  777. afx_init(hwdef->afx_base);
  778. }
  779. iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
  780. slavio_irq[30]);
  781. if (hwdef->iommu_pad_base) {
  782. /* On the real hardware (SS-5, LX) the MMU is not padded, but aliased.
  783. Software shouldn't use aliased addresses, neither should it crash
  784. when does. Using empty_slot instead of aliasing can help with
  785. debugging such accesses */
  786. empty_slot_init(hwdef->iommu_pad_base,hwdef->iommu_pad_len);
  787. }
  788. espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[18],
  789. iommu, &espdma_irq, 0);
  790. ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
  791. slavio_irq[16], iommu, &ledma_irq, 1);
  792. if (graphic_depth != 8 && graphic_depth != 24) {
  793. fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
  794. exit (1);
  795. }
  796. num_vsimms = 0;
  797. if (num_vsimms == 0) {
  798. tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
  799. graphic_depth);
  800. }
  801. for (i = num_vsimms; i < MAX_VSIMMS; i++) {
  802. /* vsimm registers probed by OBP */
  803. if (hwdef->vsimm[i].reg_base) {
  804. empty_slot_init(hwdef->vsimm[i].reg_base, 0x2000);
  805. }
  806. }
  807. if (hwdef->sx_base) {
  808. empty_slot_init(hwdef->sx_base, 0x2000);
  809. }
  810. lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
  811. nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x2000, 8);
  812. slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
  813. slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[14],
  814. display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
  815. /* Slavio TTYA (base+4, Linux ttyS0) is the first QEMU serial device
  816. Slavio TTYB (base+0, Linux ttyS1) is the second QEMU serial device */
  817. escc_init(hwdef->serial_base, slavio_irq[15], slavio_irq[15],
  818. serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
  819. cpu_halt = qemu_allocate_irqs(cpu_halt_signal, NULL, 1);
  820. if (hwdef->apc_base) {
  821. apc_init(hwdef->apc_base, cpu_halt[0]);
  822. }
  823. if (hwdef->fd_base) {
  824. /* there is zero or one floppy drive */
  825. memset(fd, 0, sizeof(fd));
  826. fd[0] = drive_get(IF_FLOPPY, 0, 0);
  827. sun4m_fdctrl_init(slavio_irq[22], hwdef->fd_base, fd,
  828. &fdc_tc);
  829. } else {
  830. fdc_tc = *qemu_allocate_irqs(dummy_fdc_tc, NULL, 1);
  831. }
  832. slavio_misc_init(hwdef->slavio_base, hwdef->aux1_base, hwdef->aux2_base,
  833. slavio_irq[30], fdc_tc);
  834. if (drive_get_max_bus(IF_SCSI) > 0) {
  835. fprintf(stderr, "qemu: too many SCSI bus\n");
  836. exit(1);
  837. }
  838. esp_init(hwdef->esp_base, 2,
  839. espdma_memory_read, espdma_memory_write,
  840. espdma, espdma_irq, &esp_reset, &dma_enable);
  841. qdev_connect_gpio_out(espdma, 0, esp_reset);
  842. qdev_connect_gpio_out(espdma, 1, dma_enable);
  843. if (hwdef->cs_base) {
  844. sysbus_create_simple("SUNW,CS4231", hwdef->cs_base,
  845. slavio_irq[5]);
  846. }
  847. if (hwdef->dbri_base) {
  848. /* ISDN chip with attached CS4215 audio codec */
  849. /* prom space */
  850. empty_slot_init(hwdef->dbri_base+0x1000, 0x30);
  851. /* reg space */
  852. empty_slot_init(hwdef->dbri_base+0x10000, 0x100);
  853. }
  854. if (hwdef->bpp_base) {
  855. /* parallel port */
  856. empty_slot_init(hwdef->bpp_base, 0x20);
  857. }
  858. kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
  859. RAM_size);
  860. nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
  861. boot_device, RAM_size, kernel_size, graphic_width,
  862. graphic_height, graphic_depth, hwdef->nvram_machine_id,
  863. "Sun4m");
  864. if (hwdef->ecc_base)
  865. ecc_init(hwdef->ecc_base, slavio_irq[28],
  866. hwdef->ecc_version);
  867. fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
  868. fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
  869. fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
  870. fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
  871. fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
  872. fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
  873. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
  874. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
  875. if (kernel_cmdline) {
  876. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
  877. pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
  878. fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline);
  879. fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
  880. strlen(kernel_cmdline) + 1);
  881. } else {
  882. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
  883. fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
  884. }
  885. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
  886. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
  887. fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
  888. qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
  889. }
  890. enum {
  891. ss2_id = 0,
  892. ss5_id = 32,
  893. vger_id,
  894. lx_id,
  895. ss4_id,
  896. scls_id,
  897. sbook_id,
  898. ss10_id = 64,
  899. ss20_id,
  900. ss600mp_id,
  901. ss1000_id = 96,
  902. ss2000_id,
  903. };
  904. static const struct sun4m_hwdef sun4m_hwdefs[] = {
  905. /* SS-5 */
  906. {
  907. .iommu_base = 0x10000000,
  908. .iommu_pad_base = 0x10004000,
  909. .iommu_pad_len = 0x0fffb000,
  910. .tcx_base = 0x50000000,
  911. .cs_base = 0x6c000000,
  912. .slavio_base = 0x70000000,
  913. .ms_kb_base = 0x71000000,
  914. .serial_base = 0x71100000,
  915. .nvram_base = 0x71200000,
  916. .fd_base = 0x71400000,
  917. .counter_base = 0x71d00000,
  918. .intctl_base = 0x71e00000,
  919. .idreg_base = 0x78000000,
  920. .dma_base = 0x78400000,
  921. .esp_base = 0x78800000,
  922. .le_base = 0x78c00000,
  923. .apc_base = 0x6a000000,
  924. .afx_base = 0x6e000000,
  925. .aux1_base = 0x71900000,
  926. .aux2_base = 0x71910000,
  927. .nvram_machine_id = 0x80,
  928. .machine_id = ss5_id,
  929. .iommu_version = 0x05000000,
  930. .max_mem = 0x10000000,
  931. .default_cpu_model = "Fujitsu MB86904",
  932. },
  933. /* SS-10 */
  934. {
  935. .iommu_base = 0xfe0000000ULL,
  936. .tcx_base = 0xe20000000ULL,
  937. .slavio_base = 0xff0000000ULL,
  938. .ms_kb_base = 0xff1000000ULL,
  939. .serial_base = 0xff1100000ULL,
  940. .nvram_base = 0xff1200000ULL,
  941. .fd_base = 0xff1700000ULL,
  942. .counter_base = 0xff1300000ULL,
  943. .intctl_base = 0xff1400000ULL,
  944. .idreg_base = 0xef0000000ULL,
  945. .dma_base = 0xef0400000ULL,
  946. .esp_base = 0xef0800000ULL,
  947. .le_base = 0xef0c00000ULL,
  948. .apc_base = 0xefa000000ULL, // XXX should not exist
  949. .aux1_base = 0xff1800000ULL,
  950. .aux2_base = 0xff1a01000ULL,
  951. .ecc_base = 0xf00000000ULL,
  952. .ecc_version = 0x10000000, // version 0, implementation 1
  953. .nvram_machine_id = 0x72,
  954. .machine_id = ss10_id,
  955. .iommu_version = 0x03000000,
  956. .max_mem = 0xf00000000ULL,
  957. .default_cpu_model = "TI SuperSparc II",
  958. },
  959. /* SS-600MP */
  960. {
  961. .iommu_base = 0xfe0000000ULL,
  962. .tcx_base = 0xe20000000ULL,
  963. .slavio_base = 0xff0000000ULL,
  964. .ms_kb_base = 0xff1000000ULL,
  965. .serial_base = 0xff1100000ULL,
  966. .nvram_base = 0xff1200000ULL,
  967. .counter_base = 0xff1300000ULL,
  968. .intctl_base = 0xff1400000ULL,
  969. .dma_base = 0xef0081000ULL,
  970. .esp_base = 0xef0080000ULL,
  971. .le_base = 0xef0060000ULL,
  972. .apc_base = 0xefa000000ULL, // XXX should not exist
  973. .aux1_base = 0xff1800000ULL,
  974. .aux2_base = 0xff1a01000ULL, // XXX should not exist
  975. .ecc_base = 0xf00000000ULL,
  976. .ecc_version = 0x00000000, // version 0, implementation 0
  977. .nvram_machine_id = 0x71,
  978. .machine_id = ss600mp_id,
  979. .iommu_version = 0x01000000,
  980. .max_mem = 0xf00000000ULL,
  981. .default_cpu_model = "TI SuperSparc II",
  982. },
  983. /* SS-20 */
  984. {
  985. .iommu_base = 0xfe0000000ULL,
  986. .tcx_base = 0xe20000000ULL,
  987. .slavio_base = 0xff0000000ULL,
  988. .ms_kb_base = 0xff1000000ULL,
  989. .serial_base = 0xff1100000ULL,
  990. .nvram_base = 0xff1200000ULL,
  991. .fd_base = 0xff1700000ULL,
  992. .counter_base = 0xff1300000ULL,
  993. .intctl_base = 0xff1400000ULL,
  994. .idreg_base = 0xef0000000ULL,
  995. .dma_base = 0xef0400000ULL,
  996. .esp_base = 0xef0800000ULL,
  997. .le_base = 0xef0c00000ULL,
  998. .bpp_base = 0xef4800000ULL,
  999. .apc_base = 0xefa000000ULL, // XXX should not exist
  1000. .aux1_base = 0xff1800000ULL,
  1001. .aux2_base = 0xff1a01000ULL,
  1002. .dbri_base = 0xee0000000ULL,
  1003. .sx_base = 0xf80000000ULL,
  1004. .vsimm = {
  1005. {
  1006. .reg_base = 0x9c000000ULL,
  1007. .vram_base = 0xfc000000ULL
  1008. }, {
  1009. .reg_base = 0x90000000ULL,
  1010. .vram_base = 0xf0000000ULL
  1011. }, {
  1012. .reg_base = 0x94000000ULL
  1013. }, {
  1014. .reg_base = 0x98000000ULL
  1015. }
  1016. },
  1017. .ecc_base = 0xf00000000ULL,
  1018. .ecc_version = 0x20000000, // version 0, implementation 2
  1019. .nvram_machine_id = 0x72,
  1020. .machine_id = ss20_id,
  1021. .iommu_version = 0x13000000,
  1022. .max_mem = 0xf00000000ULL,
  1023. .default_cpu_model = "TI SuperSparc II",
  1024. },
  1025. /* Voyager */
  1026. {
  1027. .iommu_base = 0x10000000,
  1028. .tcx_base = 0x50000000,
  1029. .slavio_base = 0x70000000,
  1030. .ms_kb_base = 0x71000000,
  1031. .serial_base = 0x71100000,
  1032. .nvram_base = 0x71200000,
  1033. .fd_base = 0x71400000,
  1034. .counter_base = 0x71d00000,
  1035. .intctl_base = 0x71e00000,
  1036. .idreg_base = 0x78000000,
  1037. .dma_base = 0x78400000,
  1038. .esp_base = 0x78800000,
  1039. .le_base = 0x78c00000,
  1040. .apc_base = 0x71300000, // pmc
  1041. .aux1_base = 0x71900000,
  1042. .aux2_base = 0x71910000,
  1043. .nvram_machine_id = 0x80,
  1044. .machine_id = vger_id,
  1045. .iommu_version = 0x05000000,
  1046. .max_mem = 0x10000000,
  1047. .default_cpu_model = "Fujitsu MB86904",
  1048. },
  1049. /* LX */
  1050. {
  1051. .iommu_base = 0x10000000,
  1052. .iommu_pad_base = 0x10004000,
  1053. .iommu_pad_len = 0x0fffb000,
  1054. .tcx_base = 0x50000000,
  1055. .slavio_base = 0x70000000,
  1056. .ms_kb_base = 0x71000000,
  1057. .serial_base = 0x71100000,
  1058. .nvram_base = 0x71200000,
  1059. .fd_base = 0x71400000,
  1060. .counter_base = 0x71d00000,
  1061. .intctl_base = 0x71e00000,
  1062. .idreg_base = 0x78000000,
  1063. .dma_base = 0x78400000,
  1064. .esp_base = 0x78800000,
  1065. .le_base = 0x78c00000,
  1066. .aux1_base = 0x71900000,
  1067. .aux2_base = 0x71910000,
  1068. .nvram_machine_id = 0x80,
  1069. .machine_id = lx_id,
  1070. .iommu_version = 0x04000000,
  1071. .max_mem = 0x10000000,
  1072. .default_cpu_model = "TI MicroSparc I",
  1073. },
  1074. /* SS-4 */
  1075. {
  1076. .iommu_base = 0x10000000,
  1077. .tcx_base = 0x50000000,
  1078. .cs_base = 0x6c000000,
  1079. .slavio_base = 0x70000000,
  1080. .ms_kb_base = 0x71000000,
  1081. .serial_base = 0x71100000,
  1082. .nvram_base = 0x71200000,
  1083. .fd_base = 0x71400000,
  1084. .counter_base = 0x71d00000,
  1085. .intctl_base = 0x71e00000,
  1086. .idreg_base = 0x78000000,
  1087. .dma_base = 0x78400000,
  1088. .esp_base = 0x78800000,
  1089. .le_base = 0x78c00000,
  1090. .apc_base = 0x6a000000,
  1091. .aux1_base = 0x71900000,
  1092. .aux2_base = 0x71910000,
  1093. .nvram_machine_id = 0x80,
  1094. .machine_id = ss4_id,
  1095. .iommu_version = 0x05000000,
  1096. .max_mem = 0x10000000,
  1097. .default_cpu_model = "Fujitsu MB86904",
  1098. },
  1099. /* SPARCClassic */
  1100. {
  1101. .iommu_base = 0x10000000,
  1102. .tcx_base = 0x50000000,
  1103. .slavio_base = 0x70000000,
  1104. .ms_kb_base = 0x71000000,
  1105. .serial_base = 0x71100000,
  1106. .nvram_base = 0x71200000,
  1107. .fd_base = 0x71400000,
  1108. .counter_base = 0x71d00000,
  1109. .intctl_base = 0x71e00000,
  1110. .idreg_base = 0x78000000,
  1111. .dma_base = 0x78400000,
  1112. .esp_base = 0x78800000,
  1113. .le_base = 0x78c00000,
  1114. .apc_base = 0x6a000000,
  1115. .aux1_base = 0x71900000,
  1116. .aux2_base = 0x71910000,
  1117. .nvram_machine_id = 0x80,
  1118. .machine_id = scls_id,
  1119. .iommu_version = 0x05000000,
  1120. .max_mem = 0x10000000,
  1121. .default_cpu_model = "TI MicroSparc I",
  1122. },
  1123. /* SPARCbook */
  1124. {
  1125. .iommu_base = 0x10000000,
  1126. .tcx_base = 0x50000000, // XXX
  1127. .slavio_base = 0x70000000,
  1128. .ms_kb_base = 0x71000000,
  1129. .serial_base = 0x71100000,
  1130. .nvram_base = 0x71200000,
  1131. .fd_base = 0x71400000,
  1132. .counter_base = 0x71d00000,
  1133. .intctl_base = 0x71e00000,
  1134. .idreg_base = 0x78000000,
  1135. .dma_base = 0x78400000,
  1136. .esp_base = 0x78800000,
  1137. .le_base = 0x78c00000,
  1138. .apc_base = 0x6a000000,
  1139. .aux1_base = 0x71900000,
  1140. .aux2_base = 0x71910000,
  1141. .nvram_machine_id = 0x80,
  1142. .machine_id = sbook_id,
  1143. .iommu_version = 0x05000000,
  1144. .max_mem = 0x10000000,
  1145. .default_cpu_model = "TI MicroSparc I",
  1146. },
  1147. };
  1148. /* SPARCstation 5 hardware initialisation */
  1149. static void ss5_init(QEMUMachineInitArgs *args)
  1150. {
  1151. ram_addr_t RAM_size = args->ram_size;
  1152. const char *cpu_model = args->cpu_model;
  1153. const char *kernel_filename = args->kernel_filename;
  1154. const char *kernel_cmdline = args->kernel_cmdline;
  1155. const char *initrd_filename = args->initrd_filename;
  1156. const char *boot_device = args->boot_device;
  1157. sun4m_hw_init(&sun4m_hwdefs[0], RAM_size, boot_device, kernel_filename,
  1158. kernel_cmdline, initrd_filename, cpu_model);
  1159. }
  1160. /* SPARCstation 10 hardware initialisation */
  1161. static void ss10_init(QEMUMachineInitArgs *args)
  1162. {
  1163. ram_addr_t RAM_size = args->ram_size;
  1164. const char *cpu_model = args->cpu_model;
  1165. const char *kernel_filename = args->kernel_filename;
  1166. const char *kernel_cmdline = args->kernel_cmdline;
  1167. const char *initrd_filename = args->initrd_filename;
  1168. const char *boot_device = args->boot_device;
  1169. sun4m_hw_init(&sun4m_hwdefs[1], RAM_size, boot_device, kernel_filename,
  1170. kernel_cmdline, initrd_filename, cpu_model);
  1171. }
  1172. /* SPARCserver 600MP hardware initialisation */
  1173. static void ss600mp_init(QEMUMachineInitArgs *args)
  1174. {
  1175. ram_addr_t RAM_size = args->ram_size;
  1176. const char *cpu_model = args->cpu_model;
  1177. const char *kernel_filename = args->kernel_filename;
  1178. const char *kernel_cmdline = args->kernel_cmdline;
  1179. const char *initrd_filename = args->initrd_filename;
  1180. const char *boot_device = args->boot_device;
  1181. sun4m_hw_init(&sun4m_hwdefs[2], RAM_size, boot_device, kernel_filename,
  1182. kernel_cmdline, initrd_filename, cpu_model);
  1183. }
  1184. /* SPARCstation 20 hardware initialisation */
  1185. static void ss20_init(QEMUMachineInitArgs *args)
  1186. {
  1187. ram_addr_t RAM_size = args->ram_size;
  1188. const char *cpu_model = args->cpu_model;
  1189. const char *kernel_filename = args->kernel_filename;
  1190. const char *kernel_cmdline = args->kernel_cmdline;
  1191. const char *initrd_filename = args->initrd_filename;
  1192. const char *boot_device = args->boot_device;
  1193. sun4m_hw_init(&sun4m_hwdefs[3], RAM_size, boot_device, kernel_filename,
  1194. kernel_cmdline, initrd_filename, cpu_model);
  1195. }
  1196. /* SPARCstation Voyager hardware initialisation */
  1197. static void vger_init(QEMUMachineInitArgs *args)
  1198. {
  1199. ram_addr_t RAM_size = args->ram_size;
  1200. const char *cpu_model = args->cpu_model;
  1201. const char *kernel_filename = args->kernel_filename;
  1202. const char *kernel_cmdline = args->kernel_cmdline;
  1203. const char *initrd_filename = args->initrd_filename;
  1204. const char *boot_device = args->boot_device;
  1205. sun4m_hw_init(&sun4m_hwdefs[4], RAM_size, boot_device, kernel_filename,
  1206. kernel_cmdline, initrd_filename, cpu_model);
  1207. }
  1208. /* SPARCstation LX hardware initialisation */
  1209. static void ss_lx_init(QEMUMachineInitArgs *args)
  1210. {
  1211. ram_addr_t RAM_size = args->ram_size;
  1212. const char *cpu_model = args->cpu_model;
  1213. const char *kernel_filename = args->kernel_filename;
  1214. const char *kernel_cmdline = args->kernel_cmdline;
  1215. const char *initrd_filename = args->initrd_filename;
  1216. const char *boot_device = args->boot_device;
  1217. sun4m_hw_init(&sun4m_hwdefs[5], RAM_size, boot_device, kernel_filename,
  1218. kernel_cmdline, initrd_filename, cpu_model);
  1219. }
  1220. /* SPARCstation 4 hardware initialisation */
  1221. static void ss4_init(QEMUMachineInitArgs *args)
  1222. {
  1223. ram_addr_t RAM_size = args->ram_size;
  1224. const char *cpu_model = args->cpu_model;
  1225. const char *kernel_filename = args->kernel_filename;
  1226. const char *kernel_cmdline = args->kernel_cmdline;
  1227. const char *initrd_filename = args->initrd_filename;
  1228. const char *boot_device = args->boot_device;
  1229. sun4m_hw_init(&sun4m_hwdefs[6], RAM_size, boot_device, kernel_filename,
  1230. kernel_cmdline, initrd_filename, cpu_model);
  1231. }
  1232. /* SPARCClassic hardware initialisation */
  1233. static void scls_init(QEMUMachineInitArgs *args)
  1234. {
  1235. ram_addr_t RAM_size = args->ram_size;
  1236. const char *cpu_model = args->cpu_model;
  1237. const char *kernel_filename = args->kernel_filename;
  1238. const char *kernel_cmdline = args->kernel_cmdline;
  1239. const char *initrd_filename = args->initrd_filename;
  1240. const char *boot_device = args->boot_device;
  1241. sun4m_hw_init(&sun4m_hwdefs[7], RAM_size, boot_device, kernel_filename,
  1242. kernel_cmdline, initrd_filename, cpu_model);
  1243. }
  1244. /* SPARCbook hardware initialisation */
  1245. static void sbook_init(QEMUMachineInitArgs *args)
  1246. {
  1247. ram_addr_t RAM_size = args->ram_size;
  1248. const char *cpu_model = args->cpu_model;
  1249. const char *kernel_filename = args->kernel_filename;
  1250. const char *kernel_cmdline = args->kernel_cmdline;
  1251. const char *initrd_filename = args->initrd_filename;
  1252. const char *boot_device = args->boot_device;
  1253. sun4m_hw_init(&sun4m_hwdefs[8], RAM_size, boot_device, kernel_filename,
  1254. kernel_cmdline, initrd_filename, cpu_model);
  1255. }
  1256. static QEMUMachine ss5_machine = {
  1257. .name = "SS-5",
  1258. .desc = "Sun4m platform, SPARCstation 5",
  1259. .init = ss5_init,
  1260. .block_default_type = IF_SCSI,
  1261. .is_default = 1,
  1262. DEFAULT_MACHINE_OPTIONS,
  1263. };
  1264. static QEMUMachine ss10_machine = {
  1265. .name = "SS-10",
  1266. .desc = "Sun4m platform, SPARCstation 10",
  1267. .init = ss10_init,
  1268. .block_default_type = IF_SCSI,
  1269. .max_cpus = 4,
  1270. DEFAULT_MACHINE_OPTIONS,
  1271. };
  1272. static QEMUMachine ss600mp_machine = {
  1273. .name = "SS-600MP",
  1274. .desc = "Sun4m platform, SPARCserver 600MP",
  1275. .init = ss600mp_init,
  1276. .block_default_type = IF_SCSI,
  1277. .max_cpus = 4,
  1278. DEFAULT_MACHINE_OPTIONS,
  1279. };
  1280. static QEMUMachine ss20_machine = {
  1281. .name = "SS-20",
  1282. .desc = "Sun4m platform, SPARCstation 20",
  1283. .init = ss20_init,
  1284. .block_default_type = IF_SCSI,
  1285. .max_cpus = 4,
  1286. DEFAULT_MACHINE_OPTIONS,
  1287. };
  1288. static QEMUMachine voyager_machine = {
  1289. .name = "Voyager",
  1290. .desc = "Sun4m platform, SPARCstation Voyager",
  1291. .init = vger_init,
  1292. .block_default_type = IF_SCSI,
  1293. DEFAULT_MACHINE_OPTIONS,
  1294. };
  1295. static QEMUMachine ss_lx_machine = {
  1296. .name = "LX",
  1297. .desc = "Sun4m platform, SPARCstation LX",
  1298. .init = ss_lx_init,
  1299. .block_default_type = IF_SCSI,
  1300. DEFAULT_MACHINE_OPTIONS,
  1301. };
  1302. static QEMUMachine ss4_machine = {
  1303. .name = "SS-4",
  1304. .desc = "Sun4m platform, SPARCstation 4",
  1305. .init = ss4_init,
  1306. .block_default_type = IF_SCSI,
  1307. DEFAULT_MACHINE_OPTIONS,
  1308. };
  1309. static QEMUMachine scls_machine = {
  1310. .name = "SPARCClassic",
  1311. .desc = "Sun4m platform, SPARCClassic",
  1312. .init = scls_init,
  1313. .block_default_type = IF_SCSI,
  1314. DEFAULT_MACHINE_OPTIONS,
  1315. };
  1316. static QEMUMachine sbook_machine = {
  1317. .name = "SPARCbook",
  1318. .desc = "Sun4m platform, SPARCbook",
  1319. .init = sbook_init,
  1320. .block_default_type = IF_SCSI,
  1321. DEFAULT_MACHINE_OPTIONS,
  1322. };
  1323. static const struct sun4d_hwdef sun4d_hwdefs[] = {
  1324. /* SS-1000 */
  1325. {
  1326. .iounit_bases = {
  1327. 0xfe0200000ULL,
  1328. 0xfe1200000ULL,
  1329. 0xfe2200000ULL,
  1330. 0xfe3200000ULL,
  1331. -1,
  1332. },
  1333. .tcx_base = 0x820000000ULL,
  1334. .slavio_base = 0xf00000000ULL,
  1335. .ms_kb_base = 0xf00240000ULL,
  1336. .serial_base = 0xf00200000ULL,
  1337. .nvram_base = 0xf00280000ULL,
  1338. .counter_base = 0xf00300000ULL,
  1339. .espdma_base = 0x800081000ULL,
  1340. .esp_base = 0x800080000ULL,
  1341. .ledma_base = 0x800040000ULL,
  1342. .le_base = 0x800060000ULL,
  1343. .sbi_base = 0xf02800000ULL,
  1344. .nvram_machine_id = 0x80,
  1345. .machine_id = ss1000_id,
  1346. .iounit_version = 0x03000000,
  1347. .max_mem = 0xf00000000ULL,
  1348. .default_cpu_model = "TI SuperSparc II",
  1349. },
  1350. /* SS-2000 */
  1351. {
  1352. .iounit_bases = {
  1353. 0xfe0200000ULL,
  1354. 0xfe1200000ULL,
  1355. 0xfe2200000ULL,
  1356. 0xfe3200000ULL,
  1357. 0xfe4200000ULL,
  1358. },
  1359. .tcx_base = 0x820000000ULL,
  1360. .slavio_base = 0xf00000000ULL,
  1361. .ms_kb_base = 0xf00240000ULL,
  1362. .serial_base = 0xf00200000ULL,
  1363. .nvram_base = 0xf00280000ULL,
  1364. .counter_base = 0xf00300000ULL,
  1365. .espdma_base = 0x800081000ULL,
  1366. .esp_base = 0x800080000ULL,
  1367. .ledma_base = 0x800040000ULL,
  1368. .le_base = 0x800060000ULL,
  1369. .sbi_base = 0xf02800000ULL,
  1370. .nvram_machine_id = 0x80,
  1371. .machine_id = ss2000_id,
  1372. .iounit_version = 0x03000000,
  1373. .max_mem = 0xf00000000ULL,
  1374. .default_cpu_model = "TI SuperSparc II",
  1375. },
  1376. };
  1377. static DeviceState *sbi_init(hwaddr addr, qemu_irq **parent_irq)
  1378. {
  1379. DeviceState *dev;
  1380. SysBusDevice *s;
  1381. unsigned int i;
  1382. dev = qdev_create(NULL, "sbi");
  1383. qdev_init_nofail(dev);
  1384. s = SYS_BUS_DEVICE(dev);
  1385. for (i = 0; i < MAX_CPUS; i++) {
  1386. sysbus_connect_irq(s, i, *parent_irq[i]);
  1387. }
  1388. sysbus_mmio_map(s, 0, addr);
  1389. return dev;
  1390. }
  1391. static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
  1392. const char *boot_device,
  1393. const char *kernel_filename,
  1394. const char *kernel_cmdline,
  1395. const char *initrd_filename, const char *cpu_model)
  1396. {
  1397. unsigned int i;
  1398. void *iounits[MAX_IOUNITS], *espdma, *ledma, *nvram;
  1399. qemu_irq *cpu_irqs[MAX_CPUS], sbi_irq[32], sbi_cpu_irq[MAX_CPUS],
  1400. espdma_irq, ledma_irq;
  1401. qemu_irq esp_reset, dma_enable;
  1402. unsigned long kernel_size;
  1403. void *fw_cfg;
  1404. DeviceState *dev;
  1405. /* init CPUs */
  1406. if (!cpu_model)
  1407. cpu_model = hwdef->default_cpu_model;
  1408. for(i = 0; i < smp_cpus; i++) {
  1409. cpu_devinit(cpu_model, i, hwdef->slavio_base, &cpu_irqs[i]);
  1410. }
  1411. for (i = smp_cpus; i < MAX_CPUS; i++)
  1412. cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
  1413. /* set up devices */
  1414. ram_init(0, RAM_size, hwdef->max_mem);
  1415. prom_init(hwdef->slavio_base, bios_name);
  1416. dev = sbi_init(hwdef->sbi_base, cpu_irqs);
  1417. for (i = 0; i < 32; i++) {
  1418. sbi_irq[i] = qdev_get_gpio_in(dev, i);
  1419. }
  1420. for (i = 0; i < MAX_CPUS; i++) {
  1421. sbi_cpu_irq[i] = qdev_get_gpio_in(dev, 32 + i);
  1422. }
  1423. for (i = 0; i < MAX_IOUNITS; i++)
  1424. if (hwdef->iounit_bases[i] != (hwaddr)-1)
  1425. iounits[i] = iommu_init(hwdef->iounit_bases[i],
  1426. hwdef->iounit_version,
  1427. sbi_irq[0]);
  1428. espdma = sparc32_dma_init(hwdef->espdma_base, sbi_irq[3],
  1429. iounits[0], &espdma_irq, 0);
  1430. /* should be lebuffer instead */
  1431. ledma = sparc32_dma_init(hwdef->ledma_base, sbi_irq[4],
  1432. iounits[0], &ledma_irq, 0);
  1433. if (graphic_depth != 8 && graphic_depth != 24) {
  1434. fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
  1435. exit (1);
  1436. }
  1437. tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
  1438. graphic_depth);
  1439. lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
  1440. nvram = m48t59_init(sbi_irq[0], hwdef->nvram_base, 0, 0x2000, 8);
  1441. slavio_timer_init_all(hwdef->counter_base, sbi_irq[10], sbi_cpu_irq, smp_cpus);
  1442. slavio_serial_ms_kbd_init(hwdef->ms_kb_base, sbi_irq[12],
  1443. display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
  1444. /* Slavio TTYA (base+4, Linux ttyS0) is the first QEMU serial device
  1445. Slavio TTYB (base+0, Linux ttyS1) is the second QEMU serial device */
  1446. escc_init(hwdef->serial_base, sbi_irq[12], sbi_irq[12],
  1447. serial_hds[0], serial_hds[1], ESCC_CLOCK, 1);
  1448. if (drive_get_max_bus(IF_SCSI) > 0) {
  1449. fprintf(stderr, "qemu: too many SCSI bus\n");
  1450. exit(1);
  1451. }
  1452. esp_init(hwdef->esp_base, 2,
  1453. espdma_memory_read, espdma_memory_write,
  1454. espdma, espdma_irq, &esp_reset, &dma_enable);
  1455. qdev_connect_gpio_out(espdma, 0, esp_reset);
  1456. qdev_connect_gpio_out(espdma, 1, dma_enable);
  1457. kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
  1458. RAM_size);
  1459. nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
  1460. boot_device, RAM_size, kernel_size, graphic_width,
  1461. graphic_height, graphic_depth, hwdef->nvram_machine_id,
  1462. "Sun4d");
  1463. fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
  1464. fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
  1465. fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
  1466. fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
  1467. fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
  1468. fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
  1469. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
  1470. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
  1471. if (kernel_cmdline) {
  1472. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
  1473. pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
  1474. fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline);
  1475. } else {
  1476. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
  1477. }
  1478. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
  1479. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
  1480. fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
  1481. qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
  1482. }
  1483. /* SPARCserver 1000 hardware initialisation */
  1484. static void ss1000_init(QEMUMachineInitArgs *args)
  1485. {
  1486. ram_addr_t RAM_size = args->ram_size;
  1487. const char *cpu_model = args->cpu_model;
  1488. const char *kernel_filename = args->kernel_filename;
  1489. const char *kernel_cmdline = args->kernel_cmdline;
  1490. const char *initrd_filename = args->initrd_filename;
  1491. const char *boot_device = args->boot_device;
  1492. sun4d_hw_init(&sun4d_hwdefs[0], RAM_size, boot_device, kernel_filename,
  1493. kernel_cmdline, initrd_filename, cpu_model);
  1494. }
  1495. /* SPARCcenter 2000 hardware initialisation */
  1496. static void ss2000_init(QEMUMachineInitArgs *args)
  1497. {
  1498. ram_addr_t RAM_size = args->ram_size;
  1499. const char *cpu_model = args->cpu_model;
  1500. const char *kernel_filename = args->kernel_filename;
  1501. const char *kernel_cmdline = args->kernel_cmdline;
  1502. const char *initrd_filename = args->initrd_filename;
  1503. const char *boot_device = args->boot_device;
  1504. sun4d_hw_init(&sun4d_hwdefs[1], RAM_size, boot_device, kernel_filename,
  1505. kernel_cmdline, initrd_filename, cpu_model);
  1506. }
  1507. static QEMUMachine ss1000_machine = {
  1508. .name = "SS-1000",
  1509. .desc = "Sun4d platform, SPARCserver 1000",
  1510. .init = ss1000_init,
  1511. .block_default_type = IF_SCSI,
  1512. .max_cpus = 8,
  1513. DEFAULT_MACHINE_OPTIONS,
  1514. };
  1515. static QEMUMachine ss2000_machine = {
  1516. .name = "SS-2000",
  1517. .desc = "Sun4d platform, SPARCcenter 2000",
  1518. .init = ss2000_init,
  1519. .block_default_type = IF_SCSI,
  1520. .max_cpus = 20,
  1521. DEFAULT_MACHINE_OPTIONS,
  1522. };
  1523. static const struct sun4c_hwdef sun4c_hwdefs[] = {
  1524. /* SS-2 */
  1525. {
  1526. .iommu_base = 0xf8000000,
  1527. .tcx_base = 0xfe000000,
  1528. .slavio_base = 0xf6000000,
  1529. .intctl_base = 0xf5000000,
  1530. .counter_base = 0xf3000000,
  1531. .ms_kb_base = 0xf0000000,
  1532. .serial_base = 0xf1000000,
  1533. .nvram_base = 0xf2000000,
  1534. .fd_base = 0xf7200000,
  1535. .dma_base = 0xf8400000,
  1536. .esp_base = 0xf8800000,
  1537. .le_base = 0xf8c00000,
  1538. .aux1_base = 0xf7400003,
  1539. .nvram_machine_id = 0x55,
  1540. .machine_id = ss2_id,
  1541. .max_mem = 0x10000000,
  1542. .default_cpu_model = "Cypress CY7C601",
  1543. },
  1544. };
  1545. static DeviceState *sun4c_intctl_init(hwaddr addr,
  1546. qemu_irq *parent_irq)
  1547. {
  1548. DeviceState *dev;
  1549. SysBusDevice *s;
  1550. unsigned int i;
  1551. dev = qdev_create(NULL, "sun4c_intctl");
  1552. qdev_init_nofail(dev);
  1553. s = SYS_BUS_DEVICE(dev);
  1554. for (i = 0; i < MAX_PILS; i++) {
  1555. sysbus_connect_irq(s, i, parent_irq[i]);
  1556. }
  1557. sysbus_mmio_map(s, 0, addr);
  1558. return dev;
  1559. }
  1560. static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
  1561. const char *boot_device,
  1562. const char *kernel_filename,
  1563. const char *kernel_cmdline,
  1564. const char *initrd_filename, const char *cpu_model)
  1565. {
  1566. void *iommu, *espdma, *ledma, *nvram;
  1567. qemu_irq *cpu_irqs, slavio_irq[8], espdma_irq, ledma_irq;
  1568. qemu_irq esp_reset, dma_enable;
  1569. qemu_irq fdc_tc;
  1570. unsigned long kernel_size;
  1571. DriveInfo *fd[MAX_FD];
  1572. void *fw_cfg;
  1573. DeviceState *dev;
  1574. unsigned int i;
  1575. /* init CPU */
  1576. if (!cpu_model)
  1577. cpu_model = hwdef->default_cpu_model;
  1578. cpu_devinit(cpu_model, 0, hwdef->slavio_base, &cpu_irqs);
  1579. /* set up devices */
  1580. ram_init(0, RAM_size, hwdef->max_mem);
  1581. prom_init(hwdef->slavio_base, bios_name);
  1582. dev = sun4c_intctl_init(hwdef->intctl_base, cpu_irqs);
  1583. for (i = 0; i < 8; i++) {
  1584. slavio_irq[i] = qdev_get_gpio_in(dev, i);
  1585. }
  1586. iommu = iommu_init(hwdef->iommu_base, hwdef->iommu_version,
  1587. slavio_irq[1]);
  1588. espdma = sparc32_dma_init(hwdef->dma_base, slavio_irq[2],
  1589. iommu, &espdma_irq, 0);
  1590. ledma = sparc32_dma_init(hwdef->dma_base + 16ULL,
  1591. slavio_irq[3], iommu, &ledma_irq, 1);
  1592. if (graphic_depth != 8 && graphic_depth != 24) {
  1593. fprintf(stderr, "qemu: Unsupported depth: %d\n", graphic_depth);
  1594. exit (1);
  1595. }
  1596. tcx_init(hwdef->tcx_base, 0x00100000, graphic_width, graphic_height,
  1597. graphic_depth);
  1598. lance_init(&nd_table[0], hwdef->le_base, ledma, ledma_irq);
  1599. nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x800, 2);
  1600. slavio_serial_ms_kbd_init(hwdef->ms_kb_base, slavio_irq[1],
  1601. display_type == DT_NOGRAPHIC, ESCC_CLOCK, 1);
  1602. /* Slavio TTYA (base+4, Linux ttyS0) is the first QEMU serial device
  1603. Slavio TTYB (base+0, Linux ttyS1) is the second QEMU serial device */
  1604. escc_init(hwdef->serial_base, slavio_irq[1],
  1605. slavio_irq[1], serial_hds[0], serial_hds[1],
  1606. ESCC_CLOCK, 1);
  1607. if (hwdef->fd_base != (hwaddr)-1) {
  1608. /* there is zero or one floppy drive */
  1609. memset(fd, 0, sizeof(fd));
  1610. fd[0] = drive_get(IF_FLOPPY, 0, 0);
  1611. sun4m_fdctrl_init(slavio_irq[1], hwdef->fd_base, fd,
  1612. &fdc_tc);
  1613. } else {
  1614. fdc_tc = *qemu_allocate_irqs(dummy_fdc_tc, NULL, 1);
  1615. }
  1616. slavio_misc_init(0, hwdef->aux1_base, 0, slavio_irq[1], fdc_tc);
  1617. if (drive_get_max_bus(IF_SCSI) > 0) {
  1618. fprintf(stderr, "qemu: too many SCSI bus\n");
  1619. exit(1);
  1620. }
  1621. esp_init(hwdef->esp_base, 2,
  1622. espdma_memory_read, espdma_memory_write,
  1623. espdma, espdma_irq, &esp_reset, &dma_enable);
  1624. qdev_connect_gpio_out(espdma, 0, esp_reset);
  1625. qdev_connect_gpio_out(espdma, 1, dma_enable);
  1626. kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
  1627. RAM_size);
  1628. nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, kernel_cmdline,
  1629. boot_device, RAM_size, kernel_size, graphic_width,
  1630. graphic_height, graphic_depth, hwdef->nvram_machine_id,
  1631. "Sun4c");
  1632. fw_cfg = fw_cfg_init(0, 0, CFG_ADDR, CFG_ADDR + 2);
  1633. fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
  1634. fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1);
  1635. fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size);
  1636. fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
  1637. fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
  1638. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
  1639. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
  1640. if (kernel_cmdline) {
  1641. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
  1642. pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE, kernel_cmdline);
  1643. fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline);
  1644. } else {
  1645. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
  1646. }
  1647. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
  1648. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, 0); // not used
  1649. fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, boot_device[0]);
  1650. qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
  1651. }
  1652. /* SPARCstation 2 hardware initialisation */
  1653. static void ss2_init(QEMUMachineInitArgs *args)
  1654. {
  1655. ram_addr_t RAM_size = args->ram_size;
  1656. const char *cpu_model = args->cpu_model;
  1657. const char *kernel_filename = args->kernel_filename;
  1658. const char *kernel_cmdline = args->kernel_cmdline;
  1659. const char *initrd_filename = args->initrd_filename;
  1660. const char *boot_device = args->boot_device;
  1661. sun4c_hw_init(&sun4c_hwdefs[0], RAM_size, boot_device, kernel_filename,
  1662. kernel_cmdline, initrd_filename, cpu_model);
  1663. }
  1664. static QEMUMachine ss2_machine = {
  1665. .name = "SS-2",
  1666. .desc = "Sun4c platform, SPARCstation 2",
  1667. .init = ss2_init,
  1668. .block_default_type = IF_SCSI,
  1669. DEFAULT_MACHINE_OPTIONS,
  1670. };
  1671. static void sun4m_register_types(void)
  1672. {
  1673. type_register_static(&idreg_info);
  1674. type_register_static(&afx_info);
  1675. type_register_static(&prom_info);
  1676. type_register_static(&ram_info);
  1677. }
  1678. static void ss2_machine_init(void)
  1679. {
  1680. qemu_register_machine(&ss5_machine);
  1681. qemu_register_machine(&ss10_machine);
  1682. qemu_register_machine(&ss600mp_machine);
  1683. qemu_register_machine(&ss20_machine);
  1684. qemu_register_machine(&voyager_machine);
  1685. qemu_register_machine(&ss_lx_machine);
  1686. qemu_register_machine(&ss4_machine);
  1687. qemu_register_machine(&scls_machine);
  1688. qemu_register_machine(&sbook_machine);
  1689. qemu_register_machine(&ss1000_machine);
  1690. qemu_register_machine(&ss2000_machine);
  1691. qemu_register_machine(&ss2_machine);
  1692. }
  1693. type_init(sun4m_register_types)
  1694. machine_init(ss2_machine_init);