Resent-Date: Mon, 16 Aug 1999 22:43:22 +0200 (MET DST)
Date: Mon, 16 Aug 1999 22:43:01 +0200 (CEST)
From: Geert Uytterhoeven <geert@thomas.kotnet.org>
To: Linux/m68k <linux-m68k@lists.linux-m68k.org>
Subject: Amiga resource management
Resent-From: linux-m68k@phil.uni-sb.de


Here's a first patch for resource management on Amiga. It's not finished yet.

Available resources:
  - Misc Amiga hardware
  - Zorro bus
      o use zorro_find_device() to find a device (cfr. PCI)
      o use zorro_request_region() to mark regions busy (+zorro_release_region)
	hence zorro_{config,unconfig}+board() are gone
  - Chip RAM

Currently the Ariadne driver is the only one that I already converted. Loading
and unloading its module works fine. More drivers are to follow.

Now my /proc/iomem looks like:

00000000-00200000 : Chip RAM
  0009e718-001dffbf : amifb
00bfd000-00bfdfff : CIA B
00bfe000-00bfefff : CIA A
00c00000-00c7ffff : Ranger Memory
00dc0000-00dcffff : A3000 RTC
00dff000-00dfffff : Custom Chips
00e80000-00efffff : Zorro II exp
  00e90000-00e90fff : Am79C960
  00e98000-00e9ffff : Ethernet Buffer
00f80000-00ffffff : Kickstart ROM
40000000-7fffffff : Zorro III cfg
ff000000-ffffffff : Zorro III exp

I didn't put a Zorro database in the kernel. Instead ariadne.c copies the board
name in the zorro_dev struct when the board is initialized.

Problems:
  - Early Chip RAM allocations (debug=mem, system beep) are not visible because 
    kmem isn't initialized yet that early. See dmesg below.
  - Why don't I see my Ariadne at 0xe90000-0xe9ffff?!?!? zorro_init() should
    add it.
  - 2.3.13 still crashes somewhere after boot up.

Comments? Suggestions?

--- m68k-2.3.13/arch/ppc/amiga/config.c.orig	Mon Aug 16 10:12:38 1999
+++ m68k-2.3.13/arch/ppc/amiga/config.c	Mon Aug 16 13:13:20 1999
@@ -731,7 +731,7 @@
 
 static void amiga_savekmsg_init(void)
 {
-    savekmsg = (struct savekmsg *)amiga_chip_alloc(SAVEKMSG_MAXMEM);
+    savekmsg = (struct savekmsg *)amiga_chip_alloc(SAVEKMSG_MAXMEM, "Debug");
     savekmsg->magic1 = SAVEKMSG_MAGIC1;
     savekmsg->magic2 = SAVEKMSG_MAGIC2;
     savekmsg->magicptr = virt_to_phys(savekmsg);
--- m68k-2.3.13/arch/m68k/amiga/chipram.c.orig	Wed May 14 07:41:01 1997
+++ m68k-2.3.13/arch/m68k/amiga/chipram.c	Mon Aug 16 21:25:03 1999
@@ -9,6 +9,7 @@
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/ioport.h>
 #include <asm/amigahw.h>
 
 struct chip_desc {
@@ -32,14 +33,18 @@
 	return chipavail;
 }
 
+static struct resource chipram = { "Chip RAM", 0 };
 
-__initfunc(void amiga_chip_init (void))
+void __init amiga_chip_init(void)
 {
   struct chip_desc *dp;
 
   if (!AMIGAHW_PRESENT(CHIP_RAM))
     return;
 
+  chipram.end = amiga_chip_size;
+  request_resource(&iomem_resource, &chipram);
+
   /* initialize start boundary */
 
   dp = DP(chipaddr);
@@ -62,7 +67,7 @@
 #endif
 }
 
-void *amiga_chip_alloc (long size)
+void *amiga_chip_alloc(long size, const char *name)
 {
 	/* last chunk */
 	struct chip_desc *dp;
@@ -72,7 +77,7 @@
 	size = (size + 7) & ~7;
 
 #ifdef DEBUG
-   printk("chip_alloc: allocate %ld bytes\n", size);
+   printk("amiga_chip_alloc: allocate %ld bytes\n", size);
 #endif
 
 	/*
@@ -98,14 +103,14 @@
 		dp = DP((unsigned long)ptr + dp->length);
 		dp->alloced = 1;
 #ifdef DEBUG
-		printk ("chip_alloc: no split\n");
+		printk ("amiga_chip_alloc: no split\n");
 #endif
 	} else {
 		/* split the extent; use the end part */
 		long newsize = dp->length - (2*sizeof(*dp) + size);
 
 #ifdef DEBUG
-		printk ("chip_alloc: splitting %d to %ld\n", dp->length,
+		printk ("amiga_chip_alloc: splitting %d to %ld\n", dp->length,
 			newsize);
 #endif
 		dp->length = newsize;
@@ -124,14 +129,18 @@
 	}
 
 #ifdef DEBUG
-	printk ("chip_alloc: returning %p\n", ptr);
+	printk ("amiga_chip_alloc: returning %p\n", ptr);
 #endif
 
 	if ((unsigned long)ptr & 7)
-		panic("chip_alloc: alignment violation\n");
+		panic("amiga_chip_alloc: alignment violation\n");
 
     chipavail -= size + (2*sizeof(*dp)); /*MILAN*/
 
+    if (!__request_region(&iomem_resource, ZTWO_PADDR(ptr), size, name))
+	printk(KERN_WARNING "amiga_chip_alloc: region of size %ld at 0x%08lx "
+	       "is busy\n", size, ZTWO_PADDR(ptr));
+
     return ptr;
 }
 
@@ -146,6 +155,7 @@
 #endif
 	/* deallocate the chunk */
 	sdp->alloced = edp->alloced = 0;
+	__release_region(&iomem_resource, ZTWO_PADDR(ptr), sdp->length);
 
 	/* check if we should merge with the previous chunk */
 	if (!sdp->first && !sdp[-1].alloced) {
--- m68k-2.3.13/arch/m68k/amiga/config.c.orig	Mon Aug 16 10:18:50 1999
+++ m68k-2.3.13/arch/m68k/amiga/config.c	Mon Aug 16 14:31:46 1999
@@ -116,6 +116,29 @@
 
 extern void (*kd_mksound)(unsigned int, unsigned int);
 
+static struct resource ranger_resource = {
+    "Ranger Memory", 0xc00000, 0xc7ffff
+};
+static struct resource ciab_resource = {
+    "CIA B", 0xbfd000, 0xbfdfff
+};
+static struct resource ciaa_resource = {
+    "CIA A", 0xbfe000, 0xbfefff
+};
+static struct resource a2000_rtc_resource = {
+    "A2000 RTC", 0xdc0000, 0xdcffff
+};
+static struct resource a3000_rtc_resource = {
+    "A3000 RTC", 0xdc0000, 0xdcffff
+};
+static struct resource custom_chips_resource = {
+    "Custom Chips", 0xdff000, 0xdfffff
+};
+static struct resource kickstart_resource = {
+    "Kickstart ROM", 0xf80000, 0xffffff
+};
+
+
     /*
      *  Parse an Amiga-specific record in the bootinfo
      */
@@ -151,11 +174,15 @@
 	    break;
 
 	case BI_AMIGA_AUTOCON:
-	    if (zorro_num_autocon < ZORRO_NUM_AUTO)
-		memcpy(&zorro_autocon[zorro_num_autocon++],
-		       (const struct ConfigDev *)data,
-		       sizeof(struct ConfigDev));
-	    else
+	    if (zorro_num_autocon < ZORRO_NUM_AUTO) {
+		const struct ConfigDev *cd = (struct ConfigDev *)data;
+		struct zorro_dev *dev = &zorro_autocon[zorro_num_autocon++];
+		dev->rom = cd->cd_Rom;
+		dev->slotaddr = cd->cd_SlotAddr;
+		dev->slotsize = cd->cd_SlotSize;
+		dev->resource.start = (unsigned long)cd->cd_BoardAddr;
+		dev->resource.end = dev->resource.start+cd->cd_BoardSize-1;
+	    } else
 		printk("amiga_parse_bootinfo: too many AutoConfig devices\n");
 	    break;
 
@@ -339,6 +366,14 @@
   amiga_debug_init();
   amiga_identify();
 
+  /* Yuk, we don't have PCI memory */
+  iomem_resource.name = "Memory";
+  request_resource(&iomem_resource, &ranger_resource);
+  request_resource(&iomem_resource, &ciab_resource);
+  request_resource(&iomem_resource, &ciaa_resource);
+  request_resource(&iomem_resource, &custom_chips_resource);
+  request_resource(&iomem_resource, &kickstart_resource);
+
   mach_sched_init      = amiga_sched_init;
   mach_keyb_init       = amiga_keyb_init;
   mach_kbdrate         = amiga_kbdrate;
@@ -354,9 +389,11 @@
   mach_gettimeoffset   = amiga_gettimeoffset;
   if (AMIGAHW_PRESENT(A3000_CLK)){
     mach_gettod  = a3000_gettod;
+    request_resource(&iomem_resource, &a3000_rtc_resource);
   }
   else{ /* if (AMIGAHW_PRESENT(A2000_CLK)) */
     mach_gettod  = a2000_gettod;
+    request_resource(&iomem_resource, &a2000_rtc_resource);
   }
 
   mach_max_dma_address = 0xffffffff; /*
@@ -798,7 +835,7 @@
 
 static void amiga_savekmsg_init(void)
 {
-    savekmsg = (struct savekmsg *)amiga_chip_alloc(SAVEKMSG_MAXMEM);
+    savekmsg = (struct savekmsg *)amiga_chip_alloc(SAVEKMSG_MAXMEM, "Debug");
     savekmsg->magic1 = SAVEKMSG_MAGIC1;
     savekmsg->magic2 = SAVEKMSG_MAGIC2;
     savekmsg->magicptr = virt_to_phys(savekmsg);
@@ -973,8 +1010,9 @@
     AMIGAHW_ANNOUNCE(MAGIC_REKICK, "Magic Hard Rekick");
     AMIGAHW_ANNOUNCE(PCMCIA, "PCMCIA Slot");
     if (AMIGAHW_PRESENT(ZORRO))
-	len += sprintf(buffer+len, "\tZorro%s AutoConfig: %d Expansion Device%s\n",
-		       AMIGAHW_PRESENT(ZORRO3) ? " III" : "",
+	len += sprintf(buffer+len, "\tZorro II%s AutoConfig: %d Expansion "
+				   "Device%s\n",
+		       AMIGAHW_PRESENT(ZORRO3) ? "I" : "",
 		       zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
 
 #undef AMIGAHW_ANNOUNCE
--- m68k-2.3.13/arch/m68k/amiga/amisound.c.orig	Tue Jun 17 01:35:53 1997
+++ m68k-2.3.13/arch/m68k/amiga/amisound.c	Mon Aug 16 14:43:20 1999
@@ -42,7 +42,7 @@
 
 __initfunc(void amiga_init_sound(void))
 {
-	snd_data = amiga_chip_alloc(sizeof(sine_data));
+	snd_data = amiga_chip_alloc(sizeof(sine_data), "Beep");
 	if (!snd_data) {
 		printk (KERN_CRIT "amiga init_sound: failed to allocate chipmem\n");
 		return;
--- m68k-2.3.13/drivers/net/ariadne.c.orig	Mon Aug 16 10:18:52 1999
+++ m68k-2.3.13/drivers/net/ariadne.c	Mon Aug 16 20:35:24 1999
@@ -148,46 +148,49 @@
 
 int __init ariadne_probe(struct device *dev)
 {
-    unsigned int key;
-    const struct ConfigDev *cd;
-    u_long board;
-    struct ariadne_private *priv;
-
-    /* Ethernet is part 0, Parallel is part 1 */
-    if ((key = zorro_find(ZORRO_PROD_VILLAGE_TRONIC_ARIADNE, 0, 0))) {
-	cd = zorro_get_board(key);
-	if ((board = (u_long)cd->cd_BoardAddr)) {
-	    dev->dev_addr[0] = 0x00;
-	    dev->dev_addr[1] = 0x60;
-	    dev->dev_addr[2] = 0x30;
-	    dev->dev_addr[3] = (cd->cd_Rom.er_SerialNumber>>16)&0xff;
-	    dev->dev_addr[4] = (cd->cd_Rom.er_SerialNumber>>8)&0xff;
-	    dev->dev_addr[5] = cd->cd_Rom.er_SerialNumber&0xff;
-	    printk("%s: Ariadne at 0x%08lx, Ethernet Address "
-		   "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board,
-		   dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
-		   dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
-
-	    init_etherdev(dev, 0);
-
-	    dev->priv = kmalloc(sizeof(struct ariadne_private), GFP_KERNEL);
-	    if (dev->priv == NULL)
-		return -ENOMEM;
-	    priv = (struct ariadne_private *)dev->priv;
-	    memset(priv, 0, sizeof(struct ariadne_private));
-
-	    priv->board = (struct AriadneBoard *)ZTWO_VADDR(board);
-	    priv->key = key;
-
-	    dev->open = &ariadne_open;
-	    dev->stop = &ariadne_close;
-	    dev->hard_start_xmit = &ariadne_start_xmit;
-	    dev->get_stats = &ariadne_get_stats;
-	    dev->set_multicast_list = &set_multicast_list;
+    struct zorro_dev *z = NULL;
 
-	    zorro_config_board(key, 0);
-	    return(0);
+    while ((z = zorro_find_device(ZORRO_PROD_VILLAGE_TRONIC_ARIADNE, z))) {
+	unsigned long board = z->resource.start;
+	struct ariadne_private *priv;
+	if (!zorro_request_region(board, 0x1000, "Am79C960"))
+	    continue;
+	if (!zorro_request_region(board+0x8000, 0x8000, "Ethernet Buffer")) {
+	    zorro_release_region(board, 0x1000);
+	    continue;
 	}
+	strcpy(z->name, "Ariadne Ethernet Card and Parallel Ports");
+	dev->dev_addr[0] = 0x00;
+	dev->dev_addr[1] = 0x60;
+	dev->dev_addr[2] = 0x30;
+	dev->dev_addr[3] = (z->rom.er_SerialNumber>>16)&0xff;
+	dev->dev_addr[4] = (z->rom.er_SerialNumber>>8)&0xff;
+	dev->dev_addr[5] = z->rom.er_SerialNumber&0xff;
+	printk("%s: Ariadne at 0x%08lx, Ethernet Address "
+	       "%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, board,
+	       dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
+	       dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
+
+	init_etherdev(dev, 0);
+
+	dev->priv = kmalloc(sizeof(struct ariadne_private), GFP_KERNEL);
+	if (dev->priv == NULL) {
+	    zorro_release_region(board, 0x1000);
+	    zorro_release_region(board+0x8000, 0x8000);
+	    return -ENOMEM;
+	}
+	priv = (struct ariadne_private *)dev->priv;
+	memset(priv, 0, sizeof(struct ariadne_private));
+
+	priv->board = (struct AriadneBoard *)ZTWO_VADDR(board);
+
+	dev->open = &ariadne_open;
+	dev->stop = &ariadne_close;
+	dev->hard_start_xmit = &ariadne_start_xmit;
+	dev->get_stats = &ariadne_get_stats;
+	dev->set_multicast_list = &set_multicast_list;
+
+	return(0);
     }
     return(ENODEV);
 }
@@ -865,9 +868,11 @@
 void cleanup_module(void)
 {
     struct ariadne_private *priv = (struct ariadne_private *)ariadne_dev.priv;
+    unsigned long board = ZTWO_PADDR(priv->board);
 
     unregister_netdev(&ariadne_dev);
-    zorro_unconfig_board(priv->key, 0);
+    zorro_release_region(board, 0x1000);
+    zorro_release_region(board+0x8000, 0x8000);
     kfree(priv);
 }
 
--- m68k-2.3.13/drivers/block/amiflop.c.orig	Mon Aug 16 10:12:39 1999
+++ m68k-2.3.13/drivers/block/amiflop.c	Mon Aug 16 13:13:20 1999
@@ -1801,7 +1801,7 @@
     printk("fd: Unable to get major %d for floppy\n",MAJOR_NR);
     return -EBUSY;
   }
-  if ((raw_buf = (char *)amiga_chip_alloc (RAW_BUF_SIZE)) == NULL) {
+  if ((raw_buf = (char *)amiga_chip_alloc (RAW_BUF_SIZE, "Floppy")) == NULL) {
   	printk("fd: cannot get chip mem buffer\n");
   	unregister_blkdev(MAJOR_NR,"fd");
   	return -ENOMEM;
--- m68k-2.3.13/drivers/block/z2ram.c.orig	Mon Aug 16 10:13:07 1999
+++ m68k-2.3.13/drivers/block/z2ram.c	Mon Aug 16 13:13:20 1999
@@ -145,7 +145,7 @@
     {
 	chip_count++;
 	z2ram_map[ z2ram_size ] =
-	    (u_long)amiga_chip_alloc( Z2RAM_CHUNKSIZE );
+	    (u_long)amiga_chip_alloc( Z2RAM_CHUNKSIZE, "z2ram" );
 
 	if ( z2ram_map[ z2ram_size ] == 0 )
 	{
--- m68k-2.3.13/drivers/scsi/gvp11.c.orig	Mon Aug 16 10:18:52 1999
+++ m68k-2.3.13/drivers/scsi/gvp11.c	Mon Aug 16 13:13:20 1999
@@ -77,7 +77,8 @@
 
 	if ( scsi_alloc_out_of_range || !HDATA(cmd->host)->dma_bounce_buffer) {
 	    HDATA(cmd->host)->dma_bounce_buffer =
-		amiga_chip_alloc(HDATA(cmd->host)->dma_bounce_len);
+		amiga_chip_alloc(HDATA(cmd->host)->dma_bounce_len,
+				       "GVP II SCSI Bounce Buffer");
 
 	    if(!HDATA(cmd->host)->dma_bounce_buffer)
 	    {
@@ -102,7 +103,8 @@
             }
 		
 	    HDATA(cmd->host)->dma_bounce_buffer =
-		amiga_chip_alloc(HDATA(cmd->host)->dma_bounce_len);
+		amiga_chip_alloc(HDATA(cmd->host)->dma_bounce_len,
+				       "GVP II SCSI Bounce Buffer");
 
 	    if(!HDATA(cmd->host)->dma_bounce_buffer)
 	    {
--- m68k-2.3.13/drivers/sound/dmasound.c.orig	Mon Aug 16 10:18:53 1999
+++ m68k-2.3.13/drivers/sound/dmasound.c	Mon Aug 16 20:54:04 1999
@@ -2889,7 +2889,7 @@
 
 static void *AmiAlloc(unsigned int size, int flags)
 {
-	return(amiga_chip_alloc((long)size));
+	return amiga_chip_alloc((long)size, "dmasound");
 }
 
 static void AmiFree(void *obj, unsigned int size)
--- m68k-2.3.13/drivers/video/vfb.c.orig	Mon Aug 16 10:18:53 1999
+++ m68k-2.3.13/drivers/video/vfb.c	Mon Aug 16 11:56:19 1999
@@ -406,7 +406,7 @@
 }
 
 
-void __init vfb_setup(char *options, int *ints)
+void __init vfb_setup(char *options)
 {
     char *this_opt;
 
--- m68k-2.3.13/drivers/video/amifb.c.orig	Mon Aug 16 10:18:53 1999
+++ m68k-2.3.13/drivers/video/amifb.c	Mon Aug 16 13:13:21 1999
@@ -2095,7 +2095,7 @@
 	u_long ptr;
 
 	size += PAGE_SIZE-1;
-	if (!(ptr = (u_long)amiga_chip_alloc(size)))
+	if (!(ptr = (u_long)amiga_chip_alloc(size, "amifb")))
 		panic("No Chip RAM for frame buffer");
 	memset((void *)ptr, 0, size);
 	ptr = PAGE_ALIGN(ptr);
--- m68k-2.3.13/drivers/zorro/zorrosyms.c.orig	Thu Jul 30 20:10:22 1998
+++ m68k-2.3.13/drivers/zorro/zorrosyms.c	Mon Aug 16 13:11:59 1999
@@ -3,7 +3,7 @@
  *
  *	Zorro Bus Services -- Exported Symbols
  *
- *	Copyright (C) 1998 Geert Uytterhoeven
+ *	Copyright (C) 1998-1999 Geert Uytterhoeven
  */
 
 #include <linux/module.h>
@@ -12,10 +12,7 @@
 
     /* Board configuration */
 
-EXPORT_SYMBOL(zorro_find);
-EXPORT_SYMBOL(zorro_get_board);
-EXPORT_SYMBOL(zorro_config_board);
-EXPORT_SYMBOL(zorro_unconfig_board);
+EXPORT_SYMBOL(zorro_find_device);
 
     /* Z2 memory */
 
--- m68k-2.3.13/drivers/zorro/proc.c.orig	Mon Aug 16 10:12:33 1999
+++ m68k-2.3.13/drivers/zorro/proc.c	Mon Aug 16 14:33:17 1999
@@ -3,7 +3,7 @@
  *
  *	Procfs interface for the Zorro bus.
  *
- *	Copyright (C) 1998 Geert Uytterhoeven
+ *	Copyright (C) 1998-1999 Geert Uytterhoeven
  *
  *	Heavily based on the procfs interface for the PCI bus, which is
  *
@@ -46,7 +46,8 @@
 {
 	struct inode *ino = file->f_dentry->d_inode;
 	struct proc_dir_entry *dp = ino->u.generic_ip;
-	struct ConfigDev *cd = dp->data;
+	struct zorro_dev *dev = dp->data;
+	struct ConfigDev cd;
 	int pos = *ppos;
 
 	if (pos >= sizeof(struct ConfigDev))
@@ -55,7 +56,16 @@
 		nbytes = sizeof(struct ConfigDev);
 	if (pos + nbytes > sizeof(struct ConfigDev))
 		nbytes = sizeof(struct ConfigDev) - pos;
-	if (copy_to_user(buf, cd, nbytes))
+
+	/* Construct a ConfigDev */
+	memset(&cd, 0, sizeof(cd));
+	cd.cd_Rom = dev->rom;
+	cd.cd_SlotAddr = dev->slotaddr;
+	cd.cd_SlotSize = dev->slotsize;
+	cd.cd_BoardAddr = (void *)dev->resource.start;
+	cd.cd_BoardSize = dev->resource.end+1-dev->resource.start;
+
+	if (copy_to_user(buf, &cd, nbytes))
 		return -EFAULT;
 	*ppos += nbytes;
 
@@ -107,20 +117,11 @@
 	int len, cnt;
 
 	for (slot = cnt = 0; slot < zorro_num_autocon && count > cnt; slot++) {
-		struct ConfigDev *cd = &zorro_autocon[slot];
-		u16 manuf = cd->cd_Rom.er_Manufacturer;
-		u8 prod = cd->cd_Rom.er_Product;
-		u8 epc;
-		if (manuf == ZORRO_MANUF(ZORRO_PROD_GVP_EPC_BASE) &&
-		    prod == ZORRO_PROD(ZORRO_PROD_GVP_EPC_BASE)) {
-		    /* GVP quirk */
-		    u32 addr = (u32)cd->cd_BoardAddr;
-		    epc = (*(u16 *)ZTWO_VADDR(addr+0x8000)) & GVP_PRODMASK;
-		} else
-		    epc = 0;
-		len = sprintf(buf, "%02x\t%04x%02x%02x\t%08x\t%08x\t%02x\n",
-			      slot, manuf, prod, epc, (u32)cd->cd_BoardAddr,
-			      cd->cd_BoardSize, cd->cd_Rom.er_Type);
+		struct zorro_dev *dev = &zorro_autocon[slot];
+		len = sprintf(buf, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot,
+			      zorro_get_id(dev), dev->resource.start,
+			      dev->resource.end+1-dev->resource.start,
+			      dev->rom.er_Type);
 		at += len;
 		if (at >= pos) {
 			if (!*start) {
@@ -154,7 +155,7 @@
 		return -ENOMEM;
 	entry->ops = &proc_bus_zorro_inode_operations;
 	entry->data = &zorro_autocon[slot];
-	entry->size = sizeof(struct ConfigDev);
+	entry->size = sizeof(struct zorro_dev);
 	return 0;
 }
 
--- m68k-2.3.13/drivers/zorro/zorro.c.orig	Mon Oct  5 22:48:05 1998
+++ m68k-2.3.13/drivers/zorro/zorro.c	Mon Aug 16 20:33:20 1999
@@ -3,7 +3,7 @@
  *
  *    Zorro Bus Services
  *
- *    Copyright (C) 1995-1998 Geert Uytterhoeven
+ *    Copyright (C) 1995-1999 Geert Uytterhoeven
  *
  *    This file is subject to the terms and conditions of the GNU General Public
  *    License.  See the file COPYING in the main directory of this archive
@@ -20,120 +20,59 @@
 #include <asm/amigahw.h>
 
 
+extern void zorro_namedevice(struct zorro_dev *dev);
+
     /*
-     *  Expansion Devices
+     *  Zorro Expansion Devices
      */
 
 u_int zorro_num_autocon = 0;
-struct ConfigDev zorro_autocon[ZORRO_NUM_AUTO];
-static u32 zorro_autocon_parts[ZORRO_NUM_AUTO] = { 0, };
+struct zorro_dev zorro_autocon[ZORRO_NUM_AUTO];
 
+static struct resource zorro2_exp = {
+    "Zorro II exp", 0x00e80000, 0x00efffff
+};
+static struct resource zorro2_mem = {
+    "Zorro II mem", 0x00200000, 0x009fffff
+};
+static struct resource zorro3_exp = {
+    "Zorro III exp", 0xff000000, 0xffffffff
+};
+static struct resource zorro3_cfg = {
+    "Zorro III cfg", 0x40000000, 0x7fffffff
+};
    
-    /*
-     *  Find the key for the next unconfigured expansion device of a specific
-     *  type.
-     *
-     *  Part is a device specific number (0 <= part <= 31) to allow for the
-     *  independent configuration of independent parts of an expansion board.
-     *  Thanks to Jes Soerensen for this idea!
-     *
-     *  Index is used to specify the first board in the autocon list
-     *  to be tested. It was inserted in order to solve the problem
-     *  with the GVP boards that use the same product code, but
-     *  it should help if there are other companies which use the same
-     *  method as GVP. Drivers for boards which are not using this
-     *  method do not need to think of this - just set index = 0.
-     *
-     *  Example:
-     *
-     *      while ((key = zorro_find(ZORRO_PROD_MY_BOARD, MY_PART, 0))) {
-     *      	cd = zorro_get_board(key);
-     *      	initialise_this_board;
-     *      	zorro_config_board(key, MY_PART);
-     *      }
-     */
 
-u_int zorro_find(zorro_id id, u_int part, u_int index)
+zorro_id zorro_get_id(const struct zorro_dev *dev)
 {
-    u16 manuf = ZORRO_MANUF(id);
-    u8 prod = ZORRO_PROD(id);
-    u8 epc = ZORRO_EPC(id);
-    u_int key;
-    const struct ConfigDev *cd;
-    u32 addr;
-
-    if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
-	return 0;
-
-    if (part > 31) {
-	printk("zorro_find: bad part %d\n", part);
-	return 0;
-    }
-
-    for (key = index+1; key <= zorro_num_autocon; key++) {
-	cd = &zorro_autocon[key-1];
-	addr = (u32)cd->cd_BoardAddr;
-	if ((cd->cd_Rom.er_Manufacturer == manuf) &&
-	    (cd->cd_Rom.er_Product == prod) &&
-	    !(zorro_autocon_parts[key-1] & (1<<part)) &&
-	    (manuf != ZORRO_MANUF(ZORRO_PROD_GVP_EPC_BASE) ||
-	     prod != ZORRO_PROD(ZORRO_PROD_GVP_EPC_BASE) || /* GVP quirk */
-	     (*(u16 *)ZTWO_VADDR(addr+0x8000) & GVP_PRODMASK) == epc))
-	    return key;
-    }
-    return 0;
-}
+    u16 manuf;
+    u8 prod, epc = 0;
 
-
-    /*
-     *  Get the board corresponding to a specific key
-     */
-
-const struct ConfigDev *zorro_get_board(u_int key)
-{
-    if ((key < 1) || (key > zorro_num_autocon)) {
-	printk("zorro_get_board: bad key %d\n", key);
-	return NULL;
+    manuf = dev->rom.er_Manufacturer;
+    prod = dev->rom.er_Product;
+    if (manuf == ZORRO_MANUF(ZORRO_PROD_GVP_EPC_BASE) &&
+	prod == ZORRO_PROD(ZORRO_PROD_GVP_EPC_BASE)) {
+	/* GVP quirk */
+	unsigned long addr = dev->resource.start;
+	epc = *(u16 *)ZTWO_VADDR(addr+0x8000) & GVP_PRODMASK;
     }
-    return &zorro_autocon[key-1];
+    return (manuf << 16) | (prod << 8) | epc;
 }
 
-
-    /*
-     *  Mark a part of a board as configured
-     */
-
-void zorro_config_board(u_int key, u_int part)
+struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from)
 {
-    if ((key < 1) || (key > zorro_num_autocon))
-	printk("zorro_config_board: bad key %d\n", key);
-    else if (part > 31)
-	printk("zorro_config_board: bad part %d\n", part);
-    else if (zorro_autocon_parts[key-1] & (1<<part))
-	printk("zorro_config_board: key %d part %d is already configured\n",
-	       key, part);
-    else
-	zorro_autocon_parts[key-1] |= 1<<part;
-}
+    struct zorro_dev *dev;
 
+    if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
+	return 0;
 
-    /*
-     *  Mark a part of a board as unconfigured
-     *
-     *  This function is mainly intended for the unloading of LKMs
-     */
-
-void zorro_unconfig_board(u_int key, u_int part)
-{
-    if ((key < 1) || (key > zorro_num_autocon))
-	printk("zorro_unconfig_board: bad key %d\n", key);
-    else if (part > 31)
-	printk("zorro_unconfig_board: bad part %d\n", part);
-    else if (!(zorro_autocon_parts[key-1] & (1<<part)))
-	printk("zorro_config_board: key %d part %d is not yet configured\n",
-	       key, part);
-    else
-	zorro_autocon_parts[key-1] &= ~(1<<part);
+    dev = from ? from+1 : &zorro_autocon[0];
+    while (dev < zorro_autocon+zorro_num_autocon) {
+	if (zorro_get_id(dev) == id)
+	    return dev;
+	dev++;
+    }
+    return 0;
 }
 
 
@@ -153,17 +92,16 @@
 u32 zorro_unused_z2ram[4] = { 0, 0, 0, 0 };
 
 
-__initfunc(static void mark_region(u32 addr, u_int size, int flag))
+__initfunc(static void mark_region(unsigned long start, unsigned long end,
+				   int flag))
 {
-    u32 start, end;
+    if (flag)
+	start += Z2RAM_CHUNKMASK;
+    else
+	end += Z2RAM_CHUNKMASK;
+    start &= ~Z2RAM_CHUNKMASK;
+    end &= ~Z2RAM_CHUNKMASK;
 
-    if (flag) {
-	start = (addr+Z2RAM_CHUNKMASK) & ~Z2RAM_CHUNKMASK;
-	end = (addr+size) & ~Z2RAM_CHUNKMASK;
-    } else {
-	start = addr & ~Z2RAM_CHUNKMASK;
-	end = (addr+size+Z2RAM_CHUNKMASK) & ~Z2RAM_CHUNKMASK;
-    }
     if (end <= Z2RAM_START || start >= Z2RAM_END)
 	return;
     start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START;
@@ -185,6 +123,7 @@
 
 __initfunc(void zorro_init(void))
 {
+    struct zorro_dev *dev;
     u_int i;
 
     if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO)) {
@@ -195,17 +134,32 @@
     printk("Zorro: Probing AutoConfig expansion devices: %d device%s\n",
 	   zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
 
+    /* Request the resources */
+    request_resource(&iomem_resource, &zorro2_exp);
+    request_resource(&iomem_resource, &zorro2_mem);
+    if (AMIGAHW_PRESENT(ZORRO3)) {
+	request_resource(&iomem_resource, &zorro3_exp);
+	request_resource(&iomem_resource, &zorro3_cfg);
+    }
+    for (i = 0; i < zorro_num_autocon; i++) {
+	dev = &zorro_autocon[i];
+	dev->resource.name = dev->name;
+	zorro_namedevice(dev);
+	request_resource(&iomem_resource, &dev->resource);
+    }
+
     /* Mark all available Zorro II memory */
     for (i = 0; i < zorro_num_autocon; i++) {
-	const struct ConfigDev *cd = &zorro_autocon[i];
-	if (cd->cd_Rom.er_Type & ERTF_MEMLIST)
-	    mark_region((u32)cd->cd_BoardAddr, cd->cd_BoardSize, 1);
+	dev = &zorro_autocon[i];
+	if (dev->rom.er_Type & ERTF_MEMLIST)
+	    mark_region(dev->resource.start, dev->resource.end+1, 1);
     }
 
     /* Unmark all used Zorro II memory */
     for (i = 0; i < m68k_num_memory; i++)
 	if (m68k_memory[i].addr < 16*1024*1024)
-	    mark_region(m68k_memory[i].addr, m68k_memory[i].size, 0);
+	    mark_region(m68k_memory[i].addr,
+			m68k_memory[i].addr+m68k_memory[i].size, 0);
 
 #ifdef CONFIG_PROC_FS
     zorro_proc_init();
--- m68k-2.3.13/drivers/zorro/names.c.orig	Mon Aug 16 13:09:26 1999
+++ m68k-2.3.13/drivers/zorro/names.c	Mon Aug 16 13:38:11 1999
@@ -0,0 +1,84 @@
+/*
+ *    $Id: zorro.c,v 1.1.2.1 1998/06/07 23:21:02 geert Exp $
+ *
+ *    Zorro Expansion Device Names
+ *
+ *    Copyright (C) 1999 Geert Uytterhoeven
+ *
+ *    This file is subject to the terms and conditions of the GNU General Public
+ *    License.  See the file COPYING in the main directory of this archive
+ *    for more details.
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/zorro.h>
+
+
+    /*
+     *  Just for reference, these are the boards we have a driver for in the
+     *  kernel:
+     *
+     *  ZORRO_PROD_AMERISTAR_A2065
+     *  ZORRO_PROD_BSC_FRAMEMASTER_II
+     *  ZORRO_PROD_BSC_MULTIFACE_III
+     *  ZORRO_PROD_BSC_OKTAGON_2008
+     *  ZORRO_PROD_CBM_A2065_1
+     *  ZORRO_PROD_CBM_A2065_2
+     *  ZORRO_PROD_CBM_A4091_1
+     *  ZORRO_PROD_CBM_A4091_2
+     *  ZORRO_PROD_CBM_A590_A2091_1
+     *  ZORRO_PROD_CBM_A590_A2091_2
+     *  ZORRO_PROD_GVP_A1291
+     *  ZORRO_PROD_GVP_A530_SCSI
+     *  ZORRO_PROD_GVP_COMBO_030_R3_SCSI
+     *  ZORRO_PROD_GVP_COMBO_030_R4_SCSI
+     *  ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_RAM
+     *  ZORRO_PROD_GVP_EGS_28_24_SPECTRUM_REG
+     *  ZORRO_PROD_GVP_GFORCE_030_SCSI
+     *  ZORRO_PROD_GVP_GFORCE_040_060
+     *  ZORRO_PROD_GVP_GFORCE_040_1
+     *  ZORRO_PROD_GVP_GFORCE_040_SCSI_1
+     *  ZORRO_PROD_GVP_IO_EXTENDER
+     *  ZORRO_PROD_GVP_SERIES_II
+     *  ZORRO_PROD_HELFRICH_PICCOLO_RAM
+     *  ZORRO_PROD_HELFRICH_PICCOLO_REG
+     *  ZORRO_PROD_HELFRICH_RAINBOW_II
+     *  ZORRO_PROD_HELFRICH_SD64_RAM
+     *  ZORRO_PROD_HELFRICH_SD64_REG
+     *  ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET
+     *  ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA
+     *  ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL
+     *  ZORRO_PROD_MACROSYSTEMS_RETINA_Z3
+     *  ZORRO_PROD_MACROSYSTEMS_WARP_ENGINE_40xx
+     *  ZORRO_PROD_PHASE5_BLIZZARD_1220_CYBERSTORM
+     *  ZORRO_PROD_PHASE5_BLIZZARD_1230_II_FASTLANE_Z3_CYBERSCSI_CYBERSTORM060
+     *  ZORRO_PROD_PHASE5_BLIZZARD_1230_IV_1260
+     *  ZORRO_PROD_PHASE5_BLIZZARD_2060
+     *  ZORRO_PROD_PHASE5_BLIZZARD_603E_PLUS
+     *  ZORRO_PROD_PHASE5_CYBERSTORM_MK_II
+     *  ZORRO_PROD_PHASE5_CYBERVISION64
+     *  ZORRO_PROD_PHASE5_CYBERVISION64_3D
+     *  ZORRO_PROD_VILLAGE_TRONIC_ARIADNE
+     *  ZORRO_PROD_VILLAGE_TRONIC_ARIADNE2
+     *  ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_RAM
+     *  ZORRO_PROD_VILLAGE_TRONIC_PICASSO_II_II_PLUS_REG
+     *  ZORRO_PROD_VILLAGE_TRONIC_PICASSO_IV_Z3
+     *
+     *  And I guess these are automagically supported as well :-)
+     *
+     *  ZORRO_PROD_CBM_A560_RAM
+     *  ZORRO_PROD_CBM_A590_A2052_A2058_A2091
+     */
+
+void __init zorro_namedevice(struct zorro_dev *dev)
+{
+    zorro_id id = zorro_get_id(dev);
+
+    /*
+     *  Nah, we're not that stupid to put name databases in the kernel ;-)
+     */
+    sprintf(dev->name, "Zorro<%04x> %08x", dev->slotaddr, id);
+}
+
--- m68k-2.3.13/drivers/zorro/Makefile.orig	Thu Jul 30 20:10:22 1998
+++ m68k-2.3.13/drivers/zorro/Makefile	Mon Aug 16 13:11:59 1999
@@ -19,10 +19,10 @@
 ifeq ($(CONFIG_MODULES),y)
 O_TARGET = zorro_syms.o
 OX_OBJS  = zorrosyms.o
-O_OBJS   = zorro.o
+O_OBJS   = zorro.o names.o
 L_OBJS   := zorro_syms.o
 else
-L_OBJS   := zorro.o
+L_OBJS   := zorro.o names.o
 endif
 
 ifdef CONFIG_PROC_FS
--- m68k-2.3.13/include/linux/zorro.h.orig	Thu Feb 25 19:02:12 1999
+++ m68k-2.3.13/include/linux/zorro.h	Mon Aug 16 13:11:59 1999
@@ -1,7 +1,7 @@
 /*
  *  linux/zorro.h -- Amiga AutoConfig (Zorro) Bus Definitions
  *
- *  Copyright (C) 1995-1998 Geert Uytterhoeven
+ *  Copyright (C) 1995-1999 Geert Uytterhoeven
  *
  *  This file is subject to the terms and conditions of the GNU General Public
  *  License.  See the file COPYING in the main directory of this archive
@@ -694,8 +694,18 @@
 
 #ifdef __KERNEL__
 
+#include <linux/ioport.h>
+
+struct zorro_dev {
+    struct ExpansionRom rom;
+    u16 slotaddr;
+    u16 slotsize;
+    char name[48];
+    struct resource resource;
+};
+
 extern unsigned int zorro_num_autocon;	/* # of autoconfig devices found */
-extern struct ConfigDev zorro_autocon[ZORRO_NUM_AUTO];
+extern struct zorro_dev zorro_autocon[ZORRO_NUM_AUTO];
 
 
     /*
@@ -705,10 +715,14 @@
 extern void zorro_init(void);
 extern void zorro_proc_init(void);
 
-extern unsigned int zorro_find(zorro_id id, unsigned int part, unsigned int index);
-extern const struct ConfigDev *zorro_get_board(unsigned int key);
-extern void zorro_config_board(unsigned int key, unsigned int part);
-extern void zorro_unconfig_board(unsigned int key, unsigned int part);
+extern zorro_id zorro_get_id(const struct zorro_dev *dev);
+extern struct zorro_dev *zorro_find_device(zorro_id id,
+					   struct zorro_dev *from);
+
+#define zorro_request_region(start,n,name) \
+    __request_region(&iomem_resource, (start), (n), (name))
+#define zorro_release_region(start,n) \
+    __release_region(&iomem_resource, (start), (n))
 
 
     /*
--- m68k-2.3.13/include/asm-m68k/amigahw.h.orig	Wed Sep  2 18:39:18 1998
+++ m68k-2.3.13/include/asm-m68k/amigahw.h	Mon Aug 16 13:13:21 1999
@@ -281,7 +281,7 @@
 #define CHIP_PHYSADDR	    (0x000000)
 #define chipaddr ((unsigned long)(zTwoBase + CHIP_PHYSADDR))
 void amiga_chip_init (void);
-void *amiga_chip_alloc (long size);
+void *amiga_chip_alloc (long size, const char *name);
 void amiga_chip_free (void *);
 unsigned long amiga_chip_avail( void ); /*MILAN*/
 

dmesg:
Linux version 2.3.13 (geert@callisto) (gcc version 2.7.2.3) #14 Mon Aug 16 21:13:37 CEST 1999
Amiga hardware found: [A4000] VIDEO BLITTER AUDIO FLOPPY A4000_IDE KEYBOARD MOUSE SERIAL PARALLEL A3000_CLK CHIP_RAM PAULA LISA ALICE_PAL ZORRO3 
kmem_alloc: NULL ptr (name=unknown)
amiga_chip_alloc: region of size 131072 at 001dfff8 is busy
kmem_alloc: NULL ptr (name=unknown)
amiga_chip_alloc: region of size 24 at 001dffd0 is busy
Console: colour dummy device 80x25
Calibrating delay loop... 16.59 BogoMIPS
Memory: 11108k/12288k available (696k kernel code, 432k data, 52k init)
Buffer-cache hash table entries: 1024 (order: 0, 4096 bytes)
Page-cache hash table entries: 4096 (order: 2, 16384 bytes)
kmem_create: Forcing size word alignment - kiobuf
kmem_create: Forcing size word alignment - filp
VFS: Diskquotas version dquot_6.4.0 initialized
kmem_create: Forcing size word alignment - dquot
POSIX conformance testing by UNIFIX
Zorro: Probing AutoConfig expansion devices: 1 device
Linux NET4.0 for Linux 2.3
Based upon Swansea University Computer Society NET3.039
kmem_create: Forcing size word alignment - skbuff_head_cache
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP
TCP: Hash tables configured (established 32768 bind 32768)
Starting kswapd v1.6
Console: switching to colour frame buffer device 80x50
fb0: Amiga AGA frame buffer device, using 1280K of video memory
M68K Serial driver version 1.01
ttyS0 at 0x80dff018: Amiga builtin
RAM disk driver initialized:  16 RAM disks of 4096K size
Uniform Multi-Platform E-IDE driver Revision: 6.20
ide0: Gayle IDE interface (A4000 style)
hda: QUANTUM FIREBALL1080A, ATA DISK drive
hdb: Conner Peripherals 545MB - CP30544, ATA DISK drive
ide0 at 80dd2020 on irq 0x0000000c
hda: QUANTUM FIREBALL1080A, 1039MB w/83kB Cache, CHS=2112/16/63
hdb: Conner Peripherals 545MB - CP30544, 520MB w/256kB Cache, CHS=1057/16/63
Partition check:
 hda: RDSK hda1 hda2 hda3 hda4 hda5 hda6
 hdb: RDSK hdb1 hdb2
VFS: Mounted root (ext2 filesystem) readonly.

Greetings,

						Geert

--
Geert Uytterhoeven                    Geert.Uytterhoeven@thomas.kotnet.org
Wavelets, Linux/{m68k~Amiga,PPC~CHRP} http://www.thomas.kotnet.org/~geert/
KotNET@Thomas Network Administration -- Make your bed part of Cyberspace!!

