Skip to contentSkip to conversation

leon support - first proposal

PATCH Stefan Holst 1 participant 1 message Apr 3, 2004 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

hello!

thanks for merging my patches. just tested rc3 and it works fine here :)

here is now a first proposal for actual leon support. it has now a very low impact on existing code (mostly adding some id's and a few branches for leon).

currently the kernel has to be explicitely configured for leon architecture (like sun4). this has two reasons:

- gaisler research has received its official implementors id (0xf) quite recently and this id is still undefined in latest leon release

- there is an asi code which differs from srmmu and currently redefined in asi.h

actually there are some more nonstandard asi codes in leon but these aren't used very often or not at all. ASI_M_MMUREGS however seems to be used a lot and much code has to be added to circumvent this redefinition.

if this asi.h change is a showstopper, however, i'll try to remove it.

what do you think anout this patch? are there any issues left which need to be fixed?

drivers/sbus/sbus.c +2 -0
diff -urN a/drivers/sbus/sbus.c b/drivers/sbus/sbus.c
@@ -354,6 +354,8 @@
 		   (nd = prom_searchsiblings(nd, "sbi")) = 0) {
 		   	panic("sbi not found");
 		}
+	} else if(sparc_cpu_model = sparc_leon) {
+		return 0;
 	} else if((nd = prom_searchsiblings(topnd, "sbus")) = 0) {
 		if((iommund = prom_searchsiblings(topnd, "iommu")) = 0 ||
 		   (nd = prom_getchild(iommund)) = 0 ||
include/asm-sparc/asi.h +6 -0
diff -urN a/include/asm-sparc/asi.h b/include/asm-sparc/asi.h
@@ -108,4 +108,10 @@
 
 #define ASI_M_ACTION       0x4c   /* Breakpoint Action Register (GNU/Viking) */
 
+/* FIXME: non-standard Leon ASI definition */
+#ifdef CONFIG_LEON
+#undef ASI_M_MMUREGS
+#define ASI_M_MMUREGS		0x19
+#endif /* CONFIG_LEON */
+
 #endif /* _SPARC_ASI_H */
include/asm-sparc/machines.h +5 -1
diff -urN a/include/asm-sparc/machines.h b/include/asm-sparc/machines.h
@@ -15,7 +15,7 @@
 /* Current number of machines we know about that has an IDPROM
  * machtype entry including one entry for the 0x80 OBP machines.
  */
-#define NUM_SUN_MACHINES   15
+#define NUM_SUN_MACHINES   16
 
 extern struct Sun_Machine_Models Sun_Machines[NUM_SUN_MACHINES];
 
@@ -32,6 +32,7 @@
 
 #define SM_ARCH_MASK  0xf0
 #define SM_SUN4       0x20
+#define  M_LEON2      0x30
 #define SM_SUN4C      0x50
 #define SM_SUN4M      0x70
 #define SM_SUN4M_OBP  0x80
@@ -43,6 +44,9 @@
 #define SM_4_330      0x03    /* Sun 4/300 series */
 #define SM_4_470      0x04    /* Sun 4/400 series */
 
+/* Leon machines */
+#define M_LEON2_SOC   0x01    /* Leon2 SoC */
+
 /* Sun4c machines                Full Name              - PROM NAME */
 #define SM_4C_SS1     0x01    /* Sun4c SparcStation 1   - Sun 4/60  */
 #define SM_4C_IPC     0x02    /* Sun4c SparcStation IPC - Sun 4/40  */
include/asm-sparc/system.h +1 -0
diff -urN a/include/asm-sparc/system.h b/include/asm-sparc/system.h
@@ -29,6 +29,7 @@
   sun4u       = 0x05, /* V8 ploos ploos */
   sun_unknown = 0x06,
   ap1000      = 0x07, /* almost a sun4m */
+  sparc_leon  = 0x08, /* Leon2 SoC */
 };
 
 /* Really, userland should not be looking at any of this... */
arch/sparc/Kconfig +8 -0
diff -urN a/arch/sparc/Kconfig b/arch/sparc/Kconfig
@@ -226,6 +226,14 @@
 	  a kernel compiled with this option will run only on sun4.
 	  (And the current version will probably work only on sun4/330.)
 
+config LEON
+	bool "Running on SoC 'Leon', the open source sparc VHDL model"
+	help
+	  Say Y here if you want to run linux on the Leon System-on-a-Chip
+	  platform. For information go to www.gaisler.com. Download the VHDL 
+	  source and use the instruction level Leon sparc-simulator "tsim" which 
+	  is free for private use. 
+
 if !SUN4
 
 config PCI
arch/sparc/kernel/Makefile +1 -1
diff -urN a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
@@ -6,7 +6,7 @@
 
 EXTRA_AFLAGS	:= -ansi
 
-IRQ_OBJS := irq.o sun4m_irq.o sun4c_irq.o sun4d_irq.o
+IRQ_OBJS := irq.o sun4m_irq.o sun4c_irq.o sun4d_irq.o leon_irq.o
 obj-y    := entry.o wof.o wuf.o etrap.o rtrap.o traps.o $(IRQ_OBJS) \
 	    process.o signal.o ioport.o setup.o idprom.o \
 	    sys_sparc.o sunos_asm.o systbls.o \
arch/sparc/kernel/auxio.c +1 -0
diff -urN a/arch/sparc/kernel/auxio.c b/arch/sparc/kernel/auxio.c
@@ -29,6 +29,7 @@
 	switch (sparc_cpu_model) {
 	case sun4d:
 	case sun4:
+	case sparc_leon:
 		return;
 	default:
 		break;
arch/sparc/kernel/cpu.c +11 -2
diff -urN a/arch/sparc/kernel/cpu.c b/arch/sparc/kernel/cpu.c
@@ -73,6 +73,9 @@
   { 5, 6, "reserved"},
   { 5, 7, "No FPU"},
   { 9, 3, "Fujitsu or Weitek on-chip FPU"},
+  /* Leon */
+  { 0xf, 0, "Meiko FPU"},
+  { 0xf, 1, "GRFPU"},
 };
 
 #define NSPARCFPU  (sizeof(linux_sparc_fpu)/sizeof(struct cpu_fp_info))
@@ -117,7 +120,9 @@
   { 0xc, 0, "UNKNOWN CPU-VENDOR/TYPE"},
   { 0xd, 0, "UNKNOWN CPU-VENDOR/TYPE"},
   { 0xe, 0, "UNKNOWN CPU-VENDOR/TYPE"},
-  { 0xf, 0, "UNKNOWN CPU-VENDOR/TYPE"},
+  /* Leon */
+  { 0xf, 2, "Gaisler Research - Leon2 SoC"},
+  { 0xf, 3, "Gaisler Research - Leon3 SoC"},
 };
 
 #define NSPARCCHIPS  (sizeof(linux_sparc_chips)/sizeof(struct cpu_iu_info))
