2
0

sun4m.c 58 KB

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