Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  *    Zorro Bus Services
0003  *
0004  *    Copyright (C) 1995-2003 Geert Uytterhoeven
0005  *
0006  *    This file is subject to the terms and conditions of the GNU General Public
0007  *    License.  See the file COPYING in the main directory of this archive
0008  *    for more details.
0009  */
0010 
0011 #include <linux/module.h>
0012 #include <linux/types.h>
0013 #include <linux/kernel.h>
0014 #include <linux/init.h>
0015 #include <linux/zorro.h>
0016 #include <linux/bitops.h>
0017 #include <linux/string.h>
0018 #include <linux/platform_device.h>
0019 #include <linux/dma-mapping.h>
0020 #include <linux/slab.h>
0021 
0022 #include <asm/byteorder.h>
0023 #include <asm/setup.h>
0024 #include <asm/amigahw.h>
0025 
0026 #include "zorro.h"
0027 
0028 
0029     /*
0030      *  Zorro Expansion Devices
0031      */
0032 
0033 unsigned int zorro_num_autocon;
0034 struct zorro_dev_init zorro_autocon_init[ZORRO_NUM_AUTO] __initdata;
0035 struct zorro_dev *zorro_autocon;
0036 
0037 
0038     /*
0039      *  Zorro bus
0040      */
0041 
0042 struct zorro_bus {
0043     struct device dev;
0044     struct zorro_dev devices[];
0045 };
0046 
0047 
0048     /*
0049      *  Find Zorro Devices
0050      */
0051 
0052 struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from)
0053 {
0054     struct zorro_dev *z;
0055 
0056     if (!zorro_num_autocon)
0057         return NULL;
0058 
0059     for (z = from ? from+1 : &zorro_autocon[0];
0060          z < zorro_autocon+zorro_num_autocon;
0061          z++)
0062         if (id == ZORRO_WILDCARD || id == z->id)
0063             return z;
0064     return NULL;
0065 }
0066 EXPORT_SYMBOL(zorro_find_device);
0067 
0068 
0069     /*
0070      *  Bitmask indicating portions of available Zorro II RAM that are unused
0071      *  by the system. Every bit represents a 64K chunk, for a maximum of 8MB
0072      *  (128 chunks, physical 0x00200000-0x009fffff).
0073      *
0074      *  If you want to use (= allocate) portions of this RAM, you should clear
0075      *  the corresponding bits.
0076      *
0077      *  Possible uses:
0078      *      - z2ram device
0079      *      - SCSI DMA bounce buffers
0080      *
0081      *  FIXME: use the normal resource management
0082      */
0083 
0084 DECLARE_BITMAP(zorro_unused_z2ram, 128);
0085 EXPORT_SYMBOL(zorro_unused_z2ram);
0086 
0087 
0088 static void __init mark_region(unsigned long start, unsigned long end,
0089                    int flag)
0090 {
0091     if (flag)
0092         start += Z2RAM_CHUNKMASK;
0093     else
0094         end += Z2RAM_CHUNKMASK;
0095     start &= ~Z2RAM_CHUNKMASK;
0096     end &= ~Z2RAM_CHUNKMASK;
0097 
0098     if (end <= Z2RAM_START || start >= Z2RAM_END)
0099         return;
0100     start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START;
0101     end = end > Z2RAM_END ? Z2RAM_SIZE : end-Z2RAM_START;
0102     while (start < end) {
0103         u32 chunk = start>>Z2RAM_CHUNKSHIFT;
0104 
0105         if (flag)
0106             set_bit(chunk, zorro_unused_z2ram);
0107         else
0108             clear_bit(chunk, zorro_unused_z2ram);
0109         start += Z2RAM_CHUNKSIZE;
0110     }
0111 }
0112 
0113 
0114 static struct resource __init *zorro_find_parent_resource(
0115     struct platform_device *bridge, struct zorro_dev *z)
0116 {
0117     int i;
0118 
0119     for (i = 0; i < bridge->num_resources; i++) {
0120         struct resource *r = &bridge->resource[i];
0121 
0122         if (zorro_resource_start(z) >= r->start &&
0123             zorro_resource_end(z) <= r->end)
0124             return r;
0125     }
0126     return &iomem_resource;
0127 }
0128 
0129 
0130 
0131 static int __init amiga_zorro_probe(struct platform_device *pdev)
0132 {
0133     struct zorro_bus *bus;
0134     struct zorro_dev_init *zi;
0135     struct zorro_dev *z;
0136     struct resource *r;
0137     unsigned int i;
0138     int error;
0139 
0140     /* Initialize the Zorro bus */
0141     bus = kzalloc(struct_size(bus, devices, zorro_num_autocon),
0142               GFP_KERNEL);
0143     if (!bus)
0144         return -ENOMEM;
0145 
0146     zorro_autocon = bus->devices;
0147     bus->dev.parent = &pdev->dev;
0148     dev_set_name(&bus->dev, zorro_bus_type.name);
0149     error = device_register(&bus->dev);
0150     if (error) {
0151         pr_err("Zorro: Error registering zorro_bus\n");
0152         put_device(&bus->dev);
0153         kfree(bus);
0154         return error;
0155     }
0156     platform_set_drvdata(pdev, bus);
0157 
0158     pr_info("Zorro: Probing AutoConfig expansion devices: %u device%s\n",
0159          zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
0160 
0161     /* First identify all devices ... */
0162     for (i = 0; i < zorro_num_autocon; i++) {
0163         zi = &zorro_autocon_init[i];
0164         z = &zorro_autocon[i];
0165 
0166         z->rom = zi->rom;
0167         z->id = (be16_to_cpu(z->rom.er_Manufacturer) << 16) |
0168             (z->rom.er_Product << 8);
0169         if (z->id == ZORRO_PROD_GVP_EPC_BASE) {
0170             /* GVP quirk */
0171             unsigned long magic = zi->boardaddr + 0x8000;
0172 
0173             z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK;
0174         }
0175         z->slotaddr = zi->slotaddr;
0176         z->slotsize = zi->slotsize;
0177         sprintf(z->name, "Zorro device %08x", z->id);
0178         zorro_name_device(z);
0179         z->resource.start = zi->boardaddr;
0180         z->resource.end = zi->boardaddr + zi->boardsize - 1;
0181         z->resource.name = z->name;
0182         r = zorro_find_parent_resource(pdev, z);
0183         error = request_resource(r, &z->resource);
0184         if (error && !(z->rom.er_Type & ERTF_MEMLIST))
0185             dev_err(&bus->dev,
0186                 "Address space collision on device %s %pR\n",
0187                 z->name, &z->resource);
0188         z->dev.parent = &bus->dev;
0189         z->dev.bus = &zorro_bus_type;
0190         z->dev.id = i;
0191         switch (z->rom.er_Type & ERT_TYPEMASK) {
0192         case ERT_ZORROIII:
0193             z->dev.coherent_dma_mask = DMA_BIT_MASK(32);
0194             break;
0195 
0196         case ERT_ZORROII:
0197         default:
0198             z->dev.coherent_dma_mask = DMA_BIT_MASK(24);
0199             break;
0200         }
0201         z->dev.dma_mask = &z->dev.coherent_dma_mask;
0202     }
0203 
0204     /* ... then register them */
0205     for (i = 0; i < zorro_num_autocon; i++) {
0206         z = &zorro_autocon[i];
0207         error = device_register(&z->dev);
0208         if (error) {
0209             dev_err(&bus->dev, "Error registering device %s\n",
0210                 z->name);
0211             put_device(&z->dev);
0212             continue;
0213         }
0214     }
0215 
0216     /* Mark all available Zorro II memory */
0217     zorro_for_each_dev(z) {
0218         if (z->rom.er_Type & ERTF_MEMLIST)
0219             mark_region(zorro_resource_start(z),
0220                     zorro_resource_end(z)+1, 1);
0221     }
0222 
0223     /* Unmark all used Zorro II memory */
0224     for (i = 0; i < m68k_num_memory; i++)
0225         if (m68k_memory[i].addr < 16*1024*1024)
0226             mark_region(m68k_memory[i].addr,
0227                     m68k_memory[i].addr+m68k_memory[i].size,
0228                     0);
0229 
0230     return 0;
0231 }
0232 
0233 static struct platform_driver amiga_zorro_driver = {
0234     .driver   = {
0235         .name   = "amiga-zorro",
0236     },
0237 };
0238 
0239 static int __init amiga_zorro_init(void)
0240 {
0241     return platform_driver_probe(&amiga_zorro_driver, amiga_zorro_probe);
0242 }
0243 
0244 module_init(amiga_zorro_init);
0245 
0246 MODULE_LICENSE("GPL");