aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/jazz
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/mips/jazz
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/mips/jazz')
-rw-r--r--arch/mips/jazz/Makefile7
-rw-r--r--arch/mips/jazz/int-handler.S282
-rw-r--r--arch/mips/jazz/io.c135
-rw-r--r--arch/mips/jazz/irq.c100
-rw-r--r--arch/mips/jazz/jazzdma.c565
-rw-r--r--arch/mips/jazz/reset.c69
-rw-r--r--arch/mips/jazz/setup.c101
7 files changed, 1259 insertions, 0 deletions
diff --git a/arch/mips/jazz/Makefile b/arch/mips/jazz/Makefile
new file mode 100644
index 000000000000..85749246a671
--- /dev/null
+++ b/arch/mips/jazz/Makefile
@@ -0,0 +1,7 @@
1#
2# Makefile for the Jazz family specific parts of the kernel
3#
4
5obj-y := int-handler.o irq.o jazzdma.o reset.o setup.o
6
7EXTRA_AFLAGS := $(CFLAGS)
diff --git a/arch/mips/jazz/int-handler.S b/arch/mips/jazz/int-handler.S
new file mode 100644
index 000000000000..4dbcf91db884
--- /dev/null
+++ b/arch/mips/jazz/int-handler.S
@@ -0,0 +1,282 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1995, 1996, 1997, 1998 by Ralf Baechle and Andreas Busse
7 *
8 * Jazz family specific interrupt stuff
9 *
10 * To do: On Jazz machines we remap some non-ISA interrupts to ISA
11 * interrupts. These interrupts should use their own vectors.
12 * Squeeze the last cycles out of the handlers. Only a dead
13 * cycle is a good cycle.
14 */
15#include <asm/asm.h>
16#include <asm/mipsregs.h>
17#include <asm/jazz.h>
18#include <asm/regdef.h>
19#include <asm/stackframe.h>
20
21/*
22 * jazz_handle_int: Interrupt handler for the ACER Pica-61 boards
23 */
24 .set noreorder
25
26 NESTED(jazz_handle_int, PT_SIZE, ra)
27 .set noat
28 SAVE_ALL
29 CLI
30 .set at
31
32 /*
33 * Get pending interrupts
34 */
35 mfc0 t0,CP0_CAUSE # get pending interrupts
36 mfc0 t1,CP0_STATUS # get enabled interrupts
37 and t0,t1 # isolate allowed ones
38 andi t0,0xff00 # isolate pending bits
39 beqz t0,3f
40 sll t0,16 # delay slot
41
42 /*
43 * Find irq with highest priority
44 * FIXME: This is slow - use binary search
45 */
46 la t1,ll_vectors
471: bltz t0,2f # found pending irq
48 sll t0,1
49 b 1b
50 subu t1,PTRSIZE # delay slot
51
52 /*
53 * Do the low-level stuff
54 */
552: lw t0,(t1)
56 jr t0
57 nop # delay slot
58 END(jazz_handle_int)
59
60ll_sw0: li s1,~IE_SW0
61 mfc0 t0,CP0_CAUSE
62 and t0,s1
63 mtc0 t0,CP0_CAUSE
64 PANIC("Unimplemented sw0 handler")
65
66ll_sw1: li s1,~IE_SW1
67 mfc0 t0,CP0_CAUSE
68 and t0,s1
69 mtc0 t0,CP0_CAUSE
70 PANIC("Unimplemented sw1 handler")
71
72ll_local_dma: li s1,~IE_IRQ0
73 PANIC("Unimplemented local_dma handler")
74
75ll_local_dev: lbu t0,JAZZ_IO_IRQ_SOURCE
76#if PTRSIZE == 8 /* True 64 bit kernel */
77 dsll t0,1
78#endif
79 .set reorder
80 LONG_L t0,local_vector(t0)
81 jr t0
82 .set noreorder
83
84/*
85 * The braindead PICA hardware gives us no way to distinguish if we really
86 * received interrupt 7 from the (E)ISA bus or if we just received an
87 * interrupt with no findable cause. This sometimes happens with braindead
88 * cards. Oh well - for all the Jazz boxes slots are more or less just
89 * whistles and bells and we're aware of the problem.
90 */
91ll_isa_irq: lw a0, JAZZ_EISA_IRQ_ACK
92
93 jal do_IRQ
94 move a1,sp
95
96 j ret_from_irq
97 nop
98
99/*
100 * Hmm... This is not just a plain PC clone so the question is
101 * which devices on Jazz machines can generate an (E)ISA NMI?
102 * (Writing to nonexistent memory?)
103 */
104ll_isa_nmi: li s1,~IE_IRQ3
105 PANIC("Unimplemented isa_nmi handler")
106
107/*
108 * Timer IRQ - remapped to be more similar to an IBM compatible.
109 *
110 * The timer interrupt is handled specially to ensure that the jiffies
111 * variable is updated at all times. Specifically, the timer interrupt is
112 * just like the complete handlers except that it is invoked with interrupts
113 * disabled and should never re-enable them. If other interrupts were
114 * allowed to be processed while the timer interrupt is active, then the
115 * other interrupts would have to avoid using the jiffies variable for delay
116 * and interval timing operations to avoid hanging the system.
117 */
118ll_timer: lw zero,JAZZ_TIMER_REGISTER # timer irq cleared on read
119 li s1,~IE_IRQ4
120
121 li a0, JAZZ_TIMER_IRQ
122 jal do_IRQ
123 move a1,sp
124
125 mfc0 t0,CP0_STATUS # disable interrupts again
126 ori t0,1
127 xori t0,1
128 mtc0 t0,CP0_STATUS
129
130 j ret_from_irq
131 nop
132
133/*
134 * CPU count/compare IRQ (unused)
135 */
136ll_count: j ret_from_irq
137 mtc0 zero,CP0_COMPARE
138
139#if 0
140/*
141 * Call the handler for the interrupt
142 * (Currently unused)
143 */
144call_real: /*
145 * temporarily disable interrupt
146 */
147 mfc0 t2,CP0_STATUS
148 and t2,s1
149 mtc0 t2,CP0_STATUS
150 nor s1,zero,s1
151 jal do_IRQ
152
153 /*
154 * reenable interrupt
155 */
156 mfc0 t2,CP0_STATUS
157 or t2,s1
158 mtc0 t2,CP0_STATUS
159 j ret_from_irq
160#endif
161
162 .data
163 PTR ll_sw0 # SW0
164 PTR ll_sw1 # SW1
165 PTR ll_local_dma # Local DMA
166 PTR ll_local_dev # Local devices
167 PTR ll_isa_irq # ISA IRQ
168 PTR ll_isa_nmi # ISA NMI
169 PTR ll_timer # Timer
170ll_vectors: PTR ll_count # Count/Compare IRQ
171
172 /*
173 * Interrupt handlers for local devices.
174 */
175 .text
176 .set reorder
177loc_no_irq: PANIC("Unimplemented loc_no_irq handler")
178/*
179 * Parallel port IRQ
180 */
181loc_parallel: li s1,~JAZZ_IE_PARALLEL
182 li a0,JAZZ_PARALLEL_IRQ
183 b loc_call
184
185/*
186 * Floppy IRQ
187 */
188loc_floppy: li s1,~JAZZ_IE_FLOPPY
189 li a0,JAZZ_FLOPPY_IRQ
190 b loc_call
191
192/*
193 * Sound IRQ
194 */
195loc_sound: PANIC("Unimplemented loc_sound handler")
196loc_video: PANIC("Unimplemented loc_video handler")
197
198/*
199 * Ethernet interrupt handler
200 */
201loc_ethernet: li s1,~JAZZ_IE_ETHERNET
202 li a0,JAZZ_ETHERNET_IRQ
203 b loc_call
204
205/*
206 * SCSI interrupt handler
207 */
208loc_scsi: li s1,~JAZZ_IE_SCSI
209 li a0,JAZZ_SCSI_IRQ
210 b loc_call
211
212/*
213 * Keyboard interrupt handler
214 */
215loc_keyboard: li s1,~JAZZ_IE_KEYBOARD
216 li a0,JAZZ_KEYBOARD_IRQ
217 b loc_call
218
219/*
220 * Mouse interrupt handler
221 */
222loc_mouse: li s1,~JAZZ_IE_MOUSE
223 li a0,JAZZ_MOUSE_IRQ
224 b loc_call
225
226/*
227 * Serial port 1 IRQ
228 */
229loc_serial1: li s1,~JAZZ_IE_SERIAL1
230 li a0,JAZZ_SERIAL1_IRQ
231 b loc_call
232
233/*
234 * Serial port 2 IRQ
235 */
236loc_serial2: li s1,~JAZZ_IE_SERIAL2
237 li a0,JAZZ_SERIAL2_IRQ
238 b loc_call
239
240/*
241 * Call the interrupt handler for an interrupt generated by a
242 * local device.
243 */
244loc_call: /*
245 * Temporarily disable interrupt source
246 */
247 lhu t2,JAZZ_IO_IRQ_ENABLE
248 and t2,s1
249 sh t2,JAZZ_IO_IRQ_ENABLE
250
251 nor s1,zero,s1
252 jal do_IRQ
253
254 /*
255 * Reenable interrupt
256 */
257 lhu t2,JAZZ_IO_IRQ_ENABLE
258 or t2,s1
259 sh t2,JAZZ_IO_IRQ_ENABLE
260
261 j ret_from_irq
262
263/*
264 * "Jump extender" to reach spurious_interrupt
265 */
2663: j spurious_interrupt
267
268/*
269 * Vectors for interrupts generated by local devices
270 */
271 .data
272local_vector: PTR loc_no_irq
273 PTR loc_parallel
274 PTR loc_floppy
275 PTR loc_sound
276 PTR loc_video
277 PTR loc_ethernet
278 PTR loc_scsi
279 PTR loc_keyboard
280 PTR loc_mouse
281 PTR loc_serial1
282 PTR loc_serial2
diff --git a/arch/mips/jazz/io.c b/arch/mips/jazz/io.c
new file mode 100644
index 000000000000..e86904454c89
--- /dev/null
+++ b/arch/mips/jazz/io.c
@@ -0,0 +1,135 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Low level I/O functions for Jazz family machines.
7 *
8 * Copyright (C) 1997 by Ralf Baechle.
9 */
10#include <linux/string.h>
11#include <linux/spinlock.h>
12#include <asm/addrspace.h>
13#include <asm/system.h>
14#include <asm/jazz.h>
15
16/*
17 * Map an 16mb segment of the EISA address space to 0xe3000000;
18 */
19static inline void map_eisa_address(unsigned long address)
20{
21 /* XXX */
22 /* We've got an wired entry in the TLB. We just need to modify it.
23 fast and clean. But since we want to get rid of wired entries
24 things are a little bit more complicated ... */
25}
26
27static unsigned char jazz_readb(unsigned long addr)
28{
29 unsigned char res;
30
31 map_eisa_address(addr);
32 addr &= 0xffffff;
33 res = *(volatile unsigned char *) (JAZZ_EISA_BASE + addr);
34
35 return res;
36}
37
38static unsigned short jazz_readw(unsigned long addr)
39{
40 unsigned short res;
41
42 map_eisa_address(addr);
43 addr &= 0xffffff;
44 res = *(volatile unsigned char *) (JAZZ_EISA_BASE + addr);
45
46 return res;
47}
48
49static unsigned int jazz_readl(unsigned long addr)
50{
51 unsigned int res;
52
53 map_eisa_address(addr);
54 addr &= 0xffffff;
55 res = *(volatile unsigned char *) (JAZZ_EISA_BASE + addr);
56
57 return res;
58}
59
60static void jazz_writeb(unsigned char val, unsigned long addr)
61{
62 map_eisa_address(addr);
63 addr &= 0xffffff;
64 *(volatile unsigned char *) (JAZZ_EISA_BASE + addr) = val;
65}
66
67static void jazz_writew(unsigned short val, unsigned long addr)
68{
69 map_eisa_address(addr);
70 addr &= 0xffffff;
71 *(volatile unsigned char *) (JAZZ_EISA_BASE + addr) = val;
72}
73
74static void jazz_writel(unsigned int val, unsigned long addr)
75{
76 map_eisa_address(addr);
77 addr &= 0xffffff;
78 *(volatile unsigned char *) (JAZZ_EISA_BASE + addr) = val;
79}
80
81static void jazz_memset_io(unsigned long addr, int val, unsigned long len)
82{
83 unsigned long waddr;
84
85 waddr = JAZZ_EISA_BASE | (addr & 0xffffff);
86 while(len) {
87 unsigned long fraglen;
88
89 fraglen = (~addr + 1) & 0xffffff;
90 fraglen = (fraglen < len) ? fraglen : len;
91 map_eisa_address(addr);
92 memset((char *)waddr, val, fraglen);
93 addr += fraglen;
94 waddr = waddr + fraglen - 0x1000000;
95 len -= fraglen;
96 }
97}
98
99static void jazz_memcpy_fromio(unsigned long to, unsigned long from, unsigned long len)
100{
101 unsigned long waddr;
102
103 waddr = JAZZ_EISA_BASE | (from & 0xffffff);
104 while(len) {
105 unsigned long fraglen;
106
107 fraglen = (~from + 1) & 0xffffff;
108 fraglen = (fraglen < len) ? fraglen : len;
109 map_eisa_address(from);
110 memcpy((void *)to, (void *)waddr, fraglen);
111 to += fraglen;
112 from += fraglen;
113 waddr = waddr + fraglen - 0x1000000;
114 len -= fraglen;
115 }
116}
117
118static void jazz_memcpy_toio(unsigned long to, unsigned long from, unsigned long len)
119{
120 unsigned long waddr;
121
122 waddr = JAZZ_EISA_BASE | (to & 0xffffff);
123 while(len) {
124 unsigned long fraglen;
125
126 fraglen = (~to + 1) & 0xffffff;
127 fraglen = (fraglen < len) ? fraglen : len;
128 map_eisa_address(to);
129 memcpy((char *)to + JAZZ_EISA_BASE, (void *)from, fraglen);
130 to += fraglen;
131 from += fraglen;
132 waddr = waddr + fraglen - 0x1000000;
133 len -= fraglen;
134 }
135}
diff --git a/arch/mips/jazz/irq.c b/arch/mips/jazz/irq.c
new file mode 100644
index 000000000000..0b608fa98d5a
--- /dev/null
+++ b/arch/mips/jazz/irq.c
@@ -0,0 +1,100 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1992 Linus Torvalds
7 * Copyright (C) 1994 - 2001, 2003 Ralf Baechle
8 */
9#include <linux/init.h>
10#include <linux/interrupt.h>
11#include <linux/kernel.h>
12#include <linux/spinlock.h>
13
14#include <asm/i8259.h>
15#include <asm/io.h>
16#include <asm/jazz.h>
17
18extern asmlinkage void jazz_handle_int(void);
19
20static DEFINE_SPINLOCK(r4030_lock);
21
22static void enable_r4030_irq(unsigned int irq)
23{
24 unsigned int mask = 1 << (irq - JAZZ_PARALLEL_IRQ);
25 unsigned long flags;
26
27 spin_lock_irqsave(&r4030_lock, flags);
28 mask |= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
29 r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
30 spin_unlock_irqrestore(&r4030_lock, flags);
31}
32
33static unsigned int startup_r4030_irq(unsigned int irq)
34{
35 enable_r4030_irq(irq);
36 return 0; /* never anything pending */
37}
38
39#define shutdown_r4030_irq disable_r4030_irq
40
41void disable_r4030_irq(unsigned int irq)
42{
43 unsigned int mask = ~(1 << (irq - JAZZ_PARALLEL_IRQ));
44 unsigned long flags;
45
46 spin_lock_irqsave(&r4030_lock, flags);
47 mask &= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
48 r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
49 spin_unlock_irqrestore(&r4030_lock, flags);
50}
51
52#define mask_and_ack_r4030_irq disable_r4030_irq
53
54static void end_r4030_irq(unsigned int irq)
55{
56 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
57 enable_r4030_irq(irq);
58}
59
60static struct hw_interrupt_type r4030_irq_type = {
61 "R4030",
62 startup_r4030_irq,
63 shutdown_r4030_irq,
64 enable_r4030_irq,
65 disable_r4030_irq,
66 mask_and_ack_r4030_irq,
67 end_r4030_irq,
68 NULL
69};
70
71void __init init_r4030_ints(void)
72{
73 int i;
74
75 for (i = JAZZ_PARALLEL_IRQ; i <= JAZZ_TIMER_IRQ; i++) {
76 irq_desc[i].status = IRQ_DISABLED;
77 irq_desc[i].action = 0;
78 irq_desc[i].depth = 1;
79 irq_desc[i].handler = &r4030_irq_type;
80 }
81
82 r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, 0);
83 r4030_read_reg16(JAZZ_IO_IRQ_SOURCE); /* clear pending IRQs */
84 r4030_read_reg32(JAZZ_R4030_INVAL_ADDR); /* clear error bits */
85}
86
87/*
88 * On systems with i8259-style interrupt controllers we assume for
89 * driver compatibility reasons interrupts 0 - 15 to be the i8259
90 * interrupts even if the hardware uses a different interrupt numbering.
91 */
92void __init arch_init_irq(void)
93{
94 set_except_vector(0, jazz_handle_int);
95
96 init_i8259_irqs(); /* Integrated i8259 */
97 init_r4030_ints();
98
99 change_c0_status(ST0_IM, IE_IRQ4 | IE_IRQ3 | IE_IRQ2 | IE_IRQ1);
100}
diff --git a/arch/mips/jazz/jazzdma.c b/arch/mips/jazz/jazzdma.c
new file mode 100644
index 000000000000..46e421e14348
--- /dev/null
+++ b/arch/mips/jazz/jazzdma.c
@@ -0,0 +1,565 @@
1/*
2 * Mips Jazz DMA controller support
3 * Copyright (C) 1995, 1996 by Andreas Busse
4 *
5 * NOTE: Some of the argument checking could be removed when
6 * things have settled down. Also, instead of returning 0xffffffff
7 * on failure of vdma_alloc() one could leave page #0 unused
8 * and return the more usual NULL pointer as logical address.
9 */
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/module.h>
13#include <linux/errno.h>
14#include <linux/mm.h>
15#include <linux/bootmem.h>
16#include <linux/spinlock.h>
17#include <asm/mipsregs.h>
18#include <asm/jazz.h>
19#include <asm/io.h>
20#include <asm/uaccess.h>
21#include <asm/dma.h>
22#include <asm/jazzdma.h>
23#include <asm/pgtable.h>
24
25/*
26 * Set this to one to enable additional vdma debug code.
27 */
28#define CONF_DEBUG_VDMA 0
29
30static unsigned long vdma_pagetable_start;
31
32static DEFINE_SPINLOCK(vdma_lock);
33
34/*
35 * Debug stuff
36 */
37#define vdma_debug ((CONF_DEBUG_VDMA) ? debuglvl : 0)
38
39static int debuglvl = 3;
40
41/*
42 * Initialize the pagetable with a one-to-one mapping of
43 * the first 16 Mbytes of main memory and declare all
44 * entries to be unused. Using this method will at least
45 * allow some early device driver operations to work.
46 */
47static inline void vdma_pgtbl_init(void)
48{
49 VDMA_PGTBL_ENTRY *pgtbl = (VDMA_PGTBL_ENTRY *) vdma_pagetable_start;
50 unsigned long paddr = 0;
51 int i;
52
53 for (i = 0; i < VDMA_PGTBL_ENTRIES; i++) {
54 pgtbl[i].frame = paddr;
55 pgtbl[i].owner = VDMA_PAGE_EMPTY;
56 paddr += VDMA_PAGESIZE;
57 }
58}
59
60/*
61 * Initialize the Jazz R4030 dma controller
62 */
63void __init vdma_init(void)
64{
65 /*
66 * Allocate 32k of memory for DMA page tables. This needs to be page
67 * aligned and should be uncached to avoid cache flushing after every
68 * update.
69 */
70 vdma_pagetable_start = alloc_bootmem_low_pages(VDMA_PGTBL_SIZE);
71 if (!vdma_pagetable_start)
72 BUG();
73 dma_cache_wback_inv(vdma_pagetable_start, VDMA_PGTBL_SIZE);
74 vdma_pagetable_start = KSEG1ADDR(vdma_pagetable_start);
75
76 /*
77 * Clear the R4030 translation table
78 */
79 vdma_pgtbl_init();
80
81 r4030_write_reg32(JAZZ_R4030_TRSTBL_BASE,
82 CPHYSADDR(vdma_pagetable_start));
83 r4030_write_reg32(JAZZ_R4030_TRSTBL_LIM, VDMA_PGTBL_SIZE);
84 r4030_write_reg32(JAZZ_R4030_TRSTBL_INV, 0);
85
86 printk("VDMA: R4030 DMA pagetables initialized.\n");
87}
88
89/*
90 * Allocate DMA pagetables using a simple first-fit algorithm
91 */
92unsigned long vdma_alloc(unsigned long paddr, unsigned long size)
93{
94 VDMA_PGTBL_ENTRY *entry = (VDMA_PGTBL_ENTRY *) vdma_pagetable_start;
95 int first, last, pages, frame, i;
96 unsigned long laddr, flags;
97
98 /* check arguments */
99
100 if (paddr > 0x1fffffff) {
101 if (vdma_debug)
102 printk("vdma_alloc: Invalid physical address: %08lx\n",
103 paddr);
104 return VDMA_ERROR; /* invalid physical address */
105 }
106 if (size > 0x400000 || size == 0) {
107 if (vdma_debug)
108 printk("vdma_alloc: Invalid size: %08lx\n", size);
109 return VDMA_ERROR; /* invalid physical address */
110 }
111
112 spin_lock_irqsave(&vdma_lock, flags);
113 /*
114 * Find free chunk
115 */
116 pages = (size + 4095) >> 12; /* no. of pages to allocate */
117 first = 0;
118 while (1) {
119 while (entry[first].owner != VDMA_PAGE_EMPTY &&
120 first < VDMA_PGTBL_ENTRIES) first++;
121 if (first + pages > VDMA_PGTBL_ENTRIES) { /* nothing free */
122 spin_unlock_irqrestore(&vdma_lock, flags);
123 return VDMA_ERROR;
124 }
125
126 last = first + 1;
127 while (entry[last].owner == VDMA_PAGE_EMPTY
128 && last - first < pages)
129 last++;
130
131 if (last - first == pages)
132 break; /* found */
133 }
134
135 /*
136 * Mark pages as allocated
137 */
138 laddr = (first << 12) + (paddr & (VDMA_PAGESIZE - 1));
139 frame = paddr & ~(VDMA_PAGESIZE - 1);
140
141 for (i = first; i < last; i++) {
142 entry[i].frame = frame;
143 entry[i].owner = laddr;
144 frame += VDMA_PAGESIZE;
145 }
146
147 /*
148 * Update translation table and return logical start address
149 */
150 r4030_write_reg32(JAZZ_R4030_TRSTBL_INV, 0);
151
152 if (vdma_debug > 1)
153 printk("vdma_alloc: Allocated %d pages starting from %08lx\n",
154 pages, laddr);
155
156 if (vdma_debug > 2) {
157 printk("LADDR: ");
158 for (i = first; i < last; i++)
159 printk("%08x ", i << 12);
160 printk("\nPADDR: ");
161 for (i = first; i < last; i++)
162 printk("%08x ", entry[i].frame);
163 printk("\nOWNER: ");
164 for (i = first; i < last; i++)
165 printk("%08x ", entry[i].owner);
166 printk("\n");
167 }
168
169 spin_unlock_irqrestore(&vdma_lock, flags);
170
171 return laddr;
172}
173
174EXPORT_SYMBOL(vdma_alloc);
175
176/*
177 * Free previously allocated dma translation pages
178 * Note that this does NOT change the translation table,
179 * it just marks the free'd pages as unused!
180 */
181int vdma_free(unsigned long laddr)
182{
183 VDMA_PGTBL_ENTRY *pgtbl = (VDMA_PGTBL_ENTRY *) vdma_pagetable_start;
184 int i;
185
186 i = laddr >> 12;
187
188 if (pgtbl[i].owner != laddr) {
189 printk
190 ("vdma_free: trying to free other's dma pages, laddr=%8lx\n",
191 laddr);
192 return -1;
193 }
194
195 while (pgtbl[i].owner == laddr && i < VDMA_PGTBL_ENTRIES) {
196 pgtbl[i].owner = VDMA_PAGE_EMPTY;
197 i++;
198 }
199
200 if (vdma_debug > 1)
201 printk("vdma_free: freed %ld pages starting from %08lx\n",
202 i - (laddr >> 12), laddr);
203
204 return 0;
205}
206
207EXPORT_SYMBOL(vdma_free);
208
209/*
210 * Map certain page(s) to another physical address.
211 * Caller must have allocated the page(s) before.
212 */
213int vdma_remap(unsigned long laddr, unsigned long paddr, unsigned long size)
214{
215 VDMA_PGTBL_ENTRY *pgtbl =
216 (VDMA_PGTBL_ENTRY *) vdma_pagetable_start;
217 int first, pages, npages;
218
219 if (laddr > 0xffffff) {
220 if (vdma_debug)
221 printk
222 ("vdma_map: Invalid logical address: %08lx\n",
223 laddr);
224 return -EINVAL; /* invalid logical address */
225 }
226 if (paddr > 0x1fffffff) {
227 if (vdma_debug)
228 printk
229 ("vdma_map: Invalid physical address: %08lx\n",
230 paddr);
231 return -EINVAL; /* invalid physical address */
232 }
233
234 npages = pages =
235 (((paddr & (VDMA_PAGESIZE - 1)) + size) >> 12) + 1;
236 first = laddr >> 12;
237 if (vdma_debug)
238 printk("vdma_remap: first=%x, pages=%x\n", first, pages);
239 if (first + pages > VDMA_PGTBL_ENTRIES) {
240 if (vdma_debug)
241 printk("vdma_alloc: Invalid size: %08lx\n", size);
242 return -EINVAL;
243 }
244
245 paddr &= ~(VDMA_PAGESIZE - 1);
246 while (pages > 0 && first < VDMA_PGTBL_ENTRIES) {
247 if (pgtbl[first].owner != laddr) {
248 if (vdma_debug)
249 printk("Trying to remap other's pages.\n");
250 return -EPERM; /* not owner */
251 }
252 pgtbl[first].frame = paddr;
253 paddr += VDMA_PAGESIZE;
254 first++;
255 pages--;
256 }
257
258 /*
259 * Update translation table
260 */
261 r4030_write_reg32(JAZZ_R4030_TRSTBL_INV, 0);
262
263 if (vdma_debug > 2) {
264 int i;
265 pages = (((paddr & (VDMA_PAGESIZE - 1)) + size) >> 12) + 1;
266 first = laddr >> 12;
267 printk("LADDR: ");
268 for (i = first; i < first + pages; i++)
269 printk("%08x ", i << 12);
270 printk("\nPADDR: ");
271 for (i = first; i < first + pages; i++)
272 printk("%08x ", pgtbl[i].frame);
273 printk("\nOWNER: ");
274 for (i = first; i < first + pages; i++)
275 printk("%08x ", pgtbl[i].owner);
276 printk("\n");
277 }
278
279 return 0;
280}
281
282/*
283 * Translate a physical address to a logical address.
284 * This will return the logical address of the first
285 * match.
286 */
287unsigned long vdma_phys2log(unsigned long paddr)
288{
289 int i;
290 int frame;
291 VDMA_PGTBL_ENTRY *pgtbl =
292 (VDMA_PGTBL_ENTRY *) vdma_pagetable_start;
293
294 frame = paddr & ~(VDMA_PAGESIZE - 1);
295
296 for (i = 0; i < VDMA_PGTBL_ENTRIES; i++) {
297 if (pgtbl[i].frame == frame)
298 break;
299 }
300
301 if (i == VDMA_PGTBL_ENTRIES)
302 return ~0UL;
303
304 return (i << 12) + (paddr & (VDMA_PAGESIZE - 1));
305}
306
307EXPORT_SYMBOL(vdma_phys2log);
308
309/*
310 * Translate a logical DMA address to a physical address
311 */
312unsigned long vdma_log2phys(unsigned long laddr)
313{
314 VDMA_PGTBL_ENTRY *pgtbl =
315 (VDMA_PGTBL_ENTRY *) vdma_pagetable_start;
316
317 return pgtbl[laddr >> 12].frame + (laddr & (VDMA_PAGESIZE - 1));
318}
319
320EXPORT_SYMBOL(vdma_log2phys);
321
322/*
323 * Print DMA statistics
324 */
325void vdma_stats(void)
326{
327 int i;
328
329 printk("vdma_stats: CONFIG: %08x\n",
330 r4030_read_reg32(JAZZ_R4030_CONFIG));
331 printk("R4030 translation table base: %08x\n",
332 r4030_read_reg32(JAZZ_R4030_TRSTBL_BASE));
333 printk("R4030 translation table limit: %08x\n",
334 r4030_read_reg32(JAZZ_R4030_TRSTBL_LIM));
335 printk("vdma_stats: INV_ADDR: %08x\n",
336 r4030_read_reg32(JAZZ_R4030_INV_ADDR));
337 printk("vdma_stats: R_FAIL_ADDR: %08x\n",
338 r4030_read_reg32(JAZZ_R4030_R_FAIL_ADDR));
339 printk("vdma_stats: M_FAIL_ADDR: %08x\n",
340 r4030_read_reg32(JAZZ_R4030_M_FAIL_ADDR));
341 printk("vdma_stats: IRQ_SOURCE: %08x\n",
342 r4030_read_reg32(JAZZ_R4030_IRQ_SOURCE));
343 printk("vdma_stats: I386_ERROR: %08x\n",
344 r4030_read_reg32(JAZZ_R4030_I386_ERROR));
345 printk("vdma_chnl_modes: ");
346 for (i = 0; i < 8; i++)
347 printk("%04x ",
348 (unsigned) r4030_read_reg32(JAZZ_R4030_CHNL_MODE +
349 (i << 5)));
350 printk("\n");
351 printk("vdma_chnl_enables: ");
352 for (i = 0; i < 8; i++)
353 printk("%04x ",
354 (unsigned) r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE +
355 (i << 5)));
356 printk("\n");
357}
358
359/*
360 * DMA transfer functions
361 */
362
363/*
364 * Enable a DMA channel. Also clear any error conditions.
365 */
366void vdma_enable(int channel)
367{
368 int status;
369
370 if (vdma_debug)
371 printk("vdma_enable: channel %d\n", channel);
372
373 /*
374 * Check error conditions first
375 */
376 status = r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE + (channel << 5));
377 if (status & 0x400)
378 printk("VDMA: Channel %d: Address error!\n", channel);
379 if (status & 0x200)
380 printk("VDMA: Channel %d: Memory error!\n", channel);
381
382 /*
383 * Clear all interrupt flags
384 */
385 r4030_write_reg32(JAZZ_R4030_CHNL_ENABLE + (channel << 5),
386 r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE +
387 (channel << 5)) | R4030_TC_INTR
388 | R4030_MEM_INTR | R4030_ADDR_INTR);
389
390 /*
391 * Enable the desired channel
392 */
393 r4030_write_reg32(JAZZ_R4030_CHNL_ENABLE + (channel << 5),
394 r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE +
395 (channel << 5)) |
396 R4030_CHNL_ENABLE);
397}
398
399EXPORT_SYMBOL(vdma_enable);
400
401/*
402 * Disable a DMA channel
403 */
404void vdma_disable(int channel)
405{
406 if (vdma_debug) {
407 int status =
408 r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE +
409 (channel << 5));
410
411 printk("vdma_disable: channel %d\n", channel);
412 printk("VDMA: channel %d status: %04x (%s) mode: "
413 "%02x addr: %06x count: %06x\n",
414 channel, status,
415 ((status & 0x600) ? "ERROR" : "OK"),
416 (unsigned) r4030_read_reg32(JAZZ_R4030_CHNL_MODE +
417 (channel << 5)),
418 (unsigned) r4030_read_reg32(JAZZ_R4030_CHNL_ADDR +
419 (channel << 5)),
420 (unsigned) r4030_read_reg32(JAZZ_R4030_CHNL_COUNT +
421 (channel << 5)));
422 }
423
424 r4030_write_reg32(JAZZ_R4030_CHNL_ENABLE + (channel << 5),
425 r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE +
426 (channel << 5)) &
427 ~R4030_CHNL_ENABLE);
428
429 /*
430 * After disabling a DMA channel a remote bus register should be
431 * read to ensure that the current DMA acknowledge cycle is completed.
432 */
433 *((volatile unsigned int *) JAZZ_DUMMY_DEVICE);
434}
435
436EXPORT_SYMBOL(vdma_disable);
437
438/*
439 * Set DMA mode. This function accepts the mode values used
440 * to set a PC-style DMA controller. For the SCSI and FDC
441 * channels, we also set the default modes each time we're
442 * called.
443 * NOTE: The FAST and BURST dma modes are supported by the
444 * R4030 Rev. 2 and PICA chipsets only. I leave them disabled
445 * for now.
446 */
447void vdma_set_mode(int channel, int mode)
448{
449 if (vdma_debug)
450 printk("vdma_set_mode: channel %d, mode 0x%x\n", channel,
451 mode);
452
453 switch (channel) {
454 case JAZZ_SCSI_DMA: /* scsi */
455 r4030_write_reg32(JAZZ_R4030_CHNL_MODE + (channel << 5),
456/* R4030_MODE_FAST | */
457/* R4030_MODE_BURST | */
458 R4030_MODE_INTR_EN |
459 R4030_MODE_WIDTH_16 |
460 R4030_MODE_ATIME_80);
461 break;
462
463 case JAZZ_FLOPPY_DMA: /* floppy */
464 r4030_write_reg32(JAZZ_R4030_CHNL_MODE + (channel << 5),
465/* R4030_MODE_FAST | */
466/* R4030_MODE_BURST | */
467 R4030_MODE_INTR_EN |
468 R4030_MODE_WIDTH_8 |
469 R4030_MODE_ATIME_120);
470 break;
471
472 case JAZZ_AUDIOL_DMA:
473 case JAZZ_AUDIOR_DMA:
474 printk("VDMA: Audio DMA not supported yet.\n");
475 break;
476
477 default:
478 printk
479 ("VDMA: vdma_set_mode() called with unsupported channel %d!\n",
480 channel);
481 }
482
483 switch (mode) {
484 case DMA_MODE_READ:
485 r4030_write_reg32(JAZZ_R4030_CHNL_ENABLE + (channel << 5),
486 r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE +
487 (channel << 5)) &
488 ~R4030_CHNL_WRITE);
489 break;
490
491 case DMA_MODE_WRITE:
492 r4030_write_reg32(JAZZ_R4030_CHNL_ENABLE + (channel << 5),
493 r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE +
494 (channel << 5)) |
495 R4030_CHNL_WRITE);
496 break;
497
498 default:
499 printk
500 ("VDMA: vdma_set_mode() called with unknown dma mode 0x%x\n",
501 mode);
502 }
503}
504
505EXPORT_SYMBOL(vdma_set_mode);
506
507/*
508 * Set Transfer Address
509 */
510void vdma_set_addr(int channel, long addr)
511{
512 if (vdma_debug)
513 printk("vdma_set_addr: channel %d, addr %lx\n", channel,
514 addr);
515
516 r4030_write_reg32(JAZZ_R4030_CHNL_ADDR + (channel << 5), addr);
517}
518
519EXPORT_SYMBOL(vdma_set_addr);
520
521/*
522 * Set Transfer Count
523 */
524void vdma_set_count(int channel, int count)
525{
526 if (vdma_debug)
527 printk("vdma_set_count: channel %d, count %08x\n", channel,
528 (unsigned) count);
529
530 r4030_write_reg32(JAZZ_R4030_CHNL_COUNT + (channel << 5), count);
531}
532
533EXPORT_SYMBOL(vdma_set_count);
534
535/*
536 * Get Residual
537 */
538int vdma_get_residue(int channel)
539{
540 int residual;
541
542 residual = r4030_read_reg32(JAZZ_R4030_CHNL_COUNT + (channel << 5));
543
544 if (vdma_debug)
545 printk("vdma_get_residual: channel %d: residual=%d\n",
546 channel, residual);
547
548 return residual;
549}
550
551/*
552 * Get DMA channel enable register
553 */
554int vdma_get_enable(int channel)
555{
556 int enable;
557
558 enable = r4030_read_reg32(JAZZ_R4030_CHNL_ENABLE + (channel << 5));
559
560 if (vdma_debug)
561 printk("vdma_get_enable: channel %d: enable=%d\n", channel,
562 enable);
563
564 return enable;
565}
diff --git a/arch/mips/jazz/reset.c b/arch/mips/jazz/reset.c
new file mode 100644
index 000000000000..2a9754750bc8
--- /dev/null
+++ b/arch/mips/jazz/reset.c
@@ -0,0 +1,69 @@
1/*
2 * Reset a Jazz machine.
3 *
4 * We don't trust the firmware so we do it the classic way by poking and
5 * stabbing at the keyboard controller ...
6 */
7#include <linux/jiffies.h>
8#include <asm/jazz.h>
9#include <asm/io.h>
10#include <asm/system.h>
11#include <asm/reboot.h>
12#include <asm/delay.h>
13
14#define KBD_STAT_IBF 0x02 /* Keyboard input buffer full */
15
16static void jazz_write_output(unsigned char val)
17{
18 int status;
19
20 do {
21 status = jazz_kh->command;
22 } while (status & KBD_STAT_IBF);
23 jazz_kh->data = val;
24}
25
26static void jazz_write_command(unsigned char val)
27{
28 int status;
29
30 do {
31 status = jazz_kh->command;
32 } while (status & KBD_STAT_IBF);
33 jazz_kh->command = val;
34}
35
36static unsigned char jazz_read_status(void)
37{
38 return jazz_kh->command;
39}
40
41static inline void kb_wait(void)
42{
43 unsigned long start = jiffies;
44 unsigned long timeout = start + HZ/2;
45
46 do {
47 if (! (jazz_read_status() & 0x02))
48 return;
49 } while (time_before_eq(jiffies, timeout));
50}
51
52void jazz_machine_restart(char *command)
53{
54 while(1) {
55 kb_wait();
56 jazz_write_command (0xd1);
57 kb_wait();
58 jazz_write_output (0x00);
59 }
60}
61
62void jazz_machine_halt(void)
63{
64}
65
66void jazz_machine_power_off(void)
67{
68 /* Jazz machines don't have a software power switch */
69}
diff --git a/arch/mips/jazz/setup.c b/arch/mips/jazz/setup.c
new file mode 100644
index 000000000000..fccb06fe209d
--- /dev/null
+++ b/arch/mips/jazz/setup.c
@@ -0,0 +1,101 @@
1/*
2 * Setup pointers to hardware-dependent routines.
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 1996, 1997, 1998, 2001 by Ralf Baechle
9 * Copyright (C) 2001 MIPS Technologies, Inc.
10 */
11#include <linux/config.h>
12#include <linux/eisa.h>
13#include <linux/hdreg.h>
14#include <linux/init.h>
15#include <linux/ioport.h>
16#include <linux/sched.h>
17#include <linux/interrupt.h>
18#include <linux/mm.h>
19#include <linux/console.h>
20#include <linux/fb.h>
21#include <linux/ide.h>
22#include <asm/bootinfo.h>
23#include <asm/irq.h>
24#include <asm/jazz.h>
25#include <asm/jazzdma.h>
26#include <asm/ptrace.h>
27#include <asm/reboot.h>
28#include <asm/io.h>
29#include <asm/pgtable.h>
30#include <asm/time.h>
31#include <asm/traps.h>
32
33extern asmlinkage void jazz_handle_int(void);
34
35extern void jazz_machine_restart(char *command);
36extern void jazz_machine_halt(void);
37extern void jazz_machine_power_off(void);
38
39static void __init jazz_time_init(struct irqaction *irq)
40{
41 /* set the clock to 100 Hz */
42 r4030_write_reg32(JAZZ_TIMER_INTERVAL, 9);
43 setup_irq(JAZZ_TIMER_IRQ, irq);
44}
45
46static struct resource jazz_io_resources[] = {
47 { "dma1", 0x00, 0x1f, IORESOURCE_BUSY },
48 { "timer", 0x40, 0x5f, IORESOURCE_BUSY },
49 { "dma page reg", 0x80, 0x8f, IORESOURCE_BUSY },
50 { "dma2", 0xc0, 0xdf, IORESOURCE_BUSY },
51};
52
53static void __init jazz_setup(void)
54{
55 int i;
56
57 /* Map 0xe0000000 -> 0x0:800005C0, 0xe0010000 -> 0x1:30000580 */
58 add_wired_entry (0x02000017, 0x03c00017, 0xe0000000, PM_64K);
59
60 /* Map 0xe2000000 -> 0x0:900005C0, 0xe3010000 -> 0x0:910005C0 */
61 add_wired_entry (0x02400017, 0x02440017, 0xe2000000, PM_16M);
62
63 /* Map 0xe4000000 -> 0x0:600005C0, 0xe4100000 -> 400005C0 */
64 add_wired_entry (0x01800017, 0x01000017, 0xe4000000, PM_4M);
65
66 set_io_port_base(JAZZ_PORT_BASE);
67#ifdef CONFIG_EISA
68 if (mips_machtype == MACH_MIPS_MAGNUM_4000)
69 EISA_bus = 1;
70#endif
71 isa_slot_offset = 0xe3000000;
72
73 /* request I/O space for devices used on all i[345]86 PCs */
74 for (i = 0; i < ARRAY_SIZE(jazz_io_resources); i++)
75 request_resource(&ioport_resource, jazz_io_resources + i);
76
77 board_timer_setup = jazz_time_init;
78 /* The RTC is outside the port address space */
79
80 _machine_restart = jazz_machine_restart;
81 _machine_halt = jazz_machine_halt;
82 _machine_power_off = jazz_machine_power_off;
83
84#warning "Somebody should check if screen_info is ok for Jazz."
85
86 screen_info = (struct screen_info) {
87 0, 0, /* orig-x, orig-y */
88 0, /* unused */
89 0, /* orig_video_page */
90 0, /* orig_video_mode */
91 160, /* orig_video_cols */
92 0, 0, 0, /* unused, ega_bx, unused */
93 64, /* orig_video_lines */
94 0, /* orig_video_isVGA */
95 16 /* orig_video_points */
96 };
97
98 vdma_init();
99}
100
101early_initcall(jazz_setup);