2 * $Id: zorro.c,v 1.1.2.1 1998/06/07 23:21:02 geert Exp $
6 * Copyright (C) 1995-2000 Geert Uytterhoeven
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/zorro.h>
18 #include <asm/setup.h>
19 #include <asm/bitops.h>
20 #include <asm/amigahw.h>
24 * Zorro Expansion Devices
27 u_int zorro_num_autocon
= 0;
28 struct zorro_dev zorro_autocon
[ZORRO_NUM_AUTO
];
33 * Order _does_ matter! (see code below)
36 static struct resource zorro_res
[4] = {
37 /* Zorro II regions (on Zorro II/III) */
38 { "Zorro II exp", 0x00e80000, 0x00efffff },
39 { "Zorro II mem", 0x00200000, 0x009fffff },
40 /* Zorro III regions (on Zorro III only) */
41 { "Zorro III exp", 0xff000000, 0xffffffff },
42 { "Zorro III cfg", 0x40000000, 0x7fffffff }
45 static u_int zorro_num_res __initdata
= 0;
52 struct zorro_dev
*zorro_find_device(zorro_id id
, struct zorro_dev
*from
)
54 struct zorro_dev
*dev
;
56 if (!MACH_IS_AMIGA
|| !AMIGAHW_PRESENT(ZORRO
))
59 for (dev
= from
? from
+1 : &zorro_autocon
[0];
60 dev
< zorro_autocon
+zorro_num_autocon
;
62 if (id
== ZORRO_WILDCARD
|| id
== dev
->id
)
69 * Bitmask indicating portions of available Zorro II RAM that are unused
70 * by the system. Every bit represents a 64K chunk, for a maximum of 8MB
71 * (128 chunks, physical 0x00200000-0x009fffff).
73 * If you want to use (= allocate) portions of this RAM, you should clear
74 * the corresponding bits.
78 * - SCSI DMA bounce buffers
80 * FIXME: use the normal resource management
83 DECLARE_BITMAP(zorro_unused_z2ram
, 128);
86 static void __init
mark_region(unsigned long start
, unsigned long end
,
90 start
+= Z2RAM_CHUNKMASK
;
92 end
+= Z2RAM_CHUNKMASK
;
93 start
&= ~Z2RAM_CHUNKMASK
;
94 end
&= ~Z2RAM_CHUNKMASK
;
96 if (end
<= Z2RAM_START
|| start
>= Z2RAM_END
)
98 start
= start
< Z2RAM_START
? 0x00000000 : start
-Z2RAM_START
;
99 end
= end
> Z2RAM_END
? Z2RAM_SIZE
: end
-Z2RAM_START
;
100 while (start
< end
) {
101 u32 chunk
= start
>>Z2RAM_CHUNKSHIFT
;
103 set_bit(chunk
, zorro_unused_z2ram
);
105 clear_bit(chunk
, zorro_unused_z2ram
);
106 start
+= Z2RAM_CHUNKSIZE
;
111 static struct resource __init
*zorro_find_parent_resource(struct zorro_dev
*z
)
115 for (i
= 0; i
< zorro_num_res
; i
++)
116 if (z
->resource
.start
>= zorro_res
[i
].start
&&
117 z
->resource
.end
<= zorro_res
[i
].end
)
118 return &zorro_res
[i
];
119 return &iomem_resource
;
127 static int __init
zorro_init(void)
129 struct zorro_dev
*dev
;
132 if (!MACH_IS_AMIGA
|| !AMIGAHW_PRESENT(ZORRO
))
135 printk("Zorro: Probing AutoConfig expansion devices: %d device%s\n",
136 zorro_num_autocon
, zorro_num_autocon
== 1 ? "" : "s");
138 /* Request the resources */
139 zorro_num_res
= AMIGAHW_PRESENT(ZORRO3
) ? 4 : 2;
140 for (i
= 0; i
< zorro_num_res
; i
++)
141 request_resource(&iomem_resource
, &zorro_res
[i
]);
142 for (i
= 0; i
< zorro_num_autocon
; i
++) {
143 dev
= &zorro_autocon
[i
];
144 dev
->id
= (dev
->rom
.er_Manufacturer
<<16) | (dev
->rom
.er_Product
<<8);
145 if (dev
->id
== ZORRO_PROD_GVP_EPC_BASE
) {
147 unsigned long magic
= dev
->resource
.start
+0x8000;
148 dev
->id
|= *(u16
*)ZTWO_VADDR(magic
) & GVP_PRODMASK
;
150 sprintf(dev
->name
, "Zorro device %08x", dev
->id
);
151 zorro_name_device(dev
);
152 dev
->resource
.name
= dev
->name
;
153 if (request_resource(zorro_find_parent_resource(dev
), &dev
->resource
))
154 printk(KERN_ERR
"Zorro: Address space collision on device %s "
156 dev
->name
, dev
->resource
.start
, dev
->resource
.end
);
159 /* Mark all available Zorro II memory */
160 for (i
= 0; i
< zorro_num_autocon
; i
++) {
161 dev
= &zorro_autocon
[i
];
162 if (dev
->rom
.er_Type
& ERTF_MEMLIST
)
163 mark_region(dev
->resource
.start
, dev
->resource
.end
+1, 1);
166 /* Unmark all used Zorro II memory */
167 for (i
= 0; i
< m68k_num_memory
; i
++)
168 if (m68k_memory
[i
].addr
< 16*1024*1024)
169 mark_region(m68k_memory
[i
].addr
,
170 m68k_memory
[i
].addr
+m68k_memory
[i
].size
, 0);
175 subsys_initcall(zorro_init
);
177 EXPORT_SYMBOL(zorro_find_device
);
178 EXPORT_SYMBOL(zorro_unused_z2ram
);
180 MODULE_LICENSE("GPL");