ds.h 11.6 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * ds.h -- 16-bit PCMCIA core support
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * 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.
 *
 * (C) 1999		David A. Hinds
13
 * (C) 2003 - 2008	Dominik Brodowski
L
Linus Torvalds 已提交
14 15 16 17 18
 */

#ifndef _LINUX_DS_H
#define _LINUX_DS_H

19 20 21 22
#ifdef __KERNEL__
#include <linux/mod_devicetable.h>
#endif

L
Linus Torvalds 已提交
23
#include <pcmcia/cs_types.h>
24
#include <pcmcia/device_id.h>
L
Linus Torvalds 已提交
25 26 27

#ifdef __KERNEL__
#include <linux/device.h>
28
#include <pcmcia/ss.h>
L
Linus Torvalds 已提交
29

30 31 32 33
/*
 * PCMCIA device drivers (16-bit cards only; 32-bit cards require CardBus
 * a.k.a. PCI drivers
 */
L
Linus Torvalds 已提交
34
struct pcmcia_socket;
35
struct pcmcia_device;
36
struct config_t;
L
Linus Torvalds 已提交
37

38 39 40
/* dynamic device IDs for PCMCIA device drivers. See
 * Documentation/pcmcia/driver.txt for details.
*/
B
Bernhard Walle 已提交
41 42 43 44 45
struct pcmcia_dynids {
	spinlock_t		lock;
	struct list_head	list;
};

L
Linus Torvalds 已提交
46
struct pcmcia_driver {
47
	int (*probe)		(struct pcmcia_device *dev);
48 49
	void (*remove)		(struct pcmcia_device *dev);

50 51 52
	int (*suspend)		(struct pcmcia_device *dev);
	int (*resume)		(struct pcmcia_device *dev);

L
Linus Torvalds 已提交
53
	struct module		*owner;
54
	struct pcmcia_device_id	*id_table;
L
Linus Torvalds 已提交
55
	struct device_driver	drv;
B
Bernhard Walle 已提交
56
	struct pcmcia_dynids	dynids;
L
Linus Torvalds 已提交
57 58 59 60 61 62
};

/* driver registration */
int pcmcia_register_driver(struct pcmcia_driver *driver);
void pcmcia_unregister_driver(struct pcmcia_driver *driver);

63 64 65 66 67 68 69 70
/* Some drivers use dev_node_t to store char or block device information.
 * Don't use this in new drivers, though.
 */
typedef struct dev_node_t {
	char			dev_name[DEV_NAME_LEN];
	u_short			major, minor;
	struct dev_node_t	*next;
} dev_node_t;
71

L
Linus Torvalds 已提交
72 73 74 75 76
struct pcmcia_device {
	/* the socket and the device_no [for multifunction devices]
	   uniquely define a pcmcia_device */
	struct pcmcia_socket	*socket;

77 78
	char			*devname;

L
Linus Torvalds 已提交
79 80 81 82 83
	u8			device_no;

	/* the hardware "function" device; certain subdevices can
	 * share one hardware "function" device. */
	u8			func;
84
	struct config_t*	function_config;
L
Linus Torvalds 已提交
85 86 87

	struct list_head	socket_device_list;

88 89 90 91 92 93 94 95
	/* deprecated, will be cleaned up soon */
	dev_node_t		*dev_node;
	u_int			open;
	io_req_t		io;
	irq_req_t		irq;
	config_req_t		conf;
	window_handle_t		win;

96 97
	/* Is the device suspended, or in the process of
	 * being removed? */
98
	u16			suspended:1;
99
	u16			_removed:1;
100 101 102 103 104 105 106

	/* Flags whether io, irq, win configurations were
	 * requested, and whether the configuration is "locked" */
	u16			_irq:1;
	u16			_io:1;
	u16			_win:4;
	u16			_locked:1;
L
Linus Torvalds 已提交
107

108 109 110
	/* Flag whether a "fuzzy" func_id based match is
	 * allowed. */
	u16			allow_func_id_match:1;
111

L
Linus Torvalds 已提交
112
	/* information about this device */
113 114 115
	u16			has_manf_id:1;
	u16			has_card_id:1;
	u16			has_func_id:1;
116

117
	u16			reserved:3;
L
Linus Torvalds 已提交
118 119 120 121 122 123 124