@@ -134,10 +139,14 @@
 
 	psr_impl = ((get_psr()>>28)&0xf);
 	psr_vers = ((get_psr()>>24)&0xf);
+#ifdef CONFIG_LEON
+	psr_impl = 0xf;	/* hardcoded ids for older models/simulators */
+	psr_vers = 2;
+#endif
 
 	psr = get_psr();
 	put_psr(psr | PSR_EF);
-	fpu_vers = ((get_fsr()>>17)&0x7);
+	fpu_vers = (get_psr() & PSR_EF) ? ((get_fsr()>>17)&0x7) : 7;
 	put_psr(psr);
 
 	for(i = 0; i<NSPARCCHIPS; i++) {
arch/sparc/kernel/head.S +4 -0
diff -urN a/arch/sparc/kernel/head.S b/arch/sparc/kernel/head.S
@@ -838,6 +838,8 @@
 
 		cmp	%l1, ' '
 		be	1f
+		 cmp	%l1, '2'		! leon2 or compatible
+		be	1f
 		 cmp	%l1, 'c'
 		be	1f
 		 cmp	%l1, 'm'
@@ -860,6 +862,8 @@
 		be	sun4m_init
 		 cmp	%l1, 'd'		! Let us see how the beast will die
 		be	sun4d_init
+		 cmp	%l1, '2'		! leon2 or compatible
+		be	sun4c_continue_boot
 		 nop
 
 		/* Jump into mmu context zero. */
arch/sparc/kernel/idprom.c +2 -0
diff -urN a/arch/sparc/kernel/idprom.c b/arch/sparc/kernel/idprom.c
@@ -31,6 +31,8 @@
 { "Sun 4/200 Series", (SM_SUN4 | SM_4_260) },
 { "Sun 4/300 Series", (SM_SUN4 | SM_4_330) },
 { "Sun 4/400 Series", (SM_SUN4 | SM_4_470) },
+/* Now Leon */
+{ "Leon2 System-on-a-Chip", (M_LEON2 | M_LEON2_SOC) },
 /* Now, Sun4c's */
 { "Sun4c SparcStation 1", (SM_SUN4C | SM_4C_SS1) },
 { "Sun4c SparcStation IPC", (SM_SUN4C | SM_4C_IPC) },
arch/sparc/kernel/irq.c +5 -0
diff -urN a/arch/sparc/kernel/irq.c b/arch/sparc/kernel/irq.c
@@ -579,6 +579,7 @@
 	extern void sun4c_init_IRQ( void );
 	extern void sun4m_init_IRQ( void );
 	extern void sun4d_init_IRQ( void );
+	extern void leon_init_IRQ(void);
 
 	switch(sparc_cpu_model) {
 	case sun4c:
@@ -586,6 +587,10 @@
 		sun4c_init_IRQ();
 		break;
 
+	case sparc_leon:
+		leon_init_IRQ();
+		break;
+
 	case sun4m:
 #ifdef CONFIG_PCI
 		pcic_probe();
arch/sparc/kernel/setup.c +11 -0
diff -urN a/arch/sparc/kernel/setup.c b/arch/sparc/kernel/setup.c
@@ -274,6 +274,7 @@
 	if(!strcmp(&cputypval,"sun4d")) { sparc_cpu_model=sun4d; }
 	if(!strcmp(&cputypval,"sun4e")) { sparc_cpu_model=sun4e; }
 	if(!strcmp(&cputypval,"sun4u")) { sparc_cpu_model=sun4u; }
+	if(!strcmp(&cputypval,"leon2")) { sparc_cpu_model=sparc_leon; }
 
 #ifdef CONFIG_SUN4
 	if (sparc_cpu_model != sun4) {
@@ -281,6 +282,13 @@
 		prom_halt();
 	}
 #endif
+#ifdef CONFIG_LEON
+	/* FIXME: psr ids, asi codes */
+	if (sparc_cpu_model != sparc_leon) {
+		prom_printf("This kernel is for Leon architecture only.\n");
+		prom_halt();
+	}
+#endif
 	printk("ARCH: ");
 	switch(sparc_cpu_model) {
 	case sun4:
@@ -301,6 +309,9 @@
 	case sun4u:
 		printk("SUN4U\n");
 		break;
+	case sparc_leon:
+		printk("LEON\n");
+		break;
 	default:
 		printk("UNKNOWN!\n");
 		break;
arch/sparc/kernel/time.c +13 -0
diff -urN a/arch/sparc/kernel/time.c b/arch/sparc/kernel/time.c
@@ -43,6 +43,7 @@
 #include <asm/sun4paddr.h>
 #include <asm/page.h>
 #include <asm/pcic.h>
+#include <asm/leon.h>
 
 extern unsigned long wall_jiffies;
 
@@ -309,6 +310,9 @@
 	case sun4d:
 		node = prom_getchild(bootbus = prom_searchsiblings(prom_getchild(cpuunit = prom_searchsiblings(node, "cpu-unit")), "bootbus"));
 		break;
+	case sparc_leon:
+		node = 0;
+		return;
 	default:
 		prom_printf("CLOCK: Unsupported architecture!\n");
 		prom_halt();
@@ -393,6 +397,11 @@
 		clock_probe();
 
 	sparc_init_timers(timer_interrupt);
+
+	if (sparc_cpu_model = sparc_leon) {
+		local_irq_enable();
+		return;
+	}
 	
 #ifdef CONFIG_SUN4
 	if(idprom->id_machtype = (SM_SUN4 | SM_4_330)) {
@@ -469,6 +478,10 @@
 
 extern __inline__ unsigned long do_gettimeoffset(void)
 {
+	if (sparc_cpu_model = sparc_leon)
+		return ((LEON_REGLOAD_PA(LEON_TRLD0)&LEON_TCNT0_MASK) - 
+			(LEON_REGLOAD_PA(LEON_TCNT0)&LEON_TCNT0_MASK)) >> 2;
+
 	return (*master_l10_counter >> 10) & 0x1fffff;
 }
 
arch/sparc/mm/Makefile +4 -0
diff -urN a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
@@ -21,3 +21,7 @@
 else
 obj-y   += sun4c.o
 endif
+
+ifdef CONFIG_LEON
+obj-y   += leon.o
+endif
arch/sparc/mm/init.c +2 -0
diff -urN a/arch/sparc/mm/init.c b/arch/sparc/mm/init.c
@@ -32,6 +32,7 @@
 #include <asm/vaddrs.h>
 #include <asm/pgalloc.h>	/* bug in asm-generic/tlb.h: check_pgt_cache */
 #include <asm/tlb.h>
+#include <asm/leon.h>
 
 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
 
@@ -324,6 +325,7 @@
 		break;
 	case sun4m:
 	case sun4d:
+	case sparc_leon:
 		srmmu_paging_init();
 		sparc_unmapped_base = 0x50000000;
 		BTFIXUPSET_SETHI(sparc_unmapped_base, 0x50000000);
arch/sparc/mm/loadmmu.c +1 -0
diff -urN a/arch/sparc/mm/loadmmu.c b/arch/sparc/mm/loadmmu.c
@@ -36,6 +36,7 @@
 		break;
 	case sun4m:
 	case sun4d:
+	case sparc_leon:
 		ld_mmu_srmmu();
 		break;
 	default:
arch/sparc/mm/srmmu.c +135 -4

165 lines not on this page · raw message

include/asm-sparc/leon.h +217 -0

217 lines not on this page · raw message

arch/sparc/kernel/leon_irq.c +164 -0

164 lines not on this page · raw message

arch/sparc/mm/leon.c +99 -0

99 lines not on this page · raw message

Signature · 4 lines
RY  Stefan
+-----------------+----------------+
| [email protected] | www.s-holst.de |
+-----------------+----------------+