12d8e02e4SAxel Dörfler/*
22d8e02e4SAxel Dörfler * Copyright 2004-2008, Haiku Inc. All Rights Reserved.
32d8e02e4SAxel Dörfler * Distributed under the terms of the MIT license.
42d8e02e4SAxel Dörfler */
52d8e02e4SAxel Dörfler#ifndef _DEVICE_MANAGER_H
62d8e02e4SAxel Dörfler#define _DEVICE_MANAGER_H
72d8e02e4SAxel Dörfler
82d8e02e4SAxel Dörfler
92d8e02e4SAxel Dörfler#include <TypeConstants.h>
102d8e02e4SAxel Dörfler#include <Drivers.h>
112d8e02e4SAxel Dörfler#include <module.h>
122d8e02e4SAxel Dörfler
132d8e02e4SAxel Dörfler
147a6818d3SAxel Dörfler/* type of I/O resource */
152d8e02e4SAxel Dörflerenum {
163aecf8aaSAxel Dörfler	B_IO_MEMORY			= 1,
173aecf8aaSAxel Dörfler	B_IO_PORT			= 2,
183aecf8aaSAxel Dörfler	B_ISA_DMA_CHANNEL	= 3
192d8e02e4SAxel Dörfler};
202d8e02e4SAxel Dörfler
212d8e02e4SAxel Dörfler
227a6818d3SAxel Dörfler/* I/O resource description */
232d8e02e4SAxel Dörflertypedef struct {
242d8e02e4SAxel Dörfler	uint32	type;
257a6818d3SAxel Dörfler		/* type of I/O resource */
262d8e02e4SAxel Dörfler
272d8e02e4SAxel Dörfler	uint32	base;
287a6818d3SAxel Dörfler		/* I/O memory: first physical address (32 bit)
297a6818d3SAxel Dörfler		 * I/O port: first port address (16 bit)
307a6818d3SAxel Dörfler		 * ISA DMA channel: channel number (0-7)
317a6818d3SAxel Dörfler		 */
322d8e02e4SAxel Dörfler
332d8e02e4SAxel Dörfler	uint32	length;
347a6818d3SAxel Dörfler		/* I/O memory: size of address range (32 bit)
357a6818d3SAxel Dörfler		 * I/O port: size of port range (16 bit)
367a6818d3SAxel Dörfler		 * ISA DMA channel: must be 1
377a6818d3SAxel Dörfler		 */
382d8e02e4SAxel Dörfler} io_resource;
392d8e02e4SAxel Dörfler
407a6818d3SAxel Dörfler/* attribute of a device node */
412d8e02e4SAxel Dörflertypedef struct {
422d8e02e4SAxel Dörfler	const char		*name;
437a6818d3SAxel Dörfler	type_code		type;			/* for supported types, see value */
442d8e02e4SAxel Dörfler	union {
457a6818d3SAxel Dörfler		uint8		ui8;			/* B_UINT8_TYPE */
467a6818d3SAxel Dörfler		uint16		ui16;			/* B_UINT16_TYPE */
477a6818d3SAxel Dörfler		uint32		ui32;			/* B_UINT32_TYPE */
487a6818d3SAxel Dörfler		uint64		ui64;			/* B_UINT64_TYPE */
497a6818d3SAxel Dörfler		const char	*string;		/* B_STRING_TYPE */
507a6818d3SAxel Dörfler		struct {					/* B_RAW_TYPE */
512d8e02e4SAxel Dörfler			const void *data;
522d8e02e4SAxel Dörfler			size_t	length;
532d8e02e4SAxel Dörfler		} raw;
542d8e02e4SAxel Dörfler	} value;
552d8e02e4SAxel Dörfler} device_attr;
562d8e02e4SAxel Dörfler
572d8e02e4SAxel Dörfler
582d8e02e4SAxel Dörflertypedef struct device_node device_node;
592d8e02e4SAxel Dörflertypedef struct driver_module_info driver_module_info;
602d8e02e4SAxel Dörfler
612d8e02e4SAxel Dörfler
627a6818d3SAxel Dörfler/* interface of the device manager */
632d8e02e4SAxel Dörfler
642d8e02e4SAxel Dörflertypedef struct device_manager_info {
652d8e02e4SAxel Dörfler	module_info info;
662d8e02e4SAxel Dörfler
677a6818d3SAxel Dörfler	status_t (*rescan_node)(device_node *node);
682d8e02e4SAxel Dörfler
697a6818d3SAxel Dörfler	status_t (*register_node)(device_node *parent, const char *moduleName,
702d8e02e4SAxel Dörfler					const device_attr *attrs, const io_resource *ioResources,
712d8e02e4SAxel Dörfler					device_node **_node);
727a6818d3SAxel Dörfler	status_t (*unregister_node)(device_node *node);
732d8e02e4SAxel Dörfler
74078d0317SAxel Dörfler	status_t (*get_driver)(device_node *node, driver_module_info **_module,
752d796918SAxel Dörfler					void **_cookie);
762d8e02e4SAxel Dörfler
777a6818d3SAxel Dörfler	device_node *(*get_root_node)();
787a6818d3SAxel Dörfler	status_t (*get_next_child_node)(device_node *parent,
797a6818d3SAxel Dörfler					const device_attr *attrs, device_node **node);
807a6818d3SAxel Dörfler	device_node *(*get_parent_node)(device_node *node);
817a6818d3SAxel Dörfler	void (*put_node)(device_node *node);
827a6818d3SAxel Dörfler
837a6818d3SAxel Dörfler	status_t (*publish_device)(device_node *node, const char *path,
847a6818d3SAxel Dörfler					const char *deviceModuleName);
857a6818d3SAxel Dörfler	status_t (*unpublish_device)(device_node *node, const char *path);
862d8e02e4SAxel Dörfler
872d8e02e4SAxel Dörfler#if 0
882d8e02e4SAxel Dörfler	status_t (*acquire_io_resources)(io_resource *resources);
892d8e02e4SAxel Dörfler	status_t (*release_io_resources)(const io_resource *resources);
902d8e02e4SAxel Dörfler
912d8e02e4SAxel Dörfler	int32 (*create_id)(const char *generator);
922d8e02e4SAxel Dörfler	status_t (*free_id)(const char *generator, uint32 id);
932d8e02e4SAxel Dörfler#endif
942d8e02e4SAxel Dörfler
952d796918SAxel Dörfler	status_t (*get_attr_uint8)(const device_node *node, const char *name,
962d8e02e4SAxel Dörfler					uint8 *value, bool recursive);
972d796918SAxel Dörfler	status_t (*get_attr_uint16)(const device_node *node, const char *name,
982d8e02e4SAxel Dörfler					uint16 *value, bool recursive);
992d796918SAxel Dörfler	status_t (*get_attr_uint32)(const device_node *node, const char *name,
1002d8e02e4SAxel Dörfler					uint32 *value, bool recursive);
1012d796918SAxel Dörfler	status_t (*get_attr_uint64)(const device_node *node, const char *name,
1022d8e02e4SAxel Dörfler					uint64 *value, bool recursive);
1032d796918SAxel Dörfler	status_t (*get_attr_string)(const device_node *node, const char *name,
1042d8e02e4SAxel Dörfler					const char **_value, bool recursive);
1052d796918SAxel Dörfler	status_t (*get_attr_raw)(const device_node *node, const char *name,
1062d8e02e4SAxel Dörfler					const void **_data, size_t *_size, bool recursive);
1072d8e02e4SAxel Dörfler
1082d8e02e4SAxel Dörfler	status_t (*get_next_attr)(device_node *node, device_attr **_attr);
1092d8e02e4SAxel Dörfler} device_manager_info;
1102d8e02e4SAxel Dörfler
1112d8e02e4SAxel Dörfler
1122d8e02e4SAxel Dörfler#define B_DEVICE_MANAGER_MODULE_NAME "system/device_manager/v1"
1132d8e02e4SAxel Dörfler
1142d8e02e4SAxel Dörfler
1157a6818d3SAxel Dörfler/* interface of device driver */
1162d8e02e4SAxel Dörfler
1172d8e02e4SAxel Dörflerstruct driver_module_info {
1182d8e02e4SAxel Dörfler	module_info info;
1192d8e02e4SAxel Dörfler
1202d8e02e4SAxel Dörfler	float (*supports_device)(device_node *parent);
1212d8e02e4SAxel Dörfler	status_t (*register_device)(device_node *parent);
1222d8e02e4SAxel Dörfler
1239f925127SAxel Dörfler	status_t (*init_driver)(device_node *node, void **_driverCookie);
1249f925127SAxel Dörfler	void (*uninit_driver)(void *driverCookie);
1259f925127SAxel Dörfler	status_t (*register_child_devices)(void *driverCookie);
1269f925127SAxel Dörfler	status_t (*rescan_child_devices)(void *driverCookie);
1273aecf8aaSAxel Dörfler
1289f925127SAxel Dörfler	void (*device_removed)(void *driverCookie);
1293aecf8aaSAxel Dörfler	status_t (*suspend)(void *driverCookie, int32 state);
1303aecf8aaSAxel Dörfler	status_t (*resume)(void *driverCookie);
1312d8e02e4SAxel Dörfler};
1322d8e02e4SAxel Dörfler
1332d8e02e4SAxel Dörfler
1342d796918SAxel Dörfler/* standard device node attributes */
1352d8e02e4SAxel Dörfler
1362d796918SAxel Dörfler#define B_DEVICE_PRETTY_NAME		"device/pretty name"		/* string */
1372d796918SAxel Dörfler#define B_DEVICE_MAPPING			"device/mapping"			/* string */
1382d796918SAxel Dörfler#define B_DEVICE_BUS				"device/bus"				/* string */
1392d796918SAxel Dörfler#define B_DEVICE_FIXED_CHILD		"device/fixed child"		/* string */
1407a6818d3SAxel Dörfler#define B_DEVICE_FLAGS				"device/flags"				/* uint32 */
1412d796918SAxel Dörfler
1422d796918SAxel Dörfler#define B_DEVICE_VENDOR_ID			"device/vendor"				/* uint16 */
1432d796918SAxel Dörfler#define B_DEVICE_ID					"device/id"					/* uint16 */
1442d796918SAxel Dörfler#define B_DEVICE_TYPE				"device/type"
1452d796918SAxel Dörfler	/* uint16, PCI base class */
1462d796918SAxel Dörfler#define B_DEVICE_SUB_TYPE			"device/subtype"
1472d796918SAxel Dörfler	/* uint16, PCI sub type */
1482d796918SAxel Dörfler#define B_DEVICE_INTERFACE			"device/interface"
1492d796918SAxel Dörfler	/* uint16, PCI class API */
1502d796918SAxel Dörfler
1512d796918SAxel Dörfler#define B_DEVICE_UNIQUE_ID			"device/unique id"			/* string */
1522d8e02e4SAxel Dörfler
1537a6818d3SAxel Dörfler/* device flags */
1542d8e02e4SAxel Dörfler#define B_FIND_CHILD_ON_DEMAND		0x01
1552d8e02e4SAxel Dörfler#define B_FIND_MULTIPLE_CHILDREN	0x02
1567a6818d3SAxel Dörfler#define B_KEEP_DRIVER_LOADED		0x04
1572d8e02e4SAxel Dörfler
1582d8e02e4SAxel Dörfler
1597a6818d3SAxel Dörfler/* interface of device */
1602d8e02e4SAxel Dörfler
1612d8e02e4SAxel Dörflertypedef struct io_request io_request;
1622d8e02e4SAxel Dörfler
1632d8e02e4SAxel Dörflerstruct device_module_info {
1642d8e02e4SAxel Dörfler	module_info info;
1652d8e02e4SAxel Dörfler
1669f925127SAxel Dörfler	status_t (*init_device)(void *driverCookie, void **_deviceCookie);
1677a6818d3SAxel Dörfler	void (*uninit_device)(void *deviceCookie);
1689f925127SAxel Dörfler	void (*device_removed)(void *deviceCookie);
1692d8e02e4SAxel Dörfler
1702d8e02e4SAxel Dörfler	status_t (*device_open)(void *deviceCookie, int openMode, void **_cookie);
1712d8e02e4SAxel Dörfler	status_t (*device_close)(void *cookie);
1722d8e02e4SAxel Dörfler	status_t (*device_free)(void *cookie);
1732d8e02e4SAxel Dörfler	status_t (*device_read)(void *cookie, off_t pos, void *buffer,
1742d8e02e4SAxel Dörfler		size_t *_length);
1752d8e02e4SAxel Dörfler	status_t (*device_write)(void *cookie, off_t pos, const void *buffer,
1762d8e02e4SAxel Dörfler		size_t *_length);
1772d8e02e4SAxel Dörfler	status_t (*device_ioctl)(void *cookie, int32 op, void *buffer,
1782d8e02e4SAxel Dörfler		size_t length);
1792d8e02e4SAxel Dörfler	status_t (*device_io)(void *cookie, io_request *request);
1802d8e02e4SAxel Dörfler};
1812d8e02e4SAxel Dörfler
1822d8e02e4SAxel Dörflerextern struct device_manager_info *gDeviceManager;
1832d8e02e4SAxel Dörfler
1842d8e02e4SAxel Dörfler#endif	/* _DEVICE_MANAGER_H */
185