	u8			func_id;
	u16			manf_id;
	u16			card_id;

	char *			prod_id[4];

125
	u64			dma_mask;
126 127 128
	struct device		dev;

#ifdef CONFIG_PCMCIA_IOCTL
L
Linus Torvalds 已提交
129 130
	/* device driver wanted by cardmgr */
	struct pcmcia_driver *	cardmgr;
131
#endif
132 133 134

	/* data private to drivers */
	void			*priv;
L
Linus Torvalds 已提交
135 136 137 138 139
};

#define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev)
#define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv)

140
/* deprecated -- don't use! */
141
#define handle_to_dev(handle) (handle->dev)
L
Linus Torvalds 已提交
142

143 144 145 146 147

/* (deprecated) error reporting by PCMCIA devices. Use dev_printk()
 * or dev_dbg() directly in the driver, without referring to pcmcia_error_func()
 * and/or pcmcia_error_ret() for those functions will go away soon.
 */
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
enum service {
    AccessConfigurationRegister, AddSocketServices,
    AdjustResourceInfo, CheckEraseQueue, CloseMemory, CopyMemory,
    DeregisterClient, DeregisterEraseQueue, GetCardServicesInfo,
    GetClientInfo, GetConfigurationInfo, GetEventMask,
    GetFirstClient, GetFirstPartion, GetFirstRegion, GetFirstTuple,
    GetNextClient, GetNextPartition, GetNextRegion, GetNextTuple,
    GetStatus, GetTupleData, MapLogSocket, MapLogWindow, MapMemPage,
    MapPhySocket, MapPhyWindow, ModifyConfiguration, ModifyWindow,
    OpenMemory, ParseTuple, ReadMemory, RegisterClient,
    RegisterEraseQueue, RegisterMTD, RegisterTimer,
    ReleaseConfiguration, ReleaseExclusive, ReleaseIO, ReleaseIRQ,
    ReleaseSocketMask, ReleaseWindow, ReplaceSocketServices,
    RequestConfiguration, RequestExclusive, RequestIO, RequestIRQ,
    RequestSocketMask, RequestWindow, ResetCard, ReturnSSEntry,
    SetEventMask, SetRegion, ValidateCIS, VendorSpecific,
    WriteMemory, BindDevice, BindMTD, ReportError,
    SuspendCard, ResumeCard, EjectCard, InsertCard, ReplaceCIS,
    GetFirstWindow, GetNextWindow, GetMemPage
};
168 169 170 171 172 173 174 175 176 177 178
const char *pcmcia_error_func(int func);
const char *pcmcia_error_ret(int ret);

#define cs_error(p_dev, func, ret)			\
	{						\
		dev_printk(KERN_NOTICE, &p_dev->dev,	\
			   "%s : %s\n",			\
			   pcmcia_error_func(func),	\
			   pcmcia_error_ret(ret));	\
	}

179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
/* CIS access.
 * Use the pcmcia_* versions in PCMCIA drivers
 */
int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);

int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function,
			   tuple_t *tuple);
#define pcmcia_get_first_tuple(p_dev, tuple) \
		pccard_get_first_tuple(p_dev->socket, p_dev->func, tuple)

int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function,
			  tuple_t *tuple);
#define pcmcia_get_next_tuple(p_dev, tuple) \
		pccard_get_next_tuple(p_dev->socket, p_dev->func, tuple)

int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple);
#define pcmcia_get_tuple_data(p_dev, tuple) \
		pccard_get_tuple_data(p_dev->socket, tuple)


/* loop CIS entries for valid configuration */
int pcmcia_loop_config(struct pcmcia_device *p_dev,
		       int	(*conf_check)	(struct pcmcia_device *p_dev,
						 cistpl_cftable_entry_t *cf,
						 cistpl_cftable_entry_t *dflt,
						 unsigned int vcc,
						 void *priv_data),
		       void *priv_data);
L
Linus Torvalds 已提交
207

208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
/* is the device still there? */
struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev);

/* low-level interface reset */
int pcmcia_reset_card(struct pcmcia_socket *skt);

/* CIS config */
int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
					 conf_reg_t *reg);

/* device configuration */
int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req);
int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req);
int pcmcia_request_configuration(struct pcmcia_device *p_dev,
				 config_req_t *req);

int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req,
			  window_handle_t *wh);
int pcmcia_release_window(window_handle_t win);

int pcmcia_get_mem_page(window_handle_t win, memreq_t *req);
int pcmcia_map_mem_page(window_handle_t win, memreq_t *req);

int pcmcia_modify_configuration(struct pcmcia_device *p_dev, modconf_t *mod);
void pcmcia_disable_device(struct pcmcia_device *p_dev);

L
Linus Torvalds 已提交
234
#endif /* __KERNEL__ */
235 236 237 238 239 240 241 242 243 244 245 246



/* Below, there are only definitions which are used by
 * - the PCMCIA ioctl
 * - deprecated PCMCIA userspace tools only
 *
 * here be dragons ... here be dragons ... here be dragons ... here be drag
 */

#if defined(CONFIG_PCMCIA_IOCTL) || !defined(__KERNEL__)

D
Dominik Brodowski 已提交
247 248 249 250 251 252 253 254
#if defined(__arm__) || defined(__mips__) || defined(__avr32__) || \
	defined(__bfin__)
/* This (ioaddr_t) is exposed to userspace & hence cannot be changed. */
typedef u_int   ioaddr_t;
#else
typedef u_short	ioaddr_t;
#endif

255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
/* for AdjustResourceInfo */
typedef struct adjust_t {
	u_int			Action;
	u_int			Resource;
	u_int			Attributes;
	union {
		struct memory {
			u_long		Base;
			u_long		Size;
		} memory;
		struct io {
			ioaddr_t	BasePort;
			ioaddr_t	NumPorts;
			u_int		IOAddrLines;
		} io;
		struct irq {
			u_int		IRQ;
		} irq;
	} resource;
} adjust_t;

/* Action field */
#define REMOVE_MANAGED_RESOURCE		1
#define ADD_MANAGED_RESOURCE		2
#define GET_FIRST_MANAGED_RESOURCE	3
#define GET_NEXT_MANAGED_RESOURCE	4
/* Resource field */
#define RES_MEMORY_RANGE		1
#define RES_IO_RANGE			2
#define RES_IRQ				3
/* Attribute field */
#define RES_IRQ_TYPE			0x03
#define RES_IRQ_TYPE_EXCLUSIVE		0
#define RES_IRQ_TYPE_TIME		1
#define RES_IRQ_TYPE_DYNAMIC		2
#define RES_IRQ_CSC			0x04
#define RES_SHARED			0x08
#define RES_RESERVED			0x10
#define RES_ALLOCATED			0x20
#define RES_REMOVED			0x40


typedef struct tuple_parse_t {
	tuple_t			tuple;
	cisdata_t		data[255];
	cisparse_t		parse;
} tuple_parse_t;

typedef struct win_info_t {
	window_handle_t		handle;
	win_req_t		window;
	memreq_t		map;
} win_info_t;

typedef struct bind_info_t {
	dev_info_t		dev_info;
	u_char			function;
	struct pcmcia_device	*instance;
	char			name[DEV_NAME_LEN];
	u_short			major, minor;
	void			*next;
} bind_info_t;

typedef struct mtd_info_t {
	dev_info_t     		dev_info;
	u_int			Attributes;
	u_int			CardOffset;
} mtd_info_t;

typedef struct region_info_t {
	u_int			Attributes;
	u_int			CardOffset;
	u_int			RegionSize;
	u_int			AccessSpeed;
	u_int			BlockSize;
	u_int			PartMultiple;
	u_char			JedecMfr, JedecInfo;
	memory_handle_t		next;
} region_info_t;

#define REGION_TYPE		0x0001
#define REGION_TYPE_CM		0x0000
#define REGION_TYPE_AM		0x0001
#define REGION_PREFETCH		0x0008
#define REGION_CACHEABLE	0x0010
#define REGION_BAR_MASK		0xe000
#define REGION_BAR_SHIFT	13

/* For ReplaceCIS */
typedef struct cisdump_t {
	u_int			Length;
	cisdata_t		Data[CISTPL_MAX_CIS_SIZE];
} cisdump_t;

/* for GetConfigurationInfo */
typedef struct config_info_t {
	u_char			Function;
	u_int			Attributes;
	u_int			Vcc, Vpp1, Vpp2;
	u_int			IntType;
	u_int			ConfigBase;
	u_char			Status, Pin, Copy, Option, ExtStatus;
	u_int			Present;
	u_int			CardValues;
	u_int			AssignedIRQ;
	u_int			IRQAttributes;
	ioaddr_t		BasePort1;
	ioaddr_t		NumPorts1;
	u_int			Attributes1;
	ioaddr_t		BasePort2;
	ioaddr_t		NumPorts2;
	u_int			Attributes2;
	u_int			IOAddrLines;
} config_info_t;

typedef union ds_ioctl_arg_t {
	adjust_t		adjust;
	config_info_t		config;
	tuple_t			tuple;
	tuple_parse_t		tuple_parse;
	client_req_t		client_req;
	cs_status_t		status;
	conf_reg_t		conf_reg;
	cisinfo_t		cisinfo;
	region_info_t		region;
	bind_info_t		bind_info;
	mtd_info_t		mtd_info;
	win_info_t		win_info;
	cisdump_t		cisdump;
} ds_ioctl_arg_t;

#define DS_ADJUST_RESOURCE_INFO			_IOWR('d',  2, adjust_t)
#define DS_GET_CONFIGURATION_INFO		_IOWR('d',  3, config_info_t)
#define DS_GET_FIRST_TUPLE			_IOWR('d',  4, tuple_t)
#define DS_GET_NEXT_TUPLE			_IOWR('d',  5, tuple_t)
#define DS_GET_TUPLE_DATA			_IOWR('d',  6, tuple_parse_t)
#define DS_PARSE_TUPLE				_IOWR('d',  7, tuple_parse_t)
#define DS_RESET_CARD				_IO  ('d',  8)
#define DS_GET_STATUS				_IOWR('d',  9, cs_status_t)
#define DS_ACCESS_CONFIGURATION_REGISTER	_IOWR('d', 10, conf_reg_t)
#define DS_VALIDATE_CIS				_IOR ('d', 11, cisinfo_t)
#define DS_SUSPEND_CARD				_IO  ('d', 12)
#define DS_RESUME_CARD				_IO  ('d', 13)
#define DS_EJECT_CARD				_IO  ('d', 14)
#define DS_INSERT_CARD				_IO  ('d', 15)
#define DS_GET_FIRST_REGION			_IOWR('d', 16, region_info_t)
#define DS_GET_NEXT_REGION			_IOWR('d', 17, region_info_t)
#define DS_REPLACE_CIS				_IOWR('d', 18, cisdump_t)
#define DS_GET_FIRST_WINDOW			_IOR ('d', 19, win_info_t)
#define DS_GET_NEXT_WINDOW			_IOWR('d', 20, win_info_t)
#define DS_GET_MEM_PAGE				_IOWR('d', 21, win_info_t)

#define DS_BIND_REQUEST				_IOWR('d', 60, bind_info_t)
#define DS_GET_DEVICE_INFO			_IOWR('d', 61, bind_info_t)
#define DS_GET_NEXT_DEVICE			_IOWR('d', 62, bind_info_t)
#define DS_UNBIND_REQUEST			_IOW ('d', 63, bind_info_t)
#define DS_BIND_MTD				_IOWR('d', 64, mtd_info_t)


/* used in userspace only */
#define CS_IN_USE			0x1e

417 418 419 420 421 422 423 424 425
#define INFO_MASTER_CLIENT	0x01
#define INFO_IO_CLIENT		0x02
#define INFO_MTD_CLIENT		0x04
#define INFO_MEM_CLIENT		0x08
#define MAX_NUM_CLIENTS		3

#define INFO_CARD_SHARE		0x10
#define INFO_CARD_EXCL		0x20

426 427 428

#endif /* !defined(__KERNEL__) || defined(CONFIG_PCMCIA_IOCTL) */

L
Linus Torvalds 已提交
429
#endif /* _LINUX_DS_H */