sun4m.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597
  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 "qemu/osdep.h"
  25. #include "qemu/units.h"
  26. #include "qapi/error.h"
  27. #include "qemu-common.h"
  28. #include "cpu.h"
  29. #include "hw/sysbus.h"
  30. #include "qemu/error-report.h"
  31. #include "qemu/timer.h"
  32. #include "hw/sparc/sun4m_iommu.h"
  33. #include "hw/rtc/m48t59.h"
  34. #include "migration/vmstate.h"
  35. #include "hw/sparc/sparc32_dma.h"
  36. #include "hw/block/fdc.h"
  37. #include "sysemu/reset.h"
  38. #include "sysemu/runstate.h"
  39. #include "sysemu/sysemu.h"
  40. #include "net/net.h"
  41. #include "hw/boards.h"
  42. #include "hw/scsi/esp.h"
  43. #include "hw/nvram/sun_nvram.h"
  44. #include "hw/qdev-properties.h"
  45. #include "hw/nvram/chrp_nvram.h"
  46. #include "hw/nvram/fw_cfg.h"
  47. #include "hw/char/escc.h"
  48. #include "hw/misc/empty_slot.h"
  49. #include "hw/misc/unimp.h"
  50. #include "hw/irq.h"
  51. #include "hw/loader.h"
  52. #include "elf.h"
  53. #include "trace.h"
  54. /*
  55. * Sun4m architecture was used in the following machines:
  56. *
  57. * SPARCserver 6xxMP/xx
  58. * SPARCclassic (SPARCclassic Server)(SPARCstation LC) (4/15),
  59. * SPARCclassic X (4/10)
  60. * SPARCstation LX/ZX (4/30)
  61. * SPARCstation Voyager
  62. * SPARCstation 10/xx, SPARCserver 10/xx
  63. * SPARCstation 5, SPARCserver 5
  64. * SPARCstation 20/xx, SPARCserver 20
  65. * SPARCstation 4
  66. *
  67. * See for example: http://www.sunhelp.org/faq/sunref1.html
  68. */
  69. #define KERNEL_LOAD_ADDR 0x00004000
  70. #define CMDLINE_ADDR 0x007ff000
  71. #define INITRD_LOAD_ADDR 0x00800000
  72. #define PROM_SIZE_MAX (1 * MiB)
  73. #define PROM_VADDR 0xffd00000
  74. #define PROM_FILENAME "openbios-sparc32"
  75. #define CFG_ADDR 0xd00000510ULL
  76. #define FW_CFG_SUN4M_DEPTH (FW_CFG_ARCH_LOCAL + 0x00)
  77. #define FW_CFG_SUN4M_WIDTH (FW_CFG_ARCH_LOCAL + 0x01)
  78. #define FW_CFG_SUN4M_HEIGHT (FW_CFG_ARCH_LOCAL + 0x02)
  79. #define MAX_CPUS 16
  80. #define MAX_PILS 16
  81. #define MAX_VSIMMS 4
  82. #define ESCC_CLOCK 4915200
  83. struct sun4m_hwdef {
  84. hwaddr iommu_base, iommu_pad_base, iommu_pad_len, slavio_base;
  85. hwaddr intctl_base, counter_base, nvram_base, ms_kb_base;
  86. hwaddr serial_base, fd_base;
  87. hwaddr afx_base, idreg_base, dma_base, esp_base, le_base;
  88. hwaddr tcx_base, cs_base, apc_base, aux1_base, aux2_base;
  89. hwaddr bpp_base, dbri_base, sx_base;
  90. struct {
  91. hwaddr reg_base, vram_base;
  92. } vsimm[MAX_VSIMMS];
  93. hwaddr ecc_base;
  94. uint64_t max_mem;
  95. uint32_t ecc_version;
  96. uint32_t iommu_version;
  97. uint16_t machine_id;
  98. uint8_t nvram_machine_id;
  99. };
  100. const char *fw_cfg_arch_key_name(uint16_t key)
  101. {
  102. static const struct {
  103. uint16_t key;
  104. const char *name;
  105. } fw_cfg_arch_wellknown_keys[] = {
  106. {FW_CFG_SUN4M_DEPTH, "depth"},
  107. {FW_CFG_SUN4M_WIDTH, "width"},
  108. {FW_CFG_SUN4M_HEIGHT, "height"},
  109. };
  110. for (size_t i = 0; i < ARRAY_SIZE(fw_cfg_arch_wellknown_keys); i++) {
  111. if (fw_cfg_arch_wellknown_keys[i].key == key) {
  112. return fw_cfg_arch_wellknown_keys[i].name;
  113. }
  114. }
  115. return NULL;
  116. }
  117. static void fw_cfg_boot_set(void *opaque, const char *boot_device,
  118. Error **errp)
  119. {
  120. fw_cfg_modify_i16(opaque, FW_CFG_BOOT_DEVICE, boot_device[0]);
  121. }
  122. static void nvram_init(Nvram *nvram, uint8_t *macaddr,
  123. const char *cmdline, const char *boot_devices,
  124. ram_addr_t RAM_size, uint32_t kernel_size,
  125. int width, int height, int depth,
  126. int nvram_machine_id, const char *arch)
  127. {
  128. unsigned int i;
  129. int sysp_end;
  130. uint8_t image[0x1ff0];
  131. NvramClass *k = NVRAM_GET_CLASS(nvram);
  132. memset(image, '\0', sizeof(image));
  133. /* OpenBIOS nvram variables partition */
  134. sysp_end = chrp_nvram_create_system_partition(image, 0);
  135. /* Free space partition */
  136. chrp_nvram_create_free_partition(&image[sysp_end], 0x1fd0 - sysp_end);
  137. Sun_init_header((struct Sun_nvram *)&image[0x1fd8], macaddr,
  138. nvram_machine_id);
  139. for (i = 0; i < sizeof(image); i++) {
  140. (k->write)(nvram, i, image[i]);
  141. }
  142. }
  143. void cpu_check_irqs(CPUSPARCState *env)
  144. {
  145. CPUState *cs;
  146. /* We should be holding the BQL before we mess with IRQs */
  147. g_assert(qemu_mutex_iothread_locked());
  148. if (env->pil_in && (env->interrupt_index == 0 ||
  149. (env->interrupt_index & ~15) == TT_EXTINT)) {
  150. unsigned int i;
  151. for (i = 15; i > 0; i--) {
  152. if (env->pil_in & (1 << i)) {
  153. int old_interrupt = env->interrupt_index;
  154. env->interrupt_index = TT_EXTINT | i;
  155. if (old_interrupt != env->interrupt_index) {
  156. cs = env_cpu(env);
  157. trace_sun4m_cpu_interrupt(i);
  158. cpu_interrupt(cs, CPU_INTERRUPT_HARD);
  159. }
  160. break;
  161. }
  162. }
  163. } else if (!env->pil_in && (env->interrupt_index & ~15) == TT_EXTINT) {
  164. cs = env_cpu(env);
  165. trace_sun4m_cpu_reset_interrupt(env->interrupt_index & 15);
  166. env->interrupt_index = 0;
  167. cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
  168. }
  169. }
  170. static void cpu_kick_irq(SPARCCPU *cpu)
  171. {
  172. CPUSPARCState *env = &cpu->env;
  173. CPUState *cs = CPU(cpu);
  174. cs->halted = 0;
  175. cpu_check_irqs(env);
  176. qemu_cpu_kick(cs);
  177. }
  178. static void cpu_set_irq(void *opaque, int irq, int level)
  179. {
  180. SPARCCPU *cpu = opaque;
  181. CPUSPARCState *env = &cpu->env;
  182. if (level) {
  183. trace_sun4m_cpu_set_irq_raise(irq);
  184. env->pil_in |= 1 << irq;
  185. cpu_kick_irq(cpu);
  186. } else {
  187. trace_sun4m_cpu_set_irq_lower(irq);
  188. env->pil_in &= ~(1 << irq);
  189. cpu_check_irqs(env);
  190. }
  191. }
  192. static void dummy_cpu_set_irq(void *opaque, int irq, int level)
  193. {
  194. }
  195. static void main_cpu_reset(void *opaque)
  196. {
  197. SPARCCPU *cpu = opaque;
  198. CPUState *cs = CPU(cpu);
  199. cpu_reset(cs);
  200. cs->halted = 0;
  201. }
  202. static void secondary_cpu_reset(void *opaque)
  203. {
  204. SPARCCPU *cpu = opaque;
  205. CPUState *cs = CPU(cpu);
  206. cpu_reset(cs);
  207. cs->halted = 1;
  208. }
  209. static void cpu_halt_signal(void *opaque, int irq, int level)
  210. {
  211. if (level && current_cpu) {
  212. cpu_interrupt(current_cpu, CPU_INTERRUPT_HALT);
  213. }
  214. }
  215. static uint64_t translate_kernel_address(void *opaque, uint64_t addr)
  216. {
  217. return addr - 0xf0000000ULL;
  218. }
  219. static unsigned long sun4m_load_kernel(const char *kernel_filename,
  220. const char *initrd_filename,
  221. ram_addr_t RAM_size,
  222. uint32_t *initrd_size)
  223. {
  224. int linux_boot;
  225. unsigned int i;
  226. long kernel_size;
  227. uint8_t *ptr;
  228. linux_boot = (kernel_filename != NULL);
  229. kernel_size = 0;
  230. if (linux_boot) {
  231. int bswap_needed;
  232. #ifdef BSWAP_NEEDED
  233. bswap_needed = 1;
  234. #else
  235. bswap_needed = 0;
  236. #endif
  237. kernel_size = load_elf(kernel_filename, NULL,
  238. translate_kernel_address, NULL,
  239. NULL, NULL, NULL, NULL, 1, EM_SPARC, 0, 0);
  240. if (kernel_size < 0)
  241. kernel_size = load_aout(kernel_filename, KERNEL_LOAD_ADDR,
  242. RAM_size - KERNEL_LOAD_ADDR, bswap_needed,
  243. TARGET_PAGE_SIZE);
  244. if (kernel_size < 0)
  245. kernel_size = load_image_targphys(kernel_filename,
  246. KERNEL_LOAD_ADDR,
  247. RAM_size - KERNEL_LOAD_ADDR);
  248. if (kernel_size < 0) {
  249. error_report("could not load kernel '%s'", kernel_filename);
  250. exit(1);
  251. }
  252. /* load initrd */
  253. *initrd_size = 0;
  254. if (initrd_filename) {
  255. *initrd_size = load_image_targphys(initrd_filename,
  256. INITRD_LOAD_ADDR,
  257. RAM_size - INITRD_LOAD_ADDR);
  258. if ((int)*initrd_size < 0) {
  259. error_report("could not load initial ram disk '%s'",
  260. initrd_filename);
  261. exit(1);
  262. }
  263. }
  264. if (*initrd_size > 0) {
  265. for (i = 0; i < 64 * TARGET_PAGE_SIZE; i += TARGET_PAGE_SIZE) {
  266. ptr = rom_ptr(KERNEL_LOAD_ADDR + i, 24);
  267. if (ptr && ldl_p(ptr) == 0x48647253) { /* HdrS */
  268. stl_p(ptr + 16, INITRD_LOAD_ADDR);
  269. stl_p(ptr + 20, *initrd_size);
  270. break;
  271. }
  272. }
  273. }
  274. }
  275. return kernel_size;
  276. }
  277. static void *iommu_init(hwaddr addr, uint32_t version, qemu_irq irq)
  278. {
  279. DeviceState *dev;
  280. SysBusDevice *s;
  281. dev = qdev_new(TYPE_SUN4M_IOMMU);
  282. qdev_prop_set_uint32(dev, "version", version);
  283. s = SYS_BUS_DEVICE(dev);
  284. sysbus_realize_and_unref(s, &error_fatal);
  285. sysbus_connect_irq(s, 0, irq);
  286. sysbus_mmio_map(s, 0, addr);
  287. return s;
  288. }
  289. static void *sparc32_dma_init(hwaddr dma_base,
  290. hwaddr esp_base, qemu_irq espdma_irq,
  291. hwaddr le_base, qemu_irq ledma_irq)
  292. {
  293. DeviceState *dma;
  294. ESPDMADeviceState *espdma;
  295. LEDMADeviceState *ledma;
  296. SysBusESPState *esp;
  297. SysBusPCNetState *lance;
  298. dma = qdev_new(TYPE_SPARC32_DMA);
  299. sysbus_realize_and_unref(SYS_BUS_DEVICE(dma), &error_fatal);
  300. sysbus_mmio_map(SYS_BUS_DEVICE(dma), 0, dma_base);
  301. espdma = SPARC32_ESPDMA_DEVICE(object_resolve_path_component(
  302. OBJECT(dma), "espdma"));
  303. sysbus_connect_irq(SYS_BUS_DEVICE(espdma), 0, espdma_irq);
  304. esp = ESP_STATE(object_resolve_path_component(OBJECT(espdma), "esp"));
  305. sysbus_mmio_map(SYS_BUS_DEVICE(esp), 0, esp_base);
  306. scsi_bus_legacy_handle_cmdline(&esp->esp.bus);
  307. ledma = SPARC32_LEDMA_DEVICE(object_resolve_path_component(
  308. OBJECT(dma), "ledma"));
  309. sysbus_connect_irq(SYS_BUS_DEVICE(ledma), 0, ledma_irq);
  310. lance = SYSBUS_PCNET(object_resolve_path_component(
  311. OBJECT(ledma), "lance"));
  312. sysbus_mmio_map(SYS_BUS_DEVICE(lance), 0, le_base);
  313. return dma;
  314. }
  315. static DeviceState *slavio_intctl_init(hwaddr addr,
  316. hwaddr addrg,
  317. qemu_irq **parent_irq)
  318. {
  319. DeviceState *dev;
  320. SysBusDevice *s;
  321. unsigned int i, j;
  322. dev = qdev_new("slavio_intctl");
  323. s = SYS_BUS_DEVICE(dev);
  324. sysbus_realize_and_unref(s, &error_fatal);
  325. for (i = 0; i < MAX_CPUS; i++) {
  326. for (j = 0; j < MAX_PILS; j++) {
  327. sysbus_connect_irq(s, i * MAX_PILS + j, parent_irq[i][j]);
  328. }
  329. }
  330. sysbus_mmio_map(s, 0, addrg);
  331. for (i = 0; i < MAX_CPUS; i++) {
  332. sysbus_mmio_map(s, i + 1, addr + i * TARGET_PAGE_SIZE);
  333. }
  334. return dev;
  335. }
  336. #define SYS_TIMER_OFFSET 0x10000ULL
  337. #define CPU_TIMER_OFFSET(cpu) (0x1000ULL * cpu)
  338. static void slavio_timer_init_all(hwaddr addr, qemu_irq master_irq,
  339. qemu_irq *cpu_irqs, unsigned int num_cpus)
  340. {
  341. DeviceState *dev;
  342. SysBusDevice *s;
  343. unsigned int i;
  344. dev = qdev_new("slavio_timer");
  345. qdev_prop_set_uint32(dev, "num_cpus", num_cpus);
  346. s = SYS_BUS_DEVICE(dev);
  347. sysbus_realize_and_unref(s, &error_fatal);
  348. sysbus_connect_irq(s, 0, master_irq);
  349. sysbus_mmio_map(s, 0, addr + SYS_TIMER_OFFSET);
  350. for (i = 0; i < MAX_CPUS; i++) {
  351. sysbus_mmio_map(s, i + 1, addr + (hwaddr)CPU_TIMER_OFFSET(i));
  352. sysbus_connect_irq(s, i + 1, cpu_irqs[i]);
  353. }
  354. }
  355. static qemu_irq slavio_system_powerdown;
  356. static void slavio_powerdown_req(Notifier *n, void *opaque)
  357. {
  358. qemu_irq_raise(slavio_system_powerdown);
  359. }
  360. static Notifier slavio_system_powerdown_notifier = {
  361. .notify = slavio_powerdown_req
  362. };
  363. #define MISC_LEDS 0x01600000
  364. #define MISC_CFG 0x01800000
  365. #define MISC_DIAG 0x01a00000
  366. #define MISC_MDM 0x01b00000
  367. #define MISC_SYS 0x01f00000
  368. static void slavio_misc_init(hwaddr base,
  369. hwaddr aux1_base,
  370. hwaddr aux2_base, qemu_irq irq,
  371. qemu_irq fdc_tc)
  372. {
  373. DeviceState *dev;
  374. SysBusDevice *s;
  375. dev = qdev_new("slavio_misc");
  376. s = SYS_BUS_DEVICE(dev);
  377. sysbus_realize_and_unref(s, &error_fatal);
  378. if (base) {
  379. /* 8 bit registers */
  380. /* Slavio control */
  381. sysbus_mmio_map(s, 0, base + MISC_CFG);
  382. /* Diagnostics */
  383. sysbus_mmio_map(s, 1, base + MISC_DIAG);
  384. /* Modem control */
  385. sysbus_mmio_map(s, 2, base + MISC_MDM);
  386. /* 16 bit registers */
  387. /* ss600mp diag LEDs */
  388. sysbus_mmio_map(s, 3, base + MISC_LEDS);
  389. /* 32 bit registers */
  390. /* System control */
  391. sysbus_mmio_map(s, 4, base + MISC_SYS);
  392. }
  393. if (aux1_base) {
  394. /* AUX 1 (Misc System Functions) */
  395. sysbus_mmio_map(s, 5, aux1_base);
  396. }
  397. if (aux2_base) {
  398. /* AUX 2 (Software Powerdown Control) */
  399. sysbus_mmio_map(s, 6, aux2_base);
  400. }
  401. sysbus_connect_irq(s, 0, irq);
  402. sysbus_connect_irq(s, 1, fdc_tc);
  403. slavio_system_powerdown = qdev_get_gpio_in(dev, 0);
  404. qemu_register_powerdown_notifier(&slavio_system_powerdown_notifier);
  405. }
  406. static void ecc_init(hwaddr base, qemu_irq irq, uint32_t version)
  407. {
  408. DeviceState *dev;
  409. SysBusDevice *s;
  410. dev = qdev_new("eccmemctl");
  411. qdev_prop_set_uint32(dev, "version", version);
  412. s = SYS_BUS_DEVICE(dev);
  413. sysbus_realize_and_unref(s, &error_fatal);
  414. sysbus_connect_irq(s, 0, irq);
  415. sysbus_mmio_map(s, 0, base);
  416. if (version == 0) { // SS-600MP only
  417. sysbus_mmio_map(s, 1, base + 0x1000);
  418. }
  419. }
  420. static void apc_init(hwaddr power_base, qemu_irq cpu_halt)
  421. {
  422. DeviceState *dev;
  423. SysBusDevice *s;
  424. dev = qdev_new("apc");
  425. s = SYS_BUS_DEVICE(dev);
  426. sysbus_realize_and_unref(s, &error_fatal);
  427. /* Power management (APC) XXX: not a Slavio device */
  428. sysbus_mmio_map(s, 0, power_base);
  429. sysbus_connect_irq(s, 0, cpu_halt);
  430. }
  431. static void tcx_init(hwaddr addr, qemu_irq irq, int vram_size, int width,
  432. int height, int depth)
  433. {
  434. DeviceState *dev;
  435. SysBusDevice *s;
  436. dev = qdev_new("SUNW,tcx");
  437. qdev_prop_set_uint32(dev, "vram_size", vram_size);
  438. qdev_prop_set_uint16(dev, "width", width);
  439. qdev_prop_set_uint16(dev, "height", height);
  440. qdev_prop_set_uint16(dev, "depth", depth);
  441. s = SYS_BUS_DEVICE(dev);
  442. sysbus_realize_and_unref(s, &error_fatal);
  443. /* 10/ROM : FCode ROM */
  444. sysbus_mmio_map(s, 0, addr);
  445. /* 2/STIP : Stipple */
  446. sysbus_mmio_map(s, 1, addr + 0x04000000ULL);
  447. /* 3/BLIT : Blitter */
  448. sysbus_mmio_map(s, 2, addr + 0x06000000ULL);
  449. /* 5/RSTIP : Raw Stipple */
  450. sysbus_mmio_map(s, 3, addr + 0x0c000000ULL);
  451. /* 6/RBLIT : Raw Blitter */
  452. sysbus_mmio_map(s, 4, addr + 0x0e000000ULL);
  453. /* 7/TEC : Transform Engine */
  454. sysbus_mmio_map(s, 5, addr + 0x00700000ULL);
  455. /* 8/CMAP : DAC */
  456. sysbus_mmio_map(s, 6, addr + 0x00200000ULL);
  457. /* 9/THC : */
  458. if (depth == 8) {
  459. sysbus_mmio_map(s, 7, addr + 0x00300000ULL);
  460. } else {
  461. sysbus_mmio_map(s, 7, addr + 0x00301000ULL);
  462. }
  463. /* 11/DHC : */
  464. sysbus_mmio_map(s, 8, addr + 0x00240000ULL);
  465. /* 12/ALT : */
  466. sysbus_mmio_map(s, 9, addr + 0x00280000ULL);
  467. /* 0/DFB8 : 8-bit plane */
  468. sysbus_mmio_map(s, 10, addr + 0x00800000ULL);
  469. /* 1/DFB24 : 24bit plane */
  470. sysbus_mmio_map(s, 11, addr + 0x02000000ULL);
  471. /* 4/RDFB32: Raw framebuffer. Control plane */
  472. sysbus_mmio_map(s, 12, addr + 0x0a000000ULL);
  473. /* 9/THC24bits : NetBSD writes here even with 8-bit display: dummy */
  474. if (depth == 8) {
  475. sysbus_mmio_map(s, 13, addr + 0x00301000ULL);
  476. }
  477. sysbus_connect_irq(s, 0, irq);
  478. }
  479. static void cg3_init(hwaddr addr, qemu_irq irq, int vram_size, int width,
  480. int height, int depth)
  481. {
  482. DeviceState *dev;
  483. SysBusDevice *s;
  484. dev = qdev_new("cgthree");
  485. qdev_prop_set_uint32(dev, "vram-size", vram_size);
  486. qdev_prop_set_uint16(dev, "width", width);
  487. qdev_prop_set_uint16(dev, "height", height);
  488. qdev_prop_set_uint16(dev, "depth", depth);
  489. s = SYS_BUS_DEVICE(dev);
  490. sysbus_realize_and_unref(s, &error_fatal);
  491. /* FCode ROM */
  492. sysbus_mmio_map(s, 0, addr);
  493. /* DAC */
  494. sysbus_mmio_map(s, 1, addr + 0x400000ULL);
  495. /* 8-bit plane */
  496. sysbus_mmio_map(s, 2, addr + 0x800000ULL);
  497. sysbus_connect_irq(s, 0, irq);
  498. }
  499. /* NCR89C100/MACIO Internal ID register */
  500. #define TYPE_MACIO_ID_REGISTER "macio_idreg"
  501. static const uint8_t idreg_data[] = { 0xfe, 0x81, 0x01, 0x03 };
  502. static void idreg_init(hwaddr addr)
  503. {
  504. DeviceState *dev;
  505. SysBusDevice *s;
  506. dev = qdev_new(TYPE_MACIO_ID_REGISTER);
  507. s = SYS_BUS_DEVICE(dev);
  508. sysbus_realize_and_unref(s, &error_fatal);
  509. sysbus_mmio_map(s, 0, addr);
  510. address_space_write_rom(&address_space_memory, addr,
  511. MEMTXATTRS_UNSPECIFIED,
  512. idreg_data, sizeof(idreg_data));
  513. }
  514. #define MACIO_ID_REGISTER(obj) \
  515. OBJECT_CHECK(IDRegState, (obj), TYPE_MACIO_ID_REGISTER)
  516. typedef struct IDRegState {
  517. SysBusDevice parent_obj;
  518. MemoryRegion mem;
  519. } IDRegState;
  520. static void idreg_realize(DeviceState *ds, Error **errp)
  521. {
  522. IDRegState *s = MACIO_ID_REGISTER(ds);
  523. SysBusDevice *dev = SYS_BUS_DEVICE(ds);
  524. Error *local_err = NULL;
  525. memory_region_init_ram_nomigrate(&s->mem, OBJECT(ds), "sun4m.idreg",
  526. sizeof(idreg_data), &local_err);
  527. if (local_err) {
  528. error_propagate(errp, local_err);
  529. return;
  530. }
  531. vmstate_register_ram_global(&s->mem);
  532. memory_region_set_readonly(&s->mem, true);
  533. sysbus_init_mmio(dev, &s->mem);
  534. }
  535. static void idreg_class_init(ObjectClass *oc, void *data)
  536. {
  537. DeviceClass *dc = DEVICE_CLASS(oc);
  538. dc->realize = idreg_realize;
  539. }
  540. static const TypeInfo idreg_info = {
  541. .name = TYPE_MACIO_ID_REGISTER,
  542. .parent = TYPE_SYS_BUS_DEVICE,
  543. .instance_size = sizeof(IDRegState),
  544. .class_init = idreg_class_init,
  545. };
  546. #define TYPE_TCX_AFX "tcx_afx"
  547. #define TCX_AFX(obj) OBJECT_CHECK(AFXState, (obj), TYPE_TCX_AFX)
  548. typedef struct AFXState {
  549. SysBusDevice parent_obj;
  550. MemoryRegion mem;
  551. } AFXState;
  552. /* SS-5 TCX AFX register */
  553. static void afx_init(hwaddr addr)
  554. {
  555. DeviceState *dev;
  556. SysBusDevice *s;
  557. dev = qdev_new(TYPE_TCX_AFX);
  558. s = SYS_BUS_DEVICE(dev);
  559. sysbus_realize_and_unref(s, &error_fatal);
  560. sysbus_mmio_map(s, 0, addr);
  561. }
  562. static void afx_realize(DeviceState *ds, Error **errp)
  563. {
  564. AFXState *s = TCX_AFX(ds);
  565. SysBusDevice *dev = SYS_BUS_DEVICE(ds);
  566. Error *local_err = NULL;
  567. memory_region_init_ram_nomigrate(&s->mem, OBJECT(ds), "sun4m.afx", 4,
  568. &local_err);
  569. if (local_err) {
  570. error_propagate(errp, local_err);
  571. return;
  572. }
  573. vmstate_register_ram_global(&s->mem);
  574. sysbus_init_mmio(dev, &s->mem);
  575. }
  576. static void afx_class_init(ObjectClass *oc, void *data)
  577. {
  578. DeviceClass *dc = DEVICE_CLASS(oc);
  579. dc->realize = afx_realize;
  580. }
  581. static const TypeInfo afx_info = {
  582. .name = TYPE_TCX_AFX,
  583. .parent = TYPE_SYS_BUS_DEVICE,
  584. .instance_size = sizeof(AFXState),
  585. .class_init = afx_class_init,
  586. };
  587. #define TYPE_OPENPROM "openprom"
  588. #define OPENPROM(obj) OBJECT_CHECK(PROMState, (obj), TYPE_OPENPROM)
  589. typedef struct PROMState {
  590. SysBusDevice parent_obj;
  591. MemoryRegion prom;
  592. } PROMState;
  593. /* Boot PROM (OpenBIOS) */
  594. static uint64_t translate_prom_address(void *opaque, uint64_t addr)
  595. {
  596. hwaddr *base_addr = (hwaddr *)opaque;
  597. return addr + *base_addr - PROM_VADDR;
  598. }
  599. static void prom_init(hwaddr addr, const char *bios_name)
  600. {
  601. DeviceState *dev;
  602. SysBusDevice *s;
  603. char *filename;
  604. int ret;
  605. dev = qdev_new(TYPE_OPENPROM);
  606. s = SYS_BUS_DEVICE(dev);
  607. sysbus_realize_and_unref(s, &error_fatal);
  608. sysbus_mmio_map(s, 0, addr);
  609. /* load boot prom */
  610. if (bios_name == NULL) {
  611. bios_name = PROM_FILENAME;
  612. }
  613. filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
  614. if (filename) {
  615. ret = load_elf(filename, NULL,
  616. translate_prom_address, &addr, NULL,
  617. NULL, NULL, NULL, 1, EM_SPARC, 0, 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. error_report("could not load prom '%s'", bios_name);
  627. exit(1);
  628. }
  629. }
  630. static void prom_realize(DeviceState *ds, Error **errp)
  631. {
  632. PROMState *s = OPENPROM(ds);
  633. SysBusDevice *dev = SYS_BUS_DEVICE(ds);
  634. Error *local_err = NULL;
  635. memory_region_init_ram_nomigrate(&s->prom, OBJECT(ds), "sun4m.prom",
  636. PROM_SIZE_MAX, &local_err);
  637. if (local_err) {
  638. error_propagate(errp, local_err);
  639. return;
  640. }
  641. vmstate_register_ram_global(&s->prom);
  642. memory_region_set_readonly(&s->prom, true);
  643. sysbus_init_mmio(dev, &s->prom);
  644. }
  645. static Property prom_properties[] = {
  646. {/* end of property list */},
  647. };
  648. static void prom_class_init(ObjectClass *klass, void *data)
  649. {
  650. DeviceClass *dc = DEVICE_CLASS(klass);
  651. device_class_set_props(dc, prom_properties);
  652. dc->realize = prom_realize;
  653. }
  654. static const TypeInfo prom_info = {
  655. .name = TYPE_OPENPROM,
  656. .parent = TYPE_SYS_BUS_DEVICE,
  657. .instance_size = sizeof(PROMState),
  658. .class_init = prom_class_init,
  659. };
  660. #define TYPE_SUN4M_MEMORY "memory"
  661. #define SUN4M_RAM(obj) OBJECT_CHECK(RamDevice, (obj), TYPE_SUN4M_MEMORY)
  662. typedef struct RamDevice {
  663. SysBusDevice parent_obj;
  664. HostMemoryBackend *memdev;
  665. } RamDevice;
  666. /* System RAM */
  667. static void ram_realize(DeviceState *dev, Error **errp)
  668. {
  669. RamDevice *d = SUN4M_RAM(dev);
  670. MemoryRegion *ram = host_memory_backend_get_memory(d->memdev);
  671. sysbus_init_mmio(SYS_BUS_DEVICE(dev), ram);
  672. }
  673. static void ram_initfn(Object *obj)
  674. {
  675. RamDevice *d = SUN4M_RAM(obj);
  676. object_property_add_link(obj, "memdev", TYPE_MEMORY_BACKEND,
  677. (Object **)&d->memdev,
  678. object_property_allow_set_link,
  679. OBJ_PROP_LINK_STRONG);
  680. object_property_set_description(obj, "memdev", "Set RAM backend"
  681. "Valid value is ID of a hostmem backend");
  682. }
  683. static void ram_class_init(ObjectClass *klass, void *data)
  684. {
  685. DeviceClass *dc = DEVICE_CLASS(klass);
  686. dc->realize = ram_realize;
  687. }
  688. static const TypeInfo ram_info = {
  689. .name = TYPE_SUN4M_MEMORY,
  690. .parent = TYPE_SYS_BUS_DEVICE,
  691. .instance_size = sizeof(RamDevice),
  692. .instance_init = ram_initfn,
  693. .class_init = ram_class_init,
  694. };
  695. static void cpu_devinit(const char *cpu_type, unsigned int id,
  696. uint64_t prom_addr, qemu_irq **cpu_irqs)
  697. {
  698. CPUState *cs;
  699. SPARCCPU *cpu;
  700. CPUSPARCState *env;
  701. cpu = SPARC_CPU(cpu_create(cpu_type));
  702. env = &cpu->env;
  703. cpu_sparc_set_id(env, id);
  704. if (id == 0) {
  705. qemu_register_reset(main_cpu_reset, cpu);
  706. } else {
  707. qemu_register_reset(secondary_cpu_reset, cpu);
  708. cs = CPU(cpu);
  709. cs->halted = 1;
  710. }
  711. *cpu_irqs = qemu_allocate_irqs(cpu_set_irq, cpu, MAX_PILS);
  712. env->prom_addr = prom_addr;
  713. }
  714. static void dummy_fdc_tc(void *opaque, int irq, int level)
  715. {
  716. }
  717. static void sun4m_hw_init(const struct sun4m_hwdef *hwdef,
  718. MachineState *machine)
  719. {
  720. DeviceState *slavio_intctl;
  721. unsigned int i;
  722. void *nvram;
  723. qemu_irq *cpu_irqs[MAX_CPUS], slavio_irq[32], slavio_cpu_irq[MAX_CPUS];
  724. qemu_irq fdc_tc;
  725. unsigned long kernel_size;
  726. uint32_t initrd_size;
  727. DriveInfo *fd[MAX_FD];
  728. FWCfgState *fw_cfg;
  729. DeviceState *dev;
  730. SysBusDevice *s;
  731. unsigned int smp_cpus = machine->smp.cpus;
  732. unsigned int max_cpus = machine->smp.max_cpus;
  733. Object *ram_memdev = object_resolve_path_type(machine->ram_memdev_id,
  734. TYPE_MEMORY_BACKEND, NULL);
  735. if (machine->ram_size > hwdef->max_mem) {
  736. error_report("Too much memory for this machine: %" PRId64 ","
  737. " maximum %" PRId64,
  738. machine->ram_size / MiB, hwdef->max_mem / MiB);
  739. exit(1);
  740. }
  741. /* init CPUs */
  742. for(i = 0; i < smp_cpus; i++) {
  743. cpu_devinit(machine->cpu_type, i, hwdef->slavio_base, &cpu_irqs[i]);
  744. }
  745. for (i = smp_cpus; i < MAX_CPUS; i++)
  746. cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
  747. /* Create and map RAM frontend */
  748. dev = qdev_new("memory");
  749. object_property_set_link(OBJECT(dev), "memdev", ram_memdev, &error_fatal);
  750. sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
  751. sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0);
  752. /* models without ECC don't trap when missing ram is accessed */
  753. if (!hwdef->ecc_base) {
  754. empty_slot_init("ecc", machine->ram_size,
  755. hwdef->max_mem - machine->ram_size);
  756. }
  757. prom_init(hwdef->slavio_base, bios_name);
  758. slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
  759. hwdef->intctl_base + 0x10000ULL,
  760. cpu_irqs);
  761. for (i = 0; i < 32; i++) {
  762. slavio_irq[i] = qdev_get_gpio_in(slavio_intctl, i);
  763. }
  764. for (i = 0; i < MAX_CPUS; i++) {
  765. slavio_cpu_irq[i] = qdev_get_gpio_in(slavio_intctl, 32 + i);
  766. }
  767. if (hwdef->idreg_base) {
  768. idreg_init(hwdef->idreg_base);
  769. }
  770. if (hwdef->afx_base) {
  771. afx_init(hwdef->afx_base);
  772. }
  773. iommu_init(hwdef->iommu_base, hwdef->iommu_version, slavio_irq[30]);
  774. if (hwdef->iommu_pad_base) {
  775. /* On the real hardware (SS-5, LX) the MMU is not padded, but aliased.
  776. Software shouldn't use aliased addresses, neither should it crash
  777. when does. Using empty_slot instead of aliasing can help with
  778. debugging such accesses */
  779. empty_slot_init("iommu.alias",
  780. hwdef->iommu_pad_base, hwdef->iommu_pad_len);
  781. }
  782. sparc32_dma_init(hwdef->dma_base,
  783. hwdef->esp_base, slavio_irq[18],
  784. hwdef->le_base, slavio_irq[16]);
  785. if (graphic_depth != 8 && graphic_depth != 24) {
  786. error_report("Unsupported depth: %d", graphic_depth);
  787. exit (1);
  788. }
  789. if (vga_interface_type != VGA_NONE) {
  790. if (vga_interface_type == VGA_CG3) {
  791. if (graphic_depth != 8) {
  792. error_report("Unsupported depth: %d", graphic_depth);
  793. exit(1);
  794. }
  795. if (!(graphic_width == 1024 && graphic_height == 768) &&
  796. !(graphic_width == 1152 && graphic_height == 900)) {
  797. error_report("Unsupported resolution: %d x %d", graphic_width,
  798. graphic_height);
  799. exit(1);
  800. }
  801. /* sbus irq 5 */
  802. cg3_init(hwdef->tcx_base, slavio_irq[11], 0x00100000,
  803. graphic_width, graphic_height, graphic_depth);
  804. } else {
  805. /* If no display specified, default to TCX */
  806. if (graphic_depth != 8 && graphic_depth != 24) {
  807. error_report("Unsupported depth: %d", graphic_depth);
  808. exit(1);
  809. }
  810. if (!(graphic_width == 1024 && graphic_height == 768)) {
  811. error_report("Unsupported resolution: %d x %d",
  812. graphic_width, graphic_height);
  813. exit(1);
  814. }
  815. tcx_init(hwdef->tcx_base, slavio_irq[11], 0x00100000,
  816. graphic_width, graphic_height, graphic_depth);
  817. }
  818. }
  819. for (i = 0; i < MAX_VSIMMS; i++) {
  820. /* vsimm registers probed by OBP */
  821. if (hwdef->vsimm[i].reg_base) {
  822. char *name = g_strdup_printf("vsimm[%d]", i);
  823. empty_slot_init(name, hwdef->vsimm[i].reg_base, 0x2000);
  824. g_free(name);
  825. }
  826. }
  827. if (hwdef->sx_base) {
  828. create_unimplemented_device("SUNW,sx", hwdef->sx_base, 0x2000);
  829. }
  830. nvram = m48t59_init(slavio_irq[0], hwdef->nvram_base, 0, 0x2000, 1968, 8);
  831. slavio_timer_init_all(hwdef->counter_base, slavio_irq[19], slavio_cpu_irq, smp_cpus);
  832. /* Slavio TTYA (base+4, Linux ttyS0) is the first QEMU serial device
  833. Slavio TTYB (base+0, Linux ttyS1) is the second QEMU serial device */
  834. dev = qdev_new(TYPE_ESCC);
  835. qdev_prop_set_uint32(dev, "disabled", !machine->enable_graphics);
  836. qdev_prop_set_uint32(dev, "frequency", ESCC_CLOCK);
  837. qdev_prop_set_uint32(dev, "it_shift", 1);
  838. qdev_prop_set_chr(dev, "chrB", NULL);
  839. qdev_prop_set_chr(dev, "chrA", NULL);
  840. qdev_prop_set_uint32(dev, "chnBtype", escc_mouse);
  841. qdev_prop_set_uint32(dev, "chnAtype", escc_kbd);
  842. s = SYS_BUS_DEVICE(dev);
  843. sysbus_realize_and_unref(s, &error_fatal);
  844. sysbus_connect_irq(s, 0, slavio_irq[14]);
  845. sysbus_connect_irq(s, 1, slavio_irq[14]);
  846. sysbus_mmio_map(s, 0, hwdef->ms_kb_base);
  847. dev = qdev_new(TYPE_ESCC);
  848. qdev_prop_set_uint32(dev, "disabled", 0);
  849. qdev_prop_set_uint32(dev, "frequency", ESCC_CLOCK);
  850. qdev_prop_set_uint32(dev, "it_shift", 1);
  851. qdev_prop_set_chr(dev, "chrB", serial_hd(1));
  852. qdev_prop_set_chr(dev, "chrA", serial_hd(0));
  853. qdev_prop_set_uint32(dev, "chnBtype", escc_serial);
  854. qdev_prop_set_uint32(dev, "chnAtype", escc_serial);
  855. s = SYS_BUS_DEVICE(dev);
  856. sysbus_realize_and_unref(s, &error_fatal);
  857. sysbus_connect_irq(s, 0, slavio_irq[15]);
  858. sysbus_connect_irq(s, 1, slavio_irq[15]);
  859. sysbus_mmio_map(s, 0, hwdef->serial_base);
  860. if (hwdef->apc_base) {
  861. apc_init(hwdef->apc_base, qemu_allocate_irq(cpu_halt_signal, NULL, 0));
  862. }
  863. if (hwdef->fd_base) {
  864. /* there is zero or one floppy drive */
  865. memset(fd, 0, sizeof(fd));
  866. fd[0] = drive_get(IF_FLOPPY, 0, 0);
  867. sun4m_fdctrl_init(slavio_irq[22], hwdef->fd_base, fd,
  868. &fdc_tc);
  869. } else {
  870. fdc_tc = qemu_allocate_irq(dummy_fdc_tc, NULL, 0);
  871. }
  872. slavio_misc_init(hwdef->slavio_base, hwdef->aux1_base, hwdef->aux2_base,
  873. slavio_irq[30], fdc_tc);
  874. if (hwdef->cs_base) {
  875. sysbus_create_simple("SUNW,CS4231", hwdef->cs_base,
  876. slavio_irq[5]);
  877. }
  878. if (hwdef->dbri_base) {
  879. /* ISDN chip with attached CS4215 audio codec */
  880. /* prom space */
  881. create_unimplemented_device("SUNW,DBRI.prom",
  882. hwdef->dbri_base + 0x1000, 0x30);
  883. /* reg space */
  884. create_unimplemented_device("SUNW,DBRI",
  885. hwdef->dbri_base + 0x10000, 0x100);
  886. }
  887. if (hwdef->bpp_base) {
  888. /* parallel port */
  889. create_unimplemented_device("SUNW,bpp", hwdef->bpp_base, 0x20);
  890. }
  891. initrd_size = 0;
  892. kernel_size = sun4m_load_kernel(machine->kernel_filename,
  893. machine->initrd_filename,
  894. machine->ram_size, &initrd_size);
  895. nvram_init(nvram, (uint8_t *)&nd_table[0].macaddr, machine->kernel_cmdline,
  896. machine->boot_order, machine->ram_size, kernel_size,
  897. graphic_width, graphic_height, graphic_depth,
  898. hwdef->nvram_machine_id, "Sun4m");
  899. if (hwdef->ecc_base)
  900. ecc_init(hwdef->ecc_base, slavio_irq[28],
  901. hwdef->ecc_version);
  902. dev = qdev_new(TYPE_FW_CFG_MEM);
  903. fw_cfg = FW_CFG(dev);
  904. qdev_prop_set_uint32(dev, "data_width", 1);
  905. qdev_prop_set_bit(dev, "dma_enabled", false);
  906. object_property_add_child(OBJECT(qdev_get_machine()), TYPE_FW_CFG,
  907. OBJECT(fw_cfg));
  908. s = SYS_BUS_DEVICE(dev);
  909. sysbus_realize_and_unref(s, &error_fatal);
  910. sysbus_mmio_map(s, 0, CFG_ADDR);
  911. sysbus_mmio_map(s, 1, CFG_ADDR + 2);
  912. fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)smp_cpus);
  913. fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)max_cpus);
  914. fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)machine->ram_size);
  915. fw_cfg_add_i16(fw_cfg, FW_CFG_MACHINE_ID, hwdef->machine_id);
  916. fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_DEPTH, graphic_depth);
  917. fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_WIDTH, graphic_width);
  918. fw_cfg_add_i16(fw_cfg, FW_CFG_SUN4M_HEIGHT, graphic_height);
  919. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_ADDR, KERNEL_LOAD_ADDR);
  920. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_SIZE, kernel_size);
  921. if (machine->kernel_cmdline) {
  922. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, CMDLINE_ADDR);
  923. pstrcpy_targphys("cmdline", CMDLINE_ADDR, TARGET_PAGE_SIZE,
  924. machine->kernel_cmdline);
  925. fw_cfg_add_string(fw_cfg, FW_CFG_CMDLINE_DATA, machine->kernel_cmdline);
  926. fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE,
  927. strlen(machine->kernel_cmdline) + 1);
  928. } else {
  929. fw_cfg_add_i32(fw_cfg, FW_CFG_KERNEL_CMDLINE, 0);
  930. fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, 0);
  931. }
  932. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_ADDR, INITRD_LOAD_ADDR);
  933. fw_cfg_add_i32(fw_cfg, FW_CFG_INITRD_SIZE, initrd_size);
  934. fw_cfg_add_i16(fw_cfg, FW_CFG_BOOT_DEVICE, machine->boot_order[0]);
  935. qemu_register_boot_set(fw_cfg_boot_set, fw_cfg);
  936. }
  937. enum {
  938. ss5_id = 32,
  939. vger_id,
  940. lx_id,
  941. ss4_id,
  942. scls_id,
  943. sbook_id,
  944. ss10_id = 64,
  945. ss20_id,
  946. ss600mp_id,
  947. };
  948. static const struct sun4m_hwdef sun4m_hwdefs[] = {
  949. /* SS-5 */
  950. {
  951. .iommu_base = 0x10000000,
  952. .iommu_pad_base = 0x10004000,
  953. .iommu_pad_len = 0x0fffb000,
  954. .tcx_base = 0x50000000,
  955. .cs_base = 0x6c000000,
  956. .slavio_base = 0x70000000,
  957. .ms_kb_base = 0x71000000,
  958. .serial_base = 0x71100000,
  959. .nvram_base = 0x71200000,
  960. .fd_base = 0x71400000,
  961. .counter_base = 0x71d00000,
  962. .intctl_base = 0x71e00000,
  963. .idreg_base = 0x78000000,
  964. .dma_base = 0x78400000,
  965. .esp_base = 0x78800000,
  966. .le_base = 0x78c00000,
  967. .apc_base = 0x6a000000,
  968. .afx_base = 0x6e000000,
  969. .aux1_base = 0x71900000,
  970. .aux2_base = 0x71910000,
  971. .nvram_machine_id = 0x80,
  972. .machine_id = ss5_id,
  973. .iommu_version = 0x05000000,
  974. .max_mem = 0x10000000,
  975. },
  976. /* SS-10 */
  977. {
  978. .iommu_base = 0xfe0000000ULL,
  979. .tcx_base = 0xe20000000ULL,
  980. .slavio_base = 0xff0000000ULL,
  981. .ms_kb_base = 0xff1000000ULL,
  982. .serial_base = 0xff1100000ULL,
  983. .nvram_base = 0xff1200000ULL,
  984. .fd_base = 0xff1700000ULL,
  985. .counter_base = 0xff1300000ULL,
  986. .intctl_base = 0xff1400000ULL,
  987. .idreg_base = 0xef0000000ULL,
  988. .dma_base = 0xef0400000ULL,
  989. .esp_base = 0xef0800000ULL,
  990. .le_base = 0xef0c00000ULL,
  991. .apc_base = 0xefa000000ULL, // XXX should not exist
  992. .aux1_base = 0xff1800000ULL,
  993. .aux2_base = 0xff1a01000ULL,
  994. .ecc_base = 0xf00000000ULL,
  995. .ecc_version = 0x10000000, // version 0, implementation 1
  996. .nvram_machine_id = 0x72,
  997. .machine_id = ss10_id,
  998. .iommu_version = 0x03000000,
  999. .max_mem = 0xf00000000ULL,
  1000. },
  1001. /* SS-600MP */
  1002. {
  1003. .iommu_base = 0xfe0000000ULL,
  1004. .tcx_base = 0xe20000000ULL,
  1005. .slavio_base = 0xff0000000ULL,
  1006. .ms_kb_base = 0xff1000000ULL,
  1007. .serial_base = 0xff1100000ULL,
  1008. .nvram_base = 0xff1200000ULL,
  1009. .counter_base = 0xff1300000ULL,
  1010. .intctl_base = 0xff1400000ULL,
  1011. .dma_base = 0xef0081000ULL,
  1012. .esp_base = 0xef0080000ULL,
  1013. .le_base = 0xef0060000ULL,
  1014. .apc_base = 0xefa000000ULL, // XXX should not exist
  1015. .aux1_base = 0xff1800000ULL,
  1016. .aux2_base = 0xff1a01000ULL, // XXX should not exist
  1017. .ecc_base = 0xf00000000ULL,
  1018. .ecc_version = 0x00000000, // version 0, implementation 0
  1019. .nvram_machine_id = 0x71,
  1020. .machine_id = ss600mp_id,
  1021. .iommu_version = 0x01000000,
  1022. .max_mem = 0xf00000000ULL,
  1023. },
  1024. /* SS-20 */
  1025. {
  1026. .iommu_base = 0xfe0000000ULL,
  1027. .tcx_base = 0xe20000000ULL,
  1028. .slavio_base = 0xff0000000ULL,
  1029. .ms_kb_base = 0xff1000000ULL,
  1030. .serial_base = 0xff1100000ULL,
  1031. .nvram_base = 0xff1200000ULL,
  1032. .fd_base = 0xff1700000ULL,
  1033. .counter_base = 0xff1300000ULL,
  1034. .intctl_base = 0xff1400000ULL,
  1035. .idreg_base = 0xef0000000ULL,
  1036. .dma_base = 0xef0400000ULL,
  1037. .esp_base = 0xef0800000ULL,
  1038. .le_base = 0xef0c00000ULL,
  1039. .bpp_base = 0xef4800000ULL,
  1040. .apc_base = 0xefa000000ULL, // XXX should not exist
  1041. .aux1_base = 0xff1800000ULL,
  1042. .aux2_base = 0xff1a01000ULL,
  1043. .dbri_base = 0xee0000000ULL,
  1044. .sx_base = 0xf80000000ULL,
  1045. .vsimm = {
  1046. {
  1047. .reg_base = 0x9c000000ULL,
  1048. .vram_base = 0xfc000000ULL
  1049. }, {
  1050. .reg_base = 0x90000000ULL,
  1051. .vram_base = 0xf0000000ULL
  1052. }, {
  1053. .reg_base = 0x94000000ULL
  1054. }, {
  1055. .reg_base = 0x98000000ULL
  1056. }
  1057. },
  1058. .ecc_base = 0xf00000000ULL,
  1059. .ecc_version = 0x20000000, // version 0, implementation 2
  1060. .nvram_machine_id = 0x72,
  1061. .machine_id = ss20_id,
  1062. .iommu_version = 0x13000000,
  1063. .max_mem = 0xf00000000ULL,
  1064. },
  1065. /* Voyager */
  1066. {
  1067. .iommu_base = 0x10000000,
  1068. .tcx_base = 0x50000000,
  1069. .slavio_base = 0x70000000,
  1070. .ms_kb_base = 0x71000000,
  1071. .serial_base = 0x71100000,
  1072. .nvram_base = 0x71200000,
  1073. .fd_base = 0x71400000,
  1074. .counter_base = 0x71d00000,
  1075. .intctl_base = 0x71e00000,
  1076. .idreg_base = 0x78000000,
  1077. .dma_base = 0x78400000,
  1078. .esp_base = 0x78800000,
  1079. .le_base = 0x78c00000,
  1080. .apc_base = 0x71300000, // pmc
  1081. .aux1_base = 0x71900000,
  1082. .aux2_base = 0x71910000,
  1083. .nvram_machine_id = 0x80,
  1084. .machine_id = vger_id,
  1085. .iommu_version = 0x05000000,
  1086. .max_mem = 0x10000000,
  1087. },
  1088. /* LX */
  1089. {
  1090. .iommu_base = 0x10000000,
  1091. .iommu_pad_base = 0x10004000,
  1092. .iommu_pad_len = 0x0fffb000,
  1093. .tcx_base = 0x50000000,
  1094. .slavio_base = 0x70000000,
  1095. .ms_kb_base = 0x71000000,
  1096. .serial_base = 0x71100000,
  1097. .nvram_base = 0x71200000,
  1098. .fd_base = 0x71400000,
  1099. .counter_base = 0x71d00000,
  1100. .intctl_base = 0x71e00000,
  1101. .idreg_base = 0x78000000,
  1102. .dma_base = 0x78400000,
  1103. .esp_base = 0x78800000,
  1104. .le_base = 0x78c00000,
  1105. .aux1_base = 0x71900000,
  1106. .aux2_base = 0x71910000,
  1107. .nvram_machine_id = 0x80,
  1108. .machine_id = lx_id,
  1109. .iommu_version = 0x04000000,
  1110. .max_mem = 0x10000000,
  1111. },
  1112. /* SS-4 */
  1113. {
  1114. .iommu_base = 0x10000000,
  1115. .tcx_base = 0x50000000,
  1116. .cs_base = 0x6c000000,
  1117. .slavio_base = 0x70000000,
  1118. .ms_kb_base = 0x71000000,
  1119. .serial_base = 0x71100000,
  1120. .nvram_base = 0x71200000,
  1121. .fd_base = 0x71400000,
  1122. .counter_base = 0x71d00000,
  1123. .intctl_base = 0x71e00000,
  1124. .idreg_base = 0x78000000,
  1125. .dma_base = 0x78400000,
  1126. .esp_base = 0x78800000,
  1127. .le_base = 0x78c00000,
  1128. .apc_base = 0x6a000000,
  1129. .aux1_base = 0x71900000,
  1130. .aux2_base = 0x71910000,
  1131. .nvram_machine_id = 0x80,
  1132. .machine_id = ss4_id,
  1133. .iommu_version = 0x05000000,
  1134. .max_mem = 0x10000000,
  1135. },
  1136. /* SPARCClassic */
  1137. {
  1138. .iommu_base = 0x10000000,
  1139. .tcx_base = 0x50000000,
  1140. .slavio_base = 0x70000000,
  1141. .ms_kb_base = 0x71000000,
  1142. .serial_base = 0x71100000,
  1143. .nvram_base = 0x71200000,
  1144. .fd_base = 0x71400000,
  1145. .counter_base = 0x71d00000,
  1146. .intctl_base = 0x71e00000,
  1147. .idreg_base = 0x78000000,
  1148. .dma_base = 0x78400000,
  1149. .esp_base = 0x78800000,
  1150. .le_base = 0x78c00000,
  1151. .apc_base = 0x6a000000,
  1152. .aux1_base = 0x71900000,
  1153. .aux2_base = 0x71910000,
  1154. .nvram_machine_id = 0x80,
  1155. .machine_id = scls_id,
  1156. .iommu_version = 0x05000000,
  1157. .max_mem = 0x10000000,
  1158. },
  1159. /* SPARCbook */
  1160. {
  1161. .iommu_base = 0x10000000,
  1162. .tcx_base = 0x50000000, // XXX
  1163. .slavio_base = 0x70000000,
  1164. .ms_kb_base = 0x71000000,
  1165. .serial_base = 0x71100000,
  1166. .nvram_base = 0x71200000,
  1167. .fd_base = 0x71400000,
  1168. .counter_base = 0x71d00000,
  1169. .intctl_base = 0x71e00000,
  1170. .idreg_base = 0x78000000,
  1171. .dma_base = 0x78400000,
  1172. .esp_base = 0x78800000,
  1173. .le_base = 0x78c00000,
  1174. .apc_base = 0x6a000000,
  1175. .aux1_base = 0x71900000,
  1176. .aux2_base = 0x71910000,
  1177. .nvram_machine_id = 0x80,
  1178. .machine_id = sbook_id,
  1179. .iommu_version = 0x05000000,
  1180. .max_mem = 0x10000000,
  1181. },
  1182. };
  1183. /* SPARCstation 5 hardware initialisation */
  1184. static void ss5_init(MachineState *machine)
  1185. {
  1186. sun4m_hw_init(&sun4m_hwdefs[0], machine);
  1187. }
  1188. /* SPARCstation 10 hardware initialisation */
  1189. static void ss10_init(MachineState *machine)
  1190. {
  1191. sun4m_hw_init(&sun4m_hwdefs[1], machine);
  1192. }
  1193. /* SPARCserver 600MP hardware initialisation */
  1194. static void ss600mp_init(MachineState *machine)
  1195. {
  1196. sun4m_hw_init(&sun4m_hwdefs[2], machine);
  1197. }
  1198. /* SPARCstation 20 hardware initialisation */
  1199. static void ss20_init(MachineState *machine)
  1200. {
  1201. sun4m_hw_init(&sun4m_hwdefs[3], machine);
  1202. }
  1203. /* SPARCstation Voyager hardware initialisation */
  1204. static void vger_init(MachineState *machine)
  1205. {
  1206. sun4m_hw_init(&sun4m_hwdefs[4], machine);
  1207. }
  1208. /* SPARCstation LX hardware initialisation */
  1209. static void ss_lx_init(MachineState *machine)
  1210. {
  1211. sun4m_hw_init(&sun4m_hwdefs[5], machine);
  1212. }
  1213. /* SPARCstation 4 hardware initialisation */
  1214. static void ss4_init(MachineState *machine)
  1215. {
  1216. sun4m_hw_init(&sun4m_hwdefs[6], machine);
  1217. }
  1218. /* SPARCClassic hardware initialisation */
  1219. static void scls_init(MachineState *machine)
  1220. {
  1221. sun4m_hw_init(&sun4m_hwdefs[7], machine);
  1222. }
  1223. /* SPARCbook hardware initialisation */
  1224. static void sbook_init(MachineState *machine)
  1225. {
  1226. sun4m_hw_init(&sun4m_hwdefs[8], machine);
  1227. }
  1228. static void ss5_class_init(ObjectClass *oc, void *data)
  1229. {
  1230. MachineClass *mc = MACHINE_CLASS(oc);
  1231. mc->desc = "Sun4m platform, SPARCstation 5";
  1232. mc->init = ss5_init;
  1233. mc->block_default_type = IF_SCSI;
  1234. mc->is_default = true;
  1235. mc->default_boot_order = "c";
  1236. mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
  1237. mc->default_display = "tcx";
  1238. mc->default_ram_id = "sun4m.ram";
  1239. }
  1240. static const TypeInfo ss5_type = {
  1241. .name = MACHINE_TYPE_NAME("SS-5"),
  1242. .parent = TYPE_MACHINE,
  1243. .class_init = ss5_class_init,
  1244. };
  1245. static void ss10_class_init(ObjectClass *oc, void *data)
  1246. {
  1247. MachineClass *mc = MACHINE_CLASS(oc);
  1248. mc->desc = "Sun4m platform, SPARCstation 10";
  1249. mc->init = ss10_init;
  1250. mc->block_default_type = IF_SCSI;
  1251. mc->max_cpus = 4;
  1252. mc->default_boot_order = "c";
  1253. mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
  1254. mc->default_display = "tcx";
  1255. mc->default_ram_id = "sun4m.ram";
  1256. }
  1257. static const TypeInfo ss10_type = {
  1258. .name = MACHINE_TYPE_NAME("SS-10"),
  1259. .parent = TYPE_MACHINE,
  1260. .class_init = ss10_class_init,
  1261. };
  1262. static void ss600mp_class_init(ObjectClass *oc, void *data)
  1263. {
  1264. MachineClass *mc = MACHINE_CLASS(oc);
  1265. mc->desc = "Sun4m platform, SPARCserver 600MP";
  1266. mc->init = ss600mp_init;
  1267. mc->block_default_type = IF_SCSI;
  1268. mc->max_cpus = 4;
  1269. mc->default_boot_order = "c";
  1270. mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
  1271. mc->default_display = "tcx";
  1272. mc->default_ram_id = "sun4m.ram";
  1273. }
  1274. static const TypeInfo ss600mp_type = {
  1275. .name = MACHINE_TYPE_NAME("SS-600MP"),
  1276. .parent = TYPE_MACHINE,
  1277. .class_init = ss600mp_class_init,
  1278. };
  1279. static void ss20_class_init(ObjectClass *oc, void *data)
  1280. {
  1281. MachineClass *mc = MACHINE_CLASS(oc);
  1282. mc->desc = "Sun4m platform, SPARCstation 20";
  1283. mc->init = ss20_init;
  1284. mc->block_default_type = IF_SCSI;
  1285. mc->max_cpus = 4;
  1286. mc->default_boot_order = "c";
  1287. mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-SuperSparc-II");
  1288. mc->default_display = "tcx";
  1289. mc->default_ram_id = "sun4m.ram";
  1290. }
  1291. static const TypeInfo ss20_type = {
  1292. .name = MACHINE_TYPE_NAME("SS-20"),
  1293. .parent = TYPE_MACHINE,
  1294. .class_init = ss20_class_init,
  1295. };
  1296. static void voyager_class_init(ObjectClass *oc, void *data)
  1297. {
  1298. MachineClass *mc = MACHINE_CLASS(oc);
  1299. mc->desc = "Sun4m platform, SPARCstation Voyager";
  1300. mc->init = vger_init;
  1301. mc->block_default_type = IF_SCSI;
  1302. mc->default_boot_order = "c";
  1303. mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
  1304. mc->default_display = "tcx";
  1305. mc->default_ram_id = "sun4m.ram";
  1306. }
  1307. static const TypeInfo voyager_type = {
  1308. .name = MACHINE_TYPE_NAME("Voyager"),
  1309. .parent = TYPE_MACHINE,
  1310. .class_init = voyager_class_init,
  1311. };
  1312. static void ss_lx_class_init(ObjectClass *oc, void *data)
  1313. {
  1314. MachineClass *mc = MACHINE_CLASS(oc);
  1315. mc->desc = "Sun4m platform, SPARCstation LX";
  1316. mc->init = ss_lx_init;
  1317. mc->block_default_type = IF_SCSI;
  1318. mc->default_boot_order = "c";
  1319. mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
  1320. mc->default_display = "tcx";
  1321. mc->default_ram_id = "sun4m.ram";
  1322. }
  1323. static const TypeInfo ss_lx_type = {
  1324. .name = MACHINE_TYPE_NAME("LX"),
  1325. .parent = TYPE_MACHINE,
  1326. .class_init = ss_lx_class_init,
  1327. };
  1328. static void ss4_class_init(ObjectClass *oc, void *data)
  1329. {
  1330. MachineClass *mc = MACHINE_CLASS(oc);
  1331. mc->desc = "Sun4m platform, SPARCstation 4";
  1332. mc->init = ss4_init;
  1333. mc->block_default_type = IF_SCSI;
  1334. mc->default_boot_order = "c";
  1335. mc->default_cpu_type = SPARC_CPU_TYPE_NAME("Fujitsu-MB86904");
  1336. mc->default_display = "tcx";
  1337. mc->default_ram_id = "sun4m.ram";
  1338. }
  1339. static const TypeInfo ss4_type = {
  1340. .name = MACHINE_TYPE_NAME("SS-4"),
  1341. .parent = TYPE_MACHINE,
  1342. .class_init = ss4_class_init,
  1343. };
  1344. static void scls_class_init(ObjectClass *oc, void *data)
  1345. {
  1346. MachineClass *mc = MACHINE_CLASS(oc);
  1347. mc->desc = "Sun4m platform, SPARCClassic";
  1348. mc->init = scls_init;
  1349. mc->block_default_type = IF_SCSI;
  1350. mc->default_boot_order = "c";
  1351. mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
  1352. mc->default_display = "tcx";
  1353. mc->default_ram_id = "sun4m.ram";
  1354. }
  1355. static const TypeInfo scls_type = {
  1356. .name = MACHINE_TYPE_NAME("SPARCClassic"),
  1357. .parent = TYPE_MACHINE,
  1358. .class_init = scls_class_init,
  1359. };
  1360. static void sbook_class_init(ObjectClass *oc, void *data)
  1361. {
  1362. MachineClass *mc = MACHINE_CLASS(oc);
  1363. mc->desc = "Sun4m platform, SPARCbook";
  1364. mc->init = sbook_init;
  1365. mc->block_default_type = IF_SCSI;
  1366. mc->default_boot_order = "c";
  1367. mc->default_cpu_type = SPARC_CPU_TYPE_NAME("TI-MicroSparc-I");
  1368. mc->default_display = "tcx";
  1369. mc->default_ram_id = "sun4m.ram";
  1370. }
  1371. static const TypeInfo sbook_type = {
  1372. .name = MACHINE_TYPE_NAME("SPARCbook"),
  1373. .parent = TYPE_MACHINE,
  1374. .class_init = sbook_class_init,
  1375. };
  1376. static void sun4m_register_types(void)
  1377. {
  1378. type_register_static(&idreg_info);
  1379. type_register_static(&afx_info);
  1380. type_register_static(&prom_info);
  1381. type_register_static(&ram_info);
  1382. type_register_static(&ss5_type);
  1383. type_register_static(&ss10_type);
  1384. type_register_static(&ss600mp_type);
  1385. type_register_static(&ss20_type);
  1386. type_register_static(&voyager_type);
  1387. type_register_static(&ss_lx_type);
  1388. type_register_static(&ss4_type);
  1389. type_register_static(&scls_type);
  1390. type_register_static(&sbook_type);
  1391. }
  1392. type_init(sun4m_register_types)