1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654 |
- /*
- * VME Bridge Framework
- *
- * Author: Martyn Welch <[email protected]>
- * Copyright 2008 GE Intelligent Platforms Embedded Systems, Inc.
- *
- * Based on work by Tom Armistead and Ajit Prem
- * Copyright 2004 Motorola Inc.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- */
- #include <linux/init.h>
- #include <linux/export.h>
- #include <linux/mm.h>
- #include <linux/types.h>
- #include <linux/kernel.h>
- #include <linux/errno.h>
- #include <linux/pci.h>
- #include <linux/poll.h>
- #include <linux/highmem.h>
- #include <linux/interrupt.h>
- #include <linux/pagemap.h>
- #include <linux/device.h>
- #include <linux/dma-mapping.h>
- #include <linux/syscalls.h>
- #include <linux/mutex.h>
- #include <linux/spinlock.h>
- #include <linux/slab.h>
- #include <linux/vme.h>
- #include "vme_bridge.h"
- /* Bitmask and list of registered buses both protected by common mutex */
- static unsigned int vme_bus_numbers;
- static LIST_HEAD(vme_bus_list);
- static DEFINE_MUTEX(vme_buses_lock);
- static int __init vme_init(void);
- static struct vme_dev *dev_to_vme_dev(struct device *dev)
- {
- return container_of(dev, struct vme_dev, dev);
- }
- /*
- * Find the bridge that the resource is associated with.
- */
- static struct vme_bridge *find_bridge(struct vme_resource *resource)
- {
- /* Get list to search */
- switch (resource->type) {
- case VME_MASTER:
- return list_entry(resource->entry, struct vme_master_resource,
- list)->parent;
- break;
- case VME_SLAVE:
- return list_entry(resource->entry, struct vme_slave_resource,
- list)->parent;
- break;
- case VME_DMA:
- return list_entry(resource->entry, struct vme_dma_resource,
- list)->parent;
- break;
- case VME_LM:
- return list_entry(resource->entry, struct vme_lm_resource,
- list)->parent;
- break;
- default:
- printk(KERN_ERR "Unknown resource type\n");
- return NULL;
- break;
- }
- }
- /*
- * Allocate a contiguous block of memory for use by the driver. This is used to
- * create the buffers for the slave windows.
- */
- void *vme_alloc_consistent(struct vme_resource *resource, size_t size,
- dma_addr_t *dma)
- {
- struct vme_bridge *bridge;
- if (resource == NULL) {
- printk(KERN_ERR "No resource\n");
- return NULL;
- }
- bridge = find_bridge(resource);
- if (bridge == NULL) {
- printk(KERN_ERR "Can't find bridge\n");
- return NULL;
- }
- if (bridge->parent == NULL) {
- printk(KERN_ERR "Dev entry NULL for bridge %s\n", bridge->name);
- return NULL;
- }
- if (bridge->alloc_consistent == NULL) {
- printk(KERN_ERR "alloc_consistent not supported by bridge %s\n",
- bridge->name);
- return NULL;
- }
- return bridge->alloc_consistent(bridge->parent, size, dma);
- }
- EXPORT_SYMBOL(vme_alloc_consistent);
- /*
- * Free previously allocated contiguous block of memory.
- */
- void vme_free_consistent(struct vme_resource *resource, size_t size,
- void *vaddr, dma_addr_t dma)
- {
- struct vme_bridge *bridge;
- if (resource == NULL) {
- printk(KERN_ERR "No resource\n");
- return;
- }
- bridge = find_bridge(resource);
- if (bridge == NULL) {
- printk(KERN_ERR "Can't find bridge\n");
- return;
- }
- if (bridge->parent == NULL) {
- printk(KERN_ERR "Dev entry NULL for bridge %s\n", bridge->name);
- return;
- }
- if (bridge->free_consistent == NULL) {
- printk(KERN_ERR "free_consistent not supported by bridge %s\n",
- bridge->name);
- return;
- }
- bridge->free_consistent(bridge->parent, size, vaddr, dma);
- }
- EXPORT_SYMBOL(vme_free_consistent);
- size_t vme_get_size(struct vme_resource *resource)
- {
- int enabled, retval;
- unsigned long long base, size;
- dma_addr_t buf_base;
- u32 aspace, cycle, dwidth;
- switch (resource->type) {
- case VME_MASTER:
- retval = vme_master_get(resource, &enabled, &base, &size,
- &aspace, &cycle, &dwidth);
- if (retval)
- return 0;
- return size;
- break;
- case VME_SLAVE:
- retval = vme_slave_get(resource, &enabled, &base, &size,
- &buf_base, &aspace, &cycle);
- if (retval)
- return 0;
- return size;
- break;
- case VME_DMA:
- return 0;
- break;
- default:
- printk(KERN_ERR "Unknown resource type\n");
- return 0;
- break;
- }
- }
- EXPORT_SYMBOL(vme_get_size);
- int vme_check_window(u32 aspace, unsigned long long vme_base,
- unsigned long long size)
- {
- int retval = 0;
- switch (aspace) {
- case VME_A16:
- if (((vme_base + size) > VME_A16_MAX) ||
- (vme_base > VME_A16_MAX))
- retval = -EFAULT;
- break;
- case VME_A24:
- if (((vme_base + size) > VME_A24_MAX) ||
- (vme_base > VME_A24_MAX))
- retval = -EFAULT;
- break;
- case VME_A32:
- if (((vme_base + size) > VME_A32_MAX) ||
- (vme_base > VME_A32_MAX))
- retval = -EFAULT;
- break;
- case VME_A64:
- if ((size != 0) && (vme_base > U64_MAX + 1 - size))
- retval = -EFAULT;
- break;
- case VME_CRCSR:
- if (((vme_base + size) > VME_CRCSR_MAX) ||
- (vme_base > VME_CRCSR_MAX))
- retval = -EFAULT;
- break;
- case VME_USER1:
- case VME_USER2:
- case VME_USER3:
- case VME_USER4:
- /* User Defined */
- break;
- default:
- printk(KERN_ERR "Invalid address space\n");
- retval = -EINVAL;
- break;
- }
- return retval;
- }
- EXPORT_SYMBOL(vme_check_window);
- static u32 vme_get_aspace(int am)
- {
- switch (am) {
- case 0x29:
- case 0x2D:
- return VME_A16;
- case 0x38:
- case 0x39:
- case 0x3A:
- case 0x3B:
- case 0x3C:
- case 0x3D:
- case 0x3E:
- case 0x3F:
- return VME_A24;
- case 0x8:
- case 0x9:
- case 0xA:
- case 0xB:
- case 0xC:
- case 0xD:
- case 0xE:
- case 0xF:
- return VME_A32;
- case 0x0:
- case 0x1:
- case 0x3:
- return VME_A64;
- }
- return 0;
- }
- /*
- * Request a slave image with specific attributes, return some unique
- * identifier.
- */
- struct vme_resource *vme_slave_request(struct vme_dev *vdev, u32 address,
- u32 cycle)
- {
- struct vme_bridge *bridge;
- struct list_head *slave_pos = NULL;
- struct vme_slave_resource *allocated_image = NULL;
- struct vme_slave_resource *slave_image = NULL;
- struct vme_resource *resource = NULL;
- bridge = vdev->bridge;
- if (bridge == NULL) {
- printk(KERN_ERR "Can't find VME bus\n");
- goto err_bus;
- }
- /* Loop through slave resources */
- list_for_each(slave_pos, &bridge->slave_resources) {
- slave_image = list_entry(slave_pos,
- struct vme_slave_resource, list);
- if (slave_image == NULL) {
- printk(KERN_ERR "Registered NULL Slave resource\n");
- continue;
- }
- /* Find an unlocked and compatible image */
- mutex_lock(&slave_image->mtx);
- if (((slave_image->address_attr & address) == address) &&
- ((slave_image->cycle_attr & cycle) == cycle) &&
- (slave_image->locked == 0)) {
- slave_image->locked = 1;
- mutex_unlock(&slave_image->mtx);
- allocated_image = slave_image;
- break;
- }
- mutex_unlock(&slave_image->mtx);
- }
- /* No free image */
- if (allocated_image == NULL)
- goto err_image;
- resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL);
- if (resource == NULL) {
- printk(KERN_WARNING "Unable to allocate resource structure\n");
- goto err_alloc;
- }
- resource->type = VME_SLAVE;
- resource->entry = &allocated_image->list;
- return resource;
- err_alloc:
- /* Unlock image */
- mutex_lock(&slave_image->mtx);
- slave_image->locked = 0;
- mutex_unlock(&slave_image->mtx);
- err_image:
- err_bus:
- return NULL;
- }
- EXPORT_SYMBOL(vme_slave_request);
- int vme_slave_set(struct vme_resource *resource, int enabled,
- unsigned long long vme_base, unsigned long long size,
- dma_addr_t buf_base, u32 aspace, u32 cycle)
- {
- struct vme_bridge *bridge = find_bridge(resource);
- struct vme_slave_resource *image;
- int retval;
- if (resource->type != VME_SLAVE) {
- printk(KERN_ERR "Not a slave resource\n");
- return -EINVAL;
- }
- image = list_entry(resource->entry, struct vme_slave_resource, list);
- if (bridge->slave_set == NULL) {
- printk(KERN_ERR "Function not supported\n");
- return -ENOSYS;
- }
- if (!(((image->address_attr & aspace) == aspace) &&
- ((image->cycle_attr & cycle) == cycle))) {
- printk(KERN_ERR "Invalid attributes\n");
- return -EINVAL;
- }
- retval = vme_check_window(aspace, vme_base, size);
- if (retval)
- return retval;
- return bridge->slave_set(image, enabled, vme_base, size, buf_base,
- aspace, cycle);
- }
- EXPORT_SYMBOL(vme_slave_set);
- int vme_slave_get(struct vme_resource *resource, int *enabled,
- unsigned long long *vme_base, unsigned long long *size,
- dma_addr_t *buf_base, u32 *aspace, u32 *cycle)
- {
- struct vme_bridge *bridge = find_bridge(resource);
- struct vme_slave_resource *image;
- if (resource->type != VME_SLAVE) {
- printk(KERN_ERR "Not a slave resource\n");
- return -EINVAL;
- }
- image = list_entry(resource->entry, struct vme_slave_resource, list);
- if (bridge->slave_get == NULL) {
- printk(KERN_ERR "vme_slave_get not supported\n");
- return -EINVAL;
- }
- return bridge->slave_get(image, enabled, vme_base, size, buf_base,
- aspace, cycle);
- }
- EXPORT_SYMBOL(vme_slave_get);
- void vme_slave_free(struct vme_resource *resource)
- {
- struct vme_slave_resource *slave_image;
- if (resource->type != VME_SLAVE) {
- printk(KERN_ERR "Not a slave resource\n");
- return;
- }
- slave_image = list_entry(resource->entry, struct vme_slave_resource,
- list);
- if (slave_image == NULL) {
- printk(KERN_ERR "Can't find slave resource\n");
- return;
- }
- /* Unlock image */
- mutex_lock(&slave_image->mtx);
- if (slave_image->locked == 0)
- printk(KERN_ERR "Image is already free\n");
- slave_image->locked = 0;
- mutex_unlock(&slave_image->mtx);
- /* Free up resource memory */
- kfree(resource);
- }
- EXPORT_SYMBOL(vme_slave_free);
- /*
- * Request a master image with specific attributes, return some unique
- * identifier.
- */
- struct vme_resource *vme_master_request(struct vme_dev *vdev, u32 address,
- u32 cycle, u32 dwidth)
- {
- struct vme_bridge *bridge;
- struct list_head *master_pos = NULL;
- struct vme_master_resource *allocated_image = NULL;
- struct vme_master_resource *master_image = NULL;
- struct vme_resource *resource = NULL;
- bridge = vdev->bridge;
- if (bridge == NULL) {
- printk(KERN_ERR "Can't find VME bus\n");
- goto err_bus;
- }
- /* Loop through master resources */
- list_for_each(master_pos, &bridge->master_resources) {
- master_image = list_entry(master_pos,
- struct vme_master_resource, list);
- if (master_image == NULL) {
- printk(KERN_WARNING "Registered NULL master resource\n");
- continue;
- }
- /* Find an unlocked and compatible image */
- spin_lock(&master_image->lock);
- if (((master_image->address_attr & address) == address) &&
- ((master_image->cycle_attr & cycle) == cycle) &&
- ((master_image->width_attr & dwidth) == dwidth) &&
- (master_image->locked == 0)) {
- master_image->locked = 1;
- spin_unlock(&master_image->lock);
- allocated_image = master_image;
- break;
- }
- spin_unlock(&master_image->lock);
- }
- /* Check to see if we found a resource */
- if (allocated_image == NULL) {
- printk(KERN_ERR "Can't find a suitable resource\n");
- goto err_image;
- }
- resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL);
- if (resource == NULL) {
- printk(KERN_ERR "Unable to allocate resource structure\n");
- goto err_alloc;
- }
- resource->type = VME_MASTER;
- resource->entry = &allocated_image->list;
- return resource;
- err_alloc:
- /* Unlock image */
- spin_lock(&master_image->lock);
- master_image->locked = 0;
- spin_unlock(&master_image->lock);
- err_image:
- err_bus:
- return NULL;
- }
- EXPORT_SYMBOL(vme_master_request);
- int vme_master_set(struct vme_resource *resource, int enabled,
- unsigned long long vme_base, unsigned long long size, u32 aspace,
- u32 cycle, u32 dwidth)
- {
- struct vme_bridge *bridge = find_bridge(resource);
- struct vme_master_resource *image;
- int retval;
- if (resource->type != VME_MASTER) {
- printk(KERN_ERR "Not a master resource\n");
- return -EINVAL;
- }
- image = list_entry(resource->entry, struct vme_master_resource, list);
- if (bridge->master_set == NULL) {
- printk(KERN_WARNING "vme_master_set not supported\n");
- return -EINVAL;
- }
- if (!(((image->address_attr & aspace) == aspace) &&
- ((image->cycle_attr & cycle) == cycle) &&
- ((image->width_attr & dwidth) == dwidth))) {
- printk(KERN_WARNING "Invalid attributes\n");
- return -EINVAL;
- }
- retval = vme_check_window(aspace, vme_base, size);
- if (retval)
- return retval;
- return bridge->master_set(image, enabled, vme_base, size, aspace,
- cycle, dwidth);
- }
- EXPORT_SYMBOL(vme_master_set);
- int vme_master_get(struct vme_resource *resource, int *enabled,
- unsigned long long *vme_base, unsigned long long *size, u32 *aspace,
- u32 *cycle, u32 *dwidth)
- {
- struct vme_bridge *bridge = find_bridge(resource);
- struct vme_master_resource *image;
- if (resource->type != VME_MASTER) {
- printk(KERN_ERR "Not a master resource\n");
- return -EINVAL;
- }
- image = list_entry(resource->entry, struct vme_master_resource, list);
- if (bridge->master_get == NULL) {
- printk(KERN_WARNING "%s not supported\n", __func__);
- return -EINVAL;
- }
- return bridge->master_get(image, enabled, vme_base, size, aspace,
- cycle, dwidth);
- }
- EXPORT_SYMBOL(vme_master_get);
- /*
- * Read data out of VME space into a buffer.
- */
- ssize_t vme_master_read(struct vme_resource *resource, void *buf, size_t count,
- loff_t offset)
- {
- struct vme_bridge *bridge = find_bridge(resource);
- struct vme_master_resource *image;
- size_t length;
- if (bridge->master_read == NULL) {
- printk(KERN_WARNING "Reading from resource not supported\n");
- return -EINVAL;
- }
- if (resource->type != VME_MASTER) {
- printk(KERN_ERR "Not a master resource\n");
- return -EINVAL;
- }
- image = list_entry(resource->entry, struct vme_master_resource, list);
- length = vme_get_size(resource);
- if (offset > length) {
- printk(KERN_WARNING "Invalid Offset\n");
- return -EFAULT;
- }
- if ((offset + count) > length)
- count = length - offset;
- return bridge->master_read(image, buf, count, offset);
- }
- EXPORT_SYMBOL(vme_master_read);
- /*
- * Write data out to VME space from a buffer.
- */
- ssize_t vme_master_write(struct vme_resource *resource, void *buf,
- size_t count, loff_t offset)
- {
- struct vme_bridge *bridge = find_bridge(resource);
- struct vme_master_resource *image;
- size_t length;
- if (bridge->master_write == NULL) {
- printk(KERN_WARNING "Writing to resource not supported\n");
- return -EINVAL;
- }
- if (resource->type != VME_MASTER) {
- printk(KERN_ERR "Not a master resource\n");
- return -EINVAL;
- }
- image = list_entry(resource->entry, struct vme_master_resource, list);
- length = vme_get_size(resource);
- if (offset > length) {
- printk(KERN_WARNING "Invalid Offset\n");
- return -EFAULT;
- }
- if ((offset + count) > length)
- count = length - offset;
- return bridge->master_write(image, buf, count, offset);
- }
- EXPORT_SYMBOL(vme_master_write);
- /*
- * Perform RMW cycle to provided location.
- */
- unsigned int vme_master_rmw(struct vme_resource *resource, unsigned int mask,
- unsigned int compare, unsigned int swap, loff_t offset)
- {
- struct vme_bridge *bridge = find_bridge(resource);
- struct vme_master_resource *image;
- if (bridge->master_rmw == NULL) {
- printk(KERN_WARNING "Writing to resource not supported\n");
- return -EINVAL;
- }
- if (resource->type != VME_MASTER) {
- printk(KERN_ERR "Not a master resource\n");
- return -EINVAL;
- }
- image = list_entry(resource->entry, struct vme_master_resource, list);
- return bridge->master_rmw(image, mask, compare, swap, offset);
- }
- EXPORT_SYMBOL(vme_master_rmw);
- int vme_master_mmap(struct vme_resource *resource, struct vm_area_struct *vma)
- {
- struct vme_master_resource *image;
- phys_addr_t phys_addr;
- unsigned long vma_size;
- if (resource->type != VME_MASTER) {
- pr_err("Not a master resource\n");
- return -EINVAL;
- }
- image = list_entry(resource->entry, struct vme_master_resource, list);
- phys_addr = image->bus_resource.start + (vma->vm_pgoff << PAGE_SHIFT);
- vma_size = vma->vm_end - vma->vm_start;
- if (phys_addr + vma_size > image->bus_resource.end + 1) {
- pr_err("Map size cannot exceed the window size\n");
- return -EFAULT;
- }
- vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
- return vm_iomap_memory(vma, phys_addr, vma->vm_end - vma->vm_start);
- }
- EXPORT_SYMBOL(vme_master_mmap);
- void vme_master_free(struct vme_resource *resource)
- {
- struct vme_master_resource *master_image;
- if (resource->type != VME_MASTER) {
- printk(KERN_ERR "Not a master resource\n");
- return;
- }
- master_image = list_entry(resource->entry, struct vme_master_resource,
- list);
- if (master_image == NULL) {
- printk(KERN_ERR "Can't find master resource\n");
- return;
- }
- /* Unlock image */
- spin_lock(&master_image->lock);
- if (master_image->locked == 0)
- printk(KERN_ERR "Image is already free\n");
- master_image->locked = 0;
- spin_unlock(&master_image->lock);
- /* Free up resource memory */
- kfree(resource);
- }
- EXPORT_SYMBOL(vme_master_free);
- /*
- * Request a DMA controller with specific attributes, return some unique
- * identifier.
- */
- struct vme_resource *vme_dma_request(struct vme_dev *vdev, u32 route)
- {
- struct vme_bridge *bridge;
- struct list_head *dma_pos = NULL;
- struct vme_dma_resource *allocated_ctrlr = NULL;
- struct vme_dma_resource *dma_ctrlr = NULL;
- struct vme_resource *resource = NULL;
- /* XXX Not checking resource attributes */
- printk(KERN_ERR "No VME resource Attribute tests done\n");
- bridge = vdev->bridge;
- if (bridge == NULL) {
- printk(KERN_ERR "Can't find VME bus\n");
- goto err_bus;
- }
- /* Loop through DMA resources */
- list_for_each(dma_pos, &bridge->dma_resources) {
- dma_ctrlr = list_entry(dma_pos,
- struct vme_dma_resource, list);
- if (dma_ctrlr == NULL) {
- printk(KERN_ERR "Registered NULL DMA resource\n");
- continue;
- }
- /* Find an unlocked and compatible controller */
- mutex_lock(&dma_ctrlr->mtx);
- if (((dma_ctrlr->route_attr & route) == route) &&
- (dma_ctrlr->locked == 0)) {
- dma_ctrlr->locked = 1;
- mutex_unlock(&dma_ctrlr->mtx);
- allocated_ctrlr = dma_ctrlr;
- break;
- }
- mutex_unlock(&dma_ctrlr->mtx);
- }
- /* Check to see if we found a resource */
- if (allocated_ctrlr == NULL)
- goto err_ctrlr;
- resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL);
- if (resource == NULL) {
- printk(KERN_WARNING "Unable to allocate resource structure\n");
- goto err_alloc;
- }
- resource->type = VME_DMA;
- resource->entry = &allocated_ctrlr->list;
- return resource;
- err_alloc:
- /* Unlock image */
- mutex_lock(&dma_ctrlr->mtx);
- dma_ctrlr->locked = 0;
- mutex_unlock(&dma_ctrlr->mtx);
- err_ctrlr:
- err_bus:
- return NULL;
- }
- EXPORT_SYMBOL(vme_dma_request);
- /*
- * Start new list
- */
- struct vme_dma_list *vme_new_dma_list(struct vme_resource *resource)
- {
- struct vme_dma_resource *ctrlr;
- struct vme_dma_list *dma_list;
- if (resource->type != VME_DMA) {
- printk(KERN_ERR "Not a DMA resource\n");
- return NULL;
- }
- ctrlr = list_entry(resource->entry, struct vme_dma_resource, list);
- dma_list = kmalloc(sizeof(struct vme_dma_list), GFP_KERNEL);
- if (dma_list == NULL) {
- printk(KERN_ERR "Unable to allocate memory for new DMA list\n");
- return NULL;
- }
- INIT_LIST_HEAD(&dma_list->entries);
- dma_list->parent = ctrlr;
- mutex_init(&dma_list->mtx);
- return dma_list;
- }
- EXPORT_SYMBOL(vme_new_dma_list);
- /*
- * Create "Pattern" type attributes
- */
- struct vme_dma_attr *vme_dma_pattern_attribute(u32 pattern, u32 type)
- {
- struct vme_dma_attr *attributes;
- struct vme_dma_pattern *pattern_attr;
- attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL);
- if (attributes == NULL) {
- printk(KERN_ERR "Unable to allocate memory for attributes structure\n");
- goto err_attr;
- }
- pattern_attr = kmalloc(sizeof(struct vme_dma_pattern), GFP_KERNEL);
- if (pattern_attr == NULL) {
- printk(KERN_ERR "Unable to allocate memory for pattern attributes\n");
- goto err_pat;
- }
- attributes->type = VME_DMA_PATTERN;
- attributes->private = (void *)pattern_attr;
- pattern_attr->pattern = pattern;
- pattern_attr->type = type;
- return attributes;
- err_pat:
- kfree(attributes);
- err_attr:
- return NULL;
- }
- EXPORT_SYMBOL(vme_dma_pattern_attribute);
- /*
- * Create "PCI" type attributes
- */
- struct vme_dma_attr *vme_dma_pci_attribute(dma_addr_t address)
- {
- struct vme_dma_attr *attributes;
- struct vme_dma_pci *pci_attr;
- /* XXX Run some sanity checks here */
- attributes = kmalloc(sizeof(struct vme_dma_attr), GFP_KERNEL);
- if (attributes == NULL) {
- printk(KERN_ERR "Unable to allocate memory for attributes structure\n");
- goto err_attr;
- }
- pci_attr = kmalloc(sizeof(struct vme_dma_pci), GFP_KERNEL);
- if (pci_attr == NULL) {
- printk(KERN_ERR "Unable to allocate memory for PCI attributes\n");
- goto err_pci;
- }
- attributes->type = VME_DMA_PCI;
- attributes->private = (void *)pci_attr;
- pci_attr->address = address;
- return attributes;
- err_pci:
- kfree(attributes);
- err_attr:
- return NULL;
- }
- EXPORT_SYMBOL(vme_dma_pci_attribute);
- /*
- * Create "VME" type attributes
- */
- struct vme_dma_attr *vme_dma_vme_attribute(unsigned long long address,
- u32 aspace, u32 cycle, u32 dwidth)
- {
- struct vme_dma_attr *attributes;
- struct vme_dma_vme *vme_attr;
- attributes = kmalloc(
- sizeof(struct vme_dma_attr), GFP_KERNEL);
- if (attributes == NULL) {
- printk(KERN_ERR "Unable to allocate memory for attributes structure\n");
- goto err_attr;
- }
- vme_attr = kmalloc(sizeof(struct vme_dma_vme), GFP_KERNEL);
- if (vme_attr == NULL) {
- printk(KERN_ERR "Unable to allocate memory for VME attributes\n");
- goto err_vme;
- }
- attributes->type = VME_DMA_VME;
- attributes->private = (void *)vme_attr;
- vme_attr->address = address;
- vme_attr->aspace = aspace;
- vme_attr->cycle = cycle;
- vme_attr->dwidth = dwidth;
- return attributes;
- err_vme:
- kfree(attributes);
- err_attr:
- return NULL;
- }
- EXPORT_SYMBOL(vme_dma_vme_attribute);
- /*
- * Free attribute
- */
- void vme_dma_free_attribute(struct vme_dma_attr *attributes)
- {
- kfree(attributes->private);
- kfree(attributes);
- }
- EXPORT_SYMBOL(vme_dma_free_attribute);
- int vme_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src,
- struct vme_dma_attr *dest, size_t count)
- {
- struct vme_bridge *bridge = list->parent->parent;
- int retval;
- if (bridge->dma_list_add == NULL) {
- printk(KERN_WARNING "Link List DMA generation not supported\n");
- return -EINVAL;
- }
- if (!mutex_trylock(&list->mtx)) {
- printk(KERN_ERR "Link List already submitted\n");
- return -EINVAL;
- }
- retval = bridge->dma_list_add(list, src, dest, count);
- mutex_unlock(&list->mtx);
- return retval;
- }
- EXPORT_SYMBOL(vme_dma_list_add);
- int vme_dma_list_exec(struct vme_dma_list *list)
- {
- struct vme_bridge *bridge = list->parent->parent;
- int retval;
- if (bridge->dma_list_exec == NULL) {
- printk(KERN_ERR "Link List DMA execution not supported\n");
- return -EINVAL;
- }
- mutex_lock(&list->mtx);
- retval = bridge->dma_list_exec(list);
- mutex_unlock(&list->mtx);
- return retval;
- }
- EXPORT_SYMBOL(vme_dma_list_exec);
- int vme_dma_list_free(struct vme_dma_list *list)
- {
- struct vme_bridge *bridge = list->parent->parent;
- int retval;
- if (bridge->dma_list_empty == NULL) {
- printk(KERN_WARNING "Emptying of Link Lists not supported\n");
- return -EINVAL;
- }
- if (!mutex_trylock(&list->mtx)) {
- printk(KERN_ERR "Link List in use\n");
- return -EINVAL;
- }
- /*
- * Empty out all of the entries from the DMA list. We need to go to the
- * low level driver as DMA entries are driver specific.
- */
- retval = bridge->dma_list_empty(list);
- if (retval) {
- printk(KERN_ERR "Unable to empty link-list entries\n");
- mutex_unlock(&list->mtx);
- return retval;
- }
- mutex_unlock(&list->mtx);
- kfree(list);
- return retval;
- }
- EXPORT_SYMBOL(vme_dma_list_free);
- int vme_dma_free(struct vme_resource *resource)
- {
- struct vme_dma_resource *ctrlr;
- if (resource->type != VME_DMA) {
- printk(KERN_ERR "Not a DMA resource\n");
- return -EINVAL;
- }
- ctrlr = list_entry(resource->entry, struct vme_dma_resource, list);
- if (!mutex_trylock(&ctrlr->mtx)) {
- printk(KERN_ERR "Resource busy, can't free\n");
- return -EBUSY;
- }
- if (!(list_empty(&ctrlr->pending) && list_empty(&ctrlr->running))) {
- printk(KERN_WARNING "Resource still processing transfers\n");
- mutex_unlock(&ctrlr->mtx);
- return -EBUSY;
- }
- ctrlr->locked = 0;
- mutex_unlock(&ctrlr->mtx);
- kfree(resource);
- return 0;
- }
- EXPORT_SYMBOL(vme_dma_free);
- void vme_bus_error_handler(struct vme_bridge *bridge,
- unsigned long long address, int am)
- {
- struct list_head *handler_pos = NULL;
- struct vme_error_handler *handler;
- int handler_triggered = 0;
- u32 aspace = vme_get_aspace(am);
- list_for_each(handler_pos, &bridge->vme_error_handlers) {
- handler = list_entry(handler_pos, struct vme_error_handler,
- list);
- if ((aspace == handler->aspace) &&
- (address >= handler->start) &&
- (address < handler->end)) {
- if (!handler->num_errors)
- handler->first_error = address;
- if (handler->num_errors != UINT_MAX)
- handler->num_errors++;
- handler_triggered = 1;
- }
- }
- if (!handler_triggered)
- dev_err(bridge->parent,
- "Unhandled VME access error at address 0x%llx\n",
- address);
- }
- EXPORT_SYMBOL(vme_bus_error_handler);
- struct vme_error_handler *vme_register_error_handler(
- struct vme_bridge *bridge, u32 aspace,
- unsigned long long address, size_t len)
- {
- struct vme_error_handler *handler;
- handler = kmalloc(sizeof(*handler), GFP_KERNEL);
- if (!handler)
- return NULL;
- handler->aspace = aspace;
- handler->start = address;
- handler->end = address + len;
- handler->num_errors = 0;
- handler->first_error = 0;
- list_add_tail(&handler->list, &bridge->vme_error_handlers);
- return handler;
- }
- EXPORT_SYMBOL(vme_register_error_handler);
- void vme_unregister_error_handler(struct vme_error_handler *handler)
- {
- list_del(&handler->list);
- kfree(handler);
- }
- EXPORT_SYMBOL(vme_unregister_error_handler);
- void vme_irq_handler(struct vme_bridge *bridge, int level, int statid)
- {
- void (*call)(int, int, void *);
- void *priv_data;
- call = bridge->irq[level - 1].callback[statid].func;
- priv_data = bridge->irq[level - 1].callback[statid].priv_data;
- if (call != NULL)
- call(level, statid, priv_data);
- else
- printk(KERN_WARNING "Spurious VME interrupt, level:%x, vector:%x\n",
- level, statid);
- }
- EXPORT_SYMBOL(vme_irq_handler);
- int vme_irq_request(struct vme_dev *vdev, int level, int statid,
- void (*callback)(int, int, void *),
- void *priv_data)
- {
- struct vme_bridge *bridge;
- bridge = vdev->bridge;
- if (bridge == NULL) {
- printk(KERN_ERR "Can't find VME bus\n");
- return -EINVAL;
- }
- if ((level < 1) || (level > 7)) {
- printk(KERN_ERR "Invalid interrupt level\n");
- return -EINVAL;
- }
- if (bridge->irq_set == NULL) {
- printk(KERN_ERR "Configuring interrupts not supported\n");
- return -EINVAL;
- }
- mutex_lock(&bridge->irq_mtx);
- if (bridge->irq[level - 1].callback[statid].func) {
- mutex_unlock(&bridge->irq_mtx);
- printk(KERN_WARNING "VME Interrupt already taken\n");
- return -EBUSY;
- }
- bridge->irq[level - 1].count++;
- bridge->irq[level - 1].callback[statid].priv_data = priv_data;
- bridge->irq[level - 1].callback[statid].func = callback;
- /* Enable IRQ level */
- bridge->irq_set(bridge, level, 1, 1);
- mutex_unlock(&bridge->irq_mtx);
- return 0;
- }
- EXPORT_SYMBOL(vme_irq_request);
- void vme_irq_free(struct vme_dev *vdev, int level, int statid)
- {
- struct vme_bridge *bridge;
- bridge = vdev->bridge;
- if (bridge == NULL) {
- printk(KERN_ERR "Can't find VME bus\n");
- return;
- }
- if ((level < 1) || (level > 7)) {
- printk(KERN_ERR "Invalid interrupt level\n");
- return;
- }
- if (bridge->irq_set == NULL) {
- printk(KERN_ERR "Configuring interrupts not supported\n");
- return;
- }
- mutex_lock(&bridge->irq_mtx);
- bridge->irq[level - 1].count--;
- /* Disable IRQ level if no more interrupts attached at this level*/
- if (bridge->irq[level - 1].count == 0)
- bridge->irq_set(bridge, level, 0, 1);
- bridge->irq[level - 1].callback[statid].func = NULL;
- bridge->irq[level - 1].callback[statid].priv_data = NULL;
- mutex_unlock(&bridge->irq_mtx);
- }
- EXPORT_SYMBOL(vme_irq_free);
- int vme_irq_generate(struct vme_dev *vdev, int level, int statid)
- {
- struct vme_bridge *bridge;
- bridge = vdev->bridge;
- if (bridge == NULL) {
- printk(KERN_ERR "Can't find VME bus\n");
- return -EINVAL;
- }
- if ((level < 1) || (level > 7)) {
- printk(KERN_WARNING "Invalid interrupt level\n");
- return -EINVAL;
- }
- if (bridge->irq_generate == NULL) {
- printk(KERN_WARNING "Interrupt generation not supported\n");
- return -EINVAL;
- }
- return bridge->irq_generate(bridge, level, statid);
- }
- EXPORT_SYMBOL(vme_irq_generate);
- /*
- * Request the location monitor, return resource or NULL
- */
- struct vme_resource *vme_lm_request(struct vme_dev *vdev)
- {
- struct vme_bridge *bridge;
- struct list_head *lm_pos = NULL;
- struct vme_lm_resource *allocated_lm = NULL;
- struct vme_lm_resource *lm = NULL;
- struct vme_resource *resource = NULL;
- bridge = vdev->bridge;
- if (bridge == NULL) {
- printk(KERN_ERR "Can't find VME bus\n");
- goto err_bus;
- }
- /* Loop through DMA resources */
- list_for_each(lm_pos, &bridge->lm_resources) {
- lm = list_entry(lm_pos,
- struct vme_lm_resource, list);
- if (lm == NULL) {
- printk(KERN_ERR "Registered NULL Location Monitor resource\n");
- continue;
- }
- /* Find an unlocked controller */
- mutex_lock(&lm->mtx);
- if (lm->locked == 0) {
- lm->locked = 1;
- mutex_unlock(&lm->mtx);
- allocated_lm = lm;
- break;
- }
- mutex_unlock(&lm->mtx);
- }
- /* Check to see if we found a resource */
- if (allocated_lm == NULL)
- goto err_lm;
- resource = kmalloc(sizeof(struct vme_resource), GFP_KERNEL);
- if (resource == NULL) {
- printk(KERN_ERR "Unable to allocate resource structure\n");
- goto err_alloc;
- }
- resource->type = VME_LM;
- resource->entry = &allocated_lm->list;
- return resource;
- err_alloc:
- /* Unlock image */
- mutex_lock(&lm->mtx);
- lm->locked = 0;
- mutex_unlock(&lm->mtx);
- err_lm:
- err_bus:
- return NULL;
- }
- EXPORT_SYMBOL(vme_lm_request);
- int vme_lm_count(struct vme_resource *resource)
- {
- struct vme_lm_resource *lm;
- if (resource->type != VME_LM) {
- printk(KERN_ERR "Not a Location Monitor resource\n");
- return -EINVAL;
- }
- lm = list_entry(resource->entry, struct vme_lm_resource, list);
- return lm->monitors;
- }
- EXPORT_SYMBOL(vme_lm_count);
- int vme_lm_set(struct vme_resource *resource, unsigned long long lm_base,
- u32 aspace, u32 cycle)
- {
- struct vme_bridge *bridge = find_bridge(resource);
- struct vme_lm_resource *lm;
- if (resource->type != VME_LM) {
- printk(KERN_ERR "Not a Location Monitor resource\n");
- return -EINVAL;
- }
- lm = list_entry(resource->entry, struct vme_lm_resource, list);
- if (bridge->lm_set == NULL) {
- printk(KERN_ERR "vme_lm_set not supported\n");
- return -EINVAL;
- }
- return bridge->lm_set(lm, lm_base, aspace, cycle);
- }
- EXPORT_SYMBOL(vme_lm_set);
- int vme_lm_get(struct vme_resource *resource, unsigned long long *lm_base,
- u32 *aspace, u32 *cycle)
- {
- struct vme_bridge *bridge = find_bridge(resource);
- struct vme_lm_resource *lm;
- if (resource->type != VME_LM) {
- printk(KERN_ERR "Not a Location Monitor resource\n");
- return -EINVAL;
- }
- lm = list_entry(resource->entry, struct vme_lm_resource, list);
- if (bridge->lm_get == NULL) {
- printk(KERN_ERR "vme_lm_get not supported\n");
- return -EINVAL;
- }
- return bridge->lm_get(lm, lm_base, aspace, cycle);
- }
- EXPORT_SYMBOL(vme_lm_get);
- int vme_lm_attach(struct vme_resource *resource, int monitor,
- void (*callback)(void *), void *data)
- {
- struct vme_bridge *bridge = find_bridge(resource);
- struct vme_lm_resource *lm;
- if (resource->type != VME_LM) {
- printk(KERN_ERR "Not a Location Monitor resource\n");
- return -EINVAL;
- }
- lm = list_entry(resource->entry, struct vme_lm_resource, list);
- if (bridge->lm_attach == NULL) {
- printk(KERN_ERR "vme_lm_attach not supported\n");
- return -EINVAL;
- }
- return bridge->lm_attach(lm, monitor, callback, data);
- }
- EXPORT_SYMBOL(vme_lm_attach);
- int vme_lm_detach(struct vme_resource *resource, int monitor)
- {
- struct vme_bridge *bridge = find_bridge(resource);
- struct vme_lm_resource *lm;
- if (resource->type != VME_LM) {
- printk(KERN_ERR "Not a Location Monitor resource\n");
- return -EINVAL;
- }
- lm = list_entry(resource->entry, struct vme_lm_resource, list);
- if (bridge->lm_detach == NULL) {
- printk(KERN_ERR "vme_lm_detach not supported\n");
- return -EINVAL;
- }
- return bridge->lm_detach(lm, monitor);
- }
- EXPORT_SYMBOL(vme_lm_detach);
- void vme_lm_free(struct vme_resource *resource)
- {
- struct vme_lm_resource *lm;
- if (resource->type != VME_LM) {
- printk(KERN_ERR "Not a Location Monitor resource\n");
- return;
- }
- lm = list_entry(resource->entry, struct vme_lm_resource, list);
- mutex_lock(&lm->mtx);
- /* XXX
- * Check to see that there aren't any callbacks still attached, if
- * there are we should probably be detaching them!
- */
- lm->locked = 0;
- mutex_unlock(&lm->mtx);
- kfree(resource);
- }
- EXPORT_SYMBOL(vme_lm_free);
- int vme_slot_num(struct vme_dev *vdev)
- {
- struct vme_bridge *bridge;
- bridge = vdev->bridge;
- if (bridge == NULL) {
- printk(KERN_ERR "Can't find VME bus\n");
- return -EINVAL;
- }
- if (bridge->slot_get == NULL) {
- printk(KERN_WARNING "vme_slot_num not supported\n");
- return -EINVAL;
- }
- return bridge->slot_get(bridge);
- }
- EXPORT_SYMBOL(vme_slot_num);
- int vme_bus_num(struct vme_dev *vdev)
- {
- struct vme_bridge *bridge;
- bridge = vdev->bridge;
- if (bridge == NULL) {
- pr_err("Can't find VME bus\n");
- return -EINVAL;
- }
- return bridge->num;
- }
- EXPORT_SYMBOL(vme_bus_num);
- /* - Bridge Registration --------------------------------------------------- */
- static void vme_dev_release(struct device *dev)
- {
- kfree(dev_to_vme_dev(dev));
- }
- /* Common bridge initialization */
- struct vme_bridge *vme_init_bridge(struct vme_bridge *bridge)
- {
- INIT_LIST_HEAD(&bridge->vme_error_handlers);
- INIT_LIST_HEAD(&bridge->master_resources);
- INIT_LIST_HEAD(&bridge->slave_resources);
- INIT_LIST_HEAD(&bridge->dma_resources);
- INIT_LIST_HEAD(&bridge->lm_resources);
- mutex_init(&bridge->irq_mtx);
- return bridge;
- }
- EXPORT_SYMBOL(vme_init_bridge);
- int vme_register_bridge(struct vme_bridge *bridge)
- {
- int i;
- int ret = -1;
- mutex_lock(&vme_buses_lock);
- for (i = 0; i < sizeof(vme_bus_numbers) * 8; i++) {
- if ((vme_bus_numbers & (1 << i)) == 0) {
- vme_bus_numbers |= (1 << i);
- bridge->num = i;
- INIT_LIST_HEAD(&bridge->devices);
- list_add_tail(&bridge->bus_list, &vme_bus_list);
- ret = 0;
- break;
- }
- }
- mutex_unlock(&vme_buses_lock);
- return ret;
- }
- EXPORT_SYMBOL(vme_register_bridge);
- void vme_unregister_bridge(struct vme_bridge *bridge)
- {
- struct vme_dev *vdev;
- struct vme_dev *tmp;
- mutex_lock(&vme_buses_lock);
- vme_bus_numbers &= ~(1 << bridge->num);
- list_for_each_entry_safe(vdev, tmp, &bridge->devices, bridge_list) {
- list_del(&vdev->drv_list);
- list_del(&vdev->bridge_list);
- device_unregister(&vdev->dev);
- }
- list_del(&bridge->bus_list);
- mutex_unlock(&vme_buses_lock);
- }
- EXPORT_SYMBOL(vme_unregister_bridge);
- /* - Driver Registration --------------------------------------------------- */
- static int __vme_register_driver_bus(struct vme_driver *drv,
- struct vme_bridge *bridge, unsigned int ndevs)
- {
- int err;
- unsigned int i;
- struct vme_dev *vdev;
- struct vme_dev *tmp;
- for (i = 0; i < ndevs; i++) {
- vdev = kzalloc(sizeof(struct vme_dev), GFP_KERNEL);
- if (!vdev) {
- err = -ENOMEM;
- goto err_devalloc;
- }
- vdev->num = i;
- vdev->bridge = bridge;
- vdev->dev.platform_data = drv;
- vdev->dev.release = vme_dev_release;
- vdev->dev.parent = bridge->parent;
- vdev->dev.bus = &vme_bus_type;
- dev_set_name(&vdev->dev, "%s.%u-%u", drv->name, bridge->num,
- vdev->num);
- err = device_register(&vdev->dev);
- if (err)
- goto err_reg;
- if (vdev->dev.platform_data) {
- list_add_tail(&vdev->drv_list, &drv->devices);
- list_add_tail(&vdev->bridge_list, &bridge->devices);
- } else
- device_unregister(&vdev->dev);
- }
- return 0;
- err_reg:
- put_device(&vdev->dev);
- kfree(vdev);
- err_devalloc:
- list_for_each_entry_safe(vdev, tmp, &drv->devices, drv_list) {
- list_del(&vdev->drv_list);
- list_del(&vdev->bridge_list);
- device_unregister(&vdev->dev);
- }
- return err;
- }
- static int __vme_register_driver(struct vme_driver *drv, unsigned int ndevs)
- {
- struct vme_bridge *bridge;
- int err = 0;
- mutex_lock(&vme_buses_lock);
- list_for_each_entry(bridge, &vme_bus_list, bus_list) {
- /*
- * This cannot cause trouble as we already have vme_buses_lock
- * and if the bridge is removed, it will have to go through
- * vme_unregister_bridge() to do it (which calls remove() on
- * the bridge which in turn tries to acquire vme_buses_lock and
- * will have to wait).
- */
- err = __vme_register_driver_bus(drv, bridge, ndevs);
- if (err)
- break;
- }
- mutex_unlock(&vme_buses_lock);
- return err;
- }
- int vme_register_driver(struct vme_driver *drv, unsigned int ndevs)
- {
- int err;
- drv->driver.name = drv->name;
- drv->driver.bus = &vme_bus_type;
- INIT_LIST_HEAD(&drv->devices);
- err = driver_register(&drv->driver);
- if (err)
- return err;
- err = __vme_register_driver(drv, ndevs);
- if (err)
- driver_unregister(&drv->driver);
- return err;
- }
- EXPORT_SYMBOL(vme_register_driver);
- void vme_unregister_driver(struct vme_driver *drv)
- {
- struct vme_dev *dev, *dev_tmp;
- mutex_lock(&vme_buses_lock);
- list_for_each_entry_safe(dev, dev_tmp, &drv->devices, drv_list) {
- list_del(&dev->drv_list);
- list_del(&dev->bridge_list);
- device_unregister(&dev->dev);
- }
- mutex_unlock(&vme_buses_lock);
- driver_unregister(&drv->driver);
- }
- EXPORT_SYMBOL(vme_unregister_driver);
- /* - Bus Registration ------------------------------------------------------ */
- static int vme_bus_match(struct device *dev, struct device_driver *drv)
- {
- struct vme_driver *vme_drv;
- vme_drv = container_of(drv, struct vme_driver, driver);
- if (dev->platform_data == vme_drv) {
- struct vme_dev *vdev = dev_to_vme_dev(dev);
- if (vme_drv->match && vme_drv->match(vdev))
- return 1;
- dev->platform_data = NULL;
- }
- return 0;
- }
- static int vme_bus_probe(struct device *dev)
- {
- int retval = -ENODEV;
- struct vme_driver *driver;
- struct vme_dev *vdev = dev_to_vme_dev(dev);
- driver = dev->platform_data;
- if (driver->probe != NULL)
- retval = driver->probe(vdev);
- return retval;
- }
- static int vme_bus_remove(struct device *dev)
- {
- int retval = -ENODEV;
- struct vme_driver *driver;
- struct vme_dev *vdev = dev_to_vme_dev(dev);
- driver = dev->platform_data;
- if (driver->remove != NULL)
- retval = driver->remove(vdev);
- return retval;
- }
- struct bus_type vme_bus_type = {
- .name = "vme",
- .match = vme_bus_match,
- .probe = vme_bus_probe,
- .remove = vme_bus_remove,
- };
- EXPORT_SYMBOL(vme_bus_type);
- static int __init vme_init(void)
- {
- return bus_register(&vme_bus_type);
- }
- subsys_initcall(vme_init);
|