1/*
2 *  linux/arch/m68k/sun3/config.c
3 *
4 *  Copyright (C) 1996,1997 Pekka Pietik{inen
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License.  See the file COPYING in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/config.h>
12#include <linux/types.h>
13#include <linux/kernel.h>
14#include <linux/mm.h>
15#include <linux/tty.h>
16#include <linux/console.h>
17#include <linux/init.h>
18#include <linux/bootmem.h>
19
20#include <asm/oplib.h>
21#include <asm/setup.h>
22#include <asm/contregs.h>
23#include <asm/movs.h>
24#include <asm/pgtable.h>
25#include <asm/sun3-head.h>
26#include <asm/sun3mmu.h>
27#include <asm/rtc.h>
28#include <asm/machdep.h>
29#include <asm/intersil.h>
30#include <asm/irq.h>
31#include <asm/segment.h>
32#include <asm/sun3ints.h>
33
34extern char _text, _end;
35
36char sun3_reserved_pmeg[SUN3_PMEGS_NUM];
37
38extern unsigned long sun3_gettimeoffset(void);
39extern int sun3_get_irq_list (char *);
40extern void sun3_sched_init(void (*handler)(int, void *, struct pt_regs *));
41extern void sun3_get_model (char* model);
42extern void idprom_init (void);
43extern void sun3_gettod (int *yearp, int *monp, int *dayp,
44                   int *hourp, int *minp, int *secp);
45extern int sun3_hwclk(int set, struct rtc_time *t);
46
47extern void sun_serial_setup(void);
48volatile char* clock_va;
49extern volatile unsigned char* sun3_intreg;
50extern unsigned long availmem;
51unsigned long num_pages;
52
53void __init sun3_init(void)
54{
55	unsigned char enable_register;
56	int i;
57
58	m68k_machtype= MACH_SUN3;
59	m68k_cputype = CPU_68020;
60	m68k_fputype = FPU_68881; /* mc68881 actually */
61	m68k_mmutype = MMU_SUN3;
62	clock_va    =          (char *) 0xfe06000;	/* dark  */
63	sun3_intreg = (unsigned char *) 0xfe0a000;	/* magic */
64	sun3_disable_interrupts();
65
66	prom_init((void *)LINUX_OPPROM_BEGVM);
67
68	GET_CONTROL_BYTE(AC_SENABLE,enable_register);
69	enable_register |= 0x50; /* Enable FPU */
70	SET_CONTROL_BYTE(AC_SENABLE,enable_register);
71	GET_CONTROL_BYTE(AC_SENABLE,enable_register);
72
73	/* This code looks suspicious, because it doesn't subtract
74           memory belonging to the kernel from the available space */
75
76
77	memset(sun3_reserved_pmeg, 0, sizeof(sun3_reserved_pmeg));
78
79	/* Reserve important PMEGS */
80
81	for (i=0; i<8; i++)		/* Kernel PMEGs */
82		sun3_reserved_pmeg[i] = 1;
83
84	sun3_reserved_pmeg[247] = 1;	/* ROM mapping  */
85	sun3_reserved_pmeg[248] = 1;	/* AMD Ethernet */
86	sun3_reserved_pmeg[251] = 1;	/* VB area      */
87	sun3_reserved_pmeg[254] = 1;	/* main I/O     */
88
89	sun3_reserved_pmeg[249] = 1;
90	sun3_reserved_pmeg[252] = 1;
91	sun3_reserved_pmeg[253] = 1;
92	set_fs(KERNEL_DS);
93}
94
95/* Without this, Bad Things happen when something calls arch_reset. */
96static void sun3_reboot (void)
97{
98	prom_reboot ("vmlinux");
99}
100
101static void sun3_halt (void)
102{
103	prom_halt ();
104}
105
106/* sun3 bootmem allocation */
107
108void __init sun3_bootmem_alloc(unsigned long memory_start, unsigned long memory_end)
109{
110	unsigned long start_page;
111
112	/* align start/end to page boundries */
113	memory_start = ((memory_start + (PAGE_SIZE-1)) & PAGE_MASK);
114	memory_end = memory_end & PAGE_MASK;
115
116	start_page = __pa(memory_start) >> PAGE_SHIFT;
117	num_pages = __pa(memory_end) >> PAGE_SHIFT;
118
119	high_memory = (void *)memory_end;
120	availmem = memory_start;
121
122	availmem += init_bootmem(start_page, num_pages);
123	availmem = (availmem + (PAGE_SIZE-1)) & PAGE_MASK;
124
125	free_bootmem(__pa(availmem), memory_end - (availmem));
126}
127
128
129void __init config_sun3(void)
130{
131	unsigned long memory_start, memory_end;
132
133	printk("ARCH: SUN3\n");
134	idprom_init();
135
136	/* Subtract kernel memory from available memory */
137
138        mach_sched_init      =  sun3_sched_init;
139        mach_init_IRQ        =  sun3_init_IRQ;
140        mach_default_handler = &sun3_default_handler;
141        mach_request_irq     =  sun3_request_irq;
142        mach_free_irq        =  sun3_free_irq;
143#ifdef CONFIG_VT
144//	mach_keyb_init       =  sun3_keyb_init;
145#endif
146	enable_irq     	     =  sun3_enable_irq;
147        disable_irq  	     =  sun3_disable_irq;
148	mach_process_int     =  sun3_process_int;
149        mach_get_irq_list    =  sun3_get_irq_list;
150        mach_gettod          =  sun3_gettod;
151        mach_reset           =  sun3_reboot;
152	mach_gettimeoffset   =  sun3_gettimeoffset;
153	mach_get_model	     =  sun3_get_model;
154	mach_hwclk           =  sun3_hwclk;
155	mach_halt	     =  sun3_halt;
156#if !defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_DUMMY_CONSOLE)
157	conswitchp 	     = &dummy_con;
158#endif
159
160	memory_start = ((((int)&_end) + 0x2000) & ~0x1fff);
161// PROM seems to want the last couple of physical pages. --m
162	memory_end   = *(romvec->pv_sun3mem) + PAGE_OFFSET - 2*PAGE_SIZE;
163
164	m68k_num_memory=1;
165        m68k_memory[0].size=*(romvec->pv_sun3mem);
166
167	sun3_bootmem_alloc(memory_start, memory_end);
168
169#ifdef CONFIG_SUN3X_ZS
170	sun_serial_setup();
171#endif
172}
173
174void __init sun3_sched_init(void (*timer_routine)(int, void *, struct pt_regs *))
175{
176	sun3_disable_interrupts();
177        intersil_clock->cmd_reg=(INTERSIL_RUN|INTERSIL_INT_DISABLE|INTERSIL_24H_MODE);
178        intersil_clock->int_reg=INTERSIL_HZ_100_MASK;
179 	intersil_clear();
180        sun3_enable_irq(5);
181        intersil_clock->cmd_reg=(INTERSIL_RUN|INTERSIL_INT_ENABLE|INTERSIL_24H_MODE);
182        sun3_enable_interrupts();
183        intersil_clear();
184}
185
186