⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ds.c

📁 Linux Kernel 2.6.9 for OMAP1710
💻 C
📖 第 1 页 / 共 3 页
字号:
/*======================================================================    PC Card Driver Services        ds.c 1.112 2001/10/13 00:08:28        The contents of this file are subject to the Mozilla Public    License Version 1.1 (the "License"); you may not use this file    except in compliance with the License. You may obtain a copy of    the License at http://www.mozilla.org/MPL/    Software distributed under the License is distributed on an "AS    IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or    implied. See the License for the specific language governing    rights and limitations under the License.    The initial developer of the original code is David A. Hinds    <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds    are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.    Alternatively, the contents of this file may be used under the    terms of the GNU General Public License version 2 (the "GPL"), in    which case the provisions of the GPL are applicable instead of the    above.  If you wish to allow the use of your version of this file    only under the terms of the GPL and not to allow others to use    your version of this file under the MPL, indicate your decision    by deleting the provisions above and replace them with the notice    and other provisions required by the GPL.  If you do not delete    the provisions above, a recipient may use your version of this    file under either the MPL or the GPL.    ======================================================================*/#include <linux/config.h>#include <linux/module.h>#include <linux/moduleparam.h>#include <linux/init.h>#include <linux/kernel.h>#include <linux/major.h>#include <linux/string.h>#include <linux/errno.h>#include <linux/slab.h>#include <linux/mm.h>#include <linux/fcntl.h>#include <linux/sched.h>#include <linux/smp_lock.h>#include <linux/timer.h>#include <linux/ioctl.h>#include <linux/proc_fs.h>#include <linux/poll.h>#include <linux/pci.h>#include <linux/list.h>#include <linux/delay.h>#include <linux/workqueue.h>#include <asm/atomic.h>#define IN_CARD_SERVICES#include <pcmcia/version.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/bulkmem.h>#include <pcmcia/cistpl.h>#include <pcmcia/ds.h>#include <pcmcia/ss.h>#include "cs_internal.h"/*====================================================================*//* Module parameters */MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");MODULE_DESCRIPTION("PCMCIA Driver Services");MODULE_LICENSE("Dual MPL/GPL");#ifdef DEBUGstatic int pc_debug;module_param(pc_debug, int, 0644);#define ds_dbg(lvl, fmt, arg...) do {				\	if (pc_debug > (lvl))					\		printk(KERN_DEBUG "ds: " fmt , ## arg);		\} while (0)#else#define ds_dbg(lvl, fmt, arg...) do { } while (0)#endif/*====================================================================*/typedef struct socket_bind_t {    struct pcmcia_driver	*driver;    u_char		function;    dev_link_t		*instance;    struct socket_bind_t *next;} socket_bind_t;/* Device user information */#define MAX_EVENTS	32#define USER_MAGIC	0x7ea4#define CHECK_USER(u) \    (((u) == NULL) || ((u)->user_magic != USER_MAGIC))typedef struct user_info_t {    u_int		user_magic;    int			event_head, event_tail;    event_t		event[MAX_EVENTS];    struct user_info_t	*next;    struct pcmcia_bus_socket *socket;} user_info_t;/* Socket state information */struct pcmcia_bus_socket {	atomic_t		refcount;	client_handle_t		handle;	int			state;	user_info_t		*user;	int			req_pending, req_result;	wait_queue_head_t	queue, request;	struct work_struct	removal;	socket_bind_t		*bind;	struct pcmcia_socket	*parent;};#define DS_SOCKET_PRESENT		0x01#define DS_SOCKET_BUSY			0x02#define DS_SOCKET_REMOVAL_PENDING	0x10#define DS_SOCKET_DEAD			0x80/*====================================================================*//* Device driver ID passed to Card Services */static dev_info_t dev_info = "Driver Services";static int major_dev = -1;static struct proc_dir_entry *proc_pccard;/*====================================================================*//* code which was in cs.c before *//*======================================================================    Bind_device() associates a device driver with a particular socket.    It is normally called by Driver Services after it has identified    a newly inserted card.  An instance of that driver will then be    eligible to register as a client of this socket.    ======================================================================*/static int pcmcia_bind_device(bind_req_t *req){	client_t *client;	struct pcmcia_socket *s;	s = req->Socket;	if (!s)		return CS_BAD_SOCKET;	client = (client_t *) kmalloc(sizeof(client_t), GFP_KERNEL);	if (!client) 		return CS_OUT_OF_RESOURCE;	memset(client, '\0', sizeof(client_t));	client->client_magic = CLIENT_MAGIC;	strlcpy(client->dev_info, (char *)req->dev_info, DEV_NAME_LEN);	client->Socket = s;	client->Function = req->Function;	client->state = CLIENT_UNBOUND;	client->erase_busy.next = &client->erase_busy;	client->erase_busy.prev = &client->erase_busy;	init_waitqueue_head(&client->mtd_req);	client->next = s->clients;	s->clients = client;	ds_dbg(1, "%s: bind_device(): client 0x%p, dev %s\n",		cs_socket_name(client->Socket), client, client->dev_info);	return CS_SUCCESS;} /* bind_device *//*======================================================================    Bind_mtd() associates a device driver with a particular memory    region.  It is normally called by Driver Services after it has    identified a memory device type.  An instance of the corresponding    driver will then be able to register to control this region.    ======================================================================*/static int pcmcia_bind_mtd(mtd_bind_t *req){	struct pcmcia_socket *s;	memory_handle_t region;	s = req->Socket;	if (!s)		return CS_BAD_SOCKET;    	if (req->Attributes & REGION_TYPE_AM)		region = s->a_region;	else		region = s->c_region;	while (region) {		if (region->info.CardOffset == req->CardOffset) 			break;		region = region->info.next;	}	if (!region || (region->mtd != NULL))		return CS_BAD_OFFSET;	strlcpy(region->dev_info, (char *)req->dev_info, DEV_NAME_LEN);	ds_dbg(1, "%s: bind_mtd: attr 0x%x, offset 0x%x, dev %s\n",	      cs_socket_name(s), req->Attributes, req->CardOffset,	      (char *)req->dev_info);	return CS_SUCCESS;} /* bind_mtd *//* String tables for error messages */typedef struct lookup_t {    int key;    char *msg;} lookup_t;static const lookup_t error_table[] = {    { CS_SUCCESS,		"Operation succeeded" },    { CS_BAD_ADAPTER,		"Bad adapter" },    { CS_BAD_ATTRIBUTE, 	"Bad attribute", },    { CS_BAD_BASE,		"Bad base address" },    { CS_BAD_EDC,		"Bad EDC" },    { CS_BAD_IRQ,		"Bad IRQ" },    { CS_BAD_OFFSET,		"Bad offset" },    { CS_BAD_PAGE,		"Bad page number" },    { CS_READ_FAILURE,		"Read failure" },    { CS_BAD_SIZE,		"Bad size" },    { CS_BAD_SOCKET,		"Bad socket" },    { CS_BAD_TYPE,		"Bad type" },    { CS_BAD_VCC,		"Bad Vcc" },    { CS_BAD_VPP,		"Bad Vpp" },    { CS_BAD_WINDOW,		"Bad window" },    { CS_WRITE_FAILURE,		"Write failure" },    { CS_NO_CARD,		"No card present" },    { CS_UNSUPPORTED_FUNCTION,	"Usupported function" },    { CS_UNSUPPORTED_MODE,	"Unsupported mode" },    { CS_BAD_SPEED,		"Bad speed" },    { CS_BUSY,			"Resource busy" },    { CS_GENERAL_FAILURE,	"General failure" },    { CS_WRITE_PROTECTED,	"Write protected" },    { CS_BAD_ARG_LENGTH,	"Bad argument length" },    { CS_BAD_ARGS,		"Bad arguments" },    { CS_CONFIGURATION_LOCKED,	"Configuration locked" },    { CS_IN_USE,		"Resource in use" },    { CS_NO_MORE_ITEMS,		"No more items" },    { CS_OUT_OF_RESOURCE,	"Out of resource" },    { CS_BAD_HANDLE,		"Bad handle" },    { CS_BAD_TUPLE,		"Bad CIS tuple" }};static const lookup_t service_table[] = {    { AccessConfigurationRegister,	"AccessConfigurationRegister" },    { AddSocketServices,		"AddSocketServices" },    { AdjustResourceInfo,		"AdjustResourceInfo" },    { CheckEraseQueue,			"CheckEraseQueue" },    { CloseMemory,			"CloseMemory" },    { DeregisterClient,			"DeregisterClient" },    { DeregisterEraseQueue,		"DeregisterEraseQueue" },    { GetCardServicesInfo,		"GetCardServicesInfo" },    { GetClientInfo,			"GetClientInfo" },    { GetConfigurationInfo,		"GetConfigurationInfo" },    { GetEventMask,			"GetEventMask" },    { GetFirstClient,			"GetFirstClient" },    { GetFirstRegion,			"GetFirstRegion" },    { GetFirstTuple,			"GetFirstTuple" },    { GetNextClient,			"GetNextClient" },    { GetNextRegion,			"GetNextRegion" },    { GetNextTuple,			"GetNextTuple" },    { GetStatus,			"GetStatus" },    { GetTupleData,			"GetTupleData" },    { MapMemPage,			"MapMemPage" },    { ModifyConfiguration,		"ModifyConfiguration" },    { ModifyWindow,			"ModifyWindow" },    { OpenMemory,			"OpenMemory" },    { ParseTuple,			"ParseTuple" },    { ReadMemory,			"ReadMemory" },    { RegisterClient,			"RegisterClient" },    { RegisterEraseQueue,		"RegisterEraseQueue" },    { RegisterMTD,			"RegisterMTD" },    { ReleaseConfiguration,		"ReleaseConfiguration" },    { ReleaseIO,			"ReleaseIO" },    { ReleaseIRQ,			"ReleaseIRQ" },    { ReleaseWindow,			"ReleaseWindow" },    { RequestConfiguration,		"RequestConfiguration" },    { RequestIO,			"RequestIO" },    { RequestIRQ,			"RequestIRQ" },    { RequestSocketMask,		"RequestSocketMask" },    { RequestWindow,			"RequestWindow" },    { ResetCard,			"ResetCard" },    { SetEventMask,			"SetEventMask" },    { ValidateCIS,			"ValidateCIS" },    { WriteMemory,			"WriteMemory" },    { BindDevice,			"BindDevice" },    { BindMTD,				"BindMTD" },    { ReportError,			"ReportError" },    { SuspendCard,			"SuspendCard" },    { ResumeCard,			"ResumeCard" },    { EjectCard,			"EjectCard" },    { InsertCard,			"InsertCard" },    { ReplaceCIS,			"ReplaceCIS" }};int pcmcia_report_error(client_handle_t handle, error_info_t *err){	int i;	char *serv;	if (CHECK_HANDLE(handle))		printk(KERN_NOTICE);	else		printk(KERN_NOTICE "%s: ", handle->dev_info);	for (i = 0; i < ARRAY_SIZE(service_table); i++)		if (service_table[i].key == err->func)			break;	if (i < ARRAY_SIZE(service_table))		serv = service_table[i].msg;	else		serv = "Unknown service number";	for (i = 0; i < ARRAY_SIZE(error_table); i++)		if (error_table[i].key == err->retcode)			break;	if (i < ARRAY_SIZE(error_table))		printk("%s: %s\n", serv, error_table[i].msg);	else		printk("%s: Unknown error code %#x\n", serv, err->retcode);	return CS_SUCCESS;} /* report_error */EXPORT_SYMBOL(pcmcia_report_error);/* end of code which was in cs.c before *//*======================================================================*/void cs_error(client_handle_t handle, int func, int ret){	error_info_t err = { func, ret };	pcmcia_report_error(handle, &err);}EXPORT_SYMBOL(cs_error);/*======================================================================*/static struct pcmcia_driver * get_pcmcia_driver (dev_info_t *dev_info);static struct pcmcia_bus_socket * get_socket_info_by_nr(unsigned int nr);static void pcmcia_put_bus_socket(struct pcmcia_bus_socket *s){	if (atomic_dec_and_test(&s->refcount))		kfree(s);}static struct pcmcia_bus_socket *pcmcia_get_bus_socket(int nr){	struct pcmcia_bus_socket *s;	s = get_socket_info_by_nr(nr);	if (s) {		WARN_ON(atomic_read(&s->refcount) == 0);		atomic_inc(&s->refcount);	}	return s;}/** * pcmcia_register_driver - register a PCMCIA driver with the bus core * * Registers a PCMCIA driver with the PCMCIA bus core. */int pcmcia_register_driver(struct pcmcia_driver *driver){	if (!driver)		return -EINVAL; 	driver->use_count = 0;	driver->drv.bus = &pcmcia_bus_type;	return driver_register(&driver->drv);}EXPORT_SYMBOL(pcmcia_register_driver);/** * pcmcia_unregister_driver - unregister a PCMCIA driver with the bus core */void pcmcia_unregister_driver(struct pcmcia_driver *driver){	driver_unregister(&driver->drv);}EXPORT_SYMBOL(pcmcia_unregister_driver);#ifdef CONFIG_PROC_FSstatic struct proc_dir_entry *proc_pccard = NULL;static int proc_read_drivers_callback(struct device_driver *driver, void *d){	char **p = d;	struct pcmcia_driver *p_dev = container_of(driver, 						   struct pcmcia_driver, drv);	*p += sprintf(*p, "%-24.24s 1 %d\n", driver->name, p_dev->use_count);	d = (void *) p;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -