xref: /original-bsd/sys/sys/device.h (revision f737e041)
1 /*
2  * Copyright (c) 1992, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This software was developed by the Computer Systems Engineering group
6  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7  * contributed to Berkeley.
8  *
9  * All advertising materials mentioning features or use of this software
10  * must display the following acknowledgement:
11  *	This product includes software developed by the University of
12  *	California, Lawrence Berkeley Laboratory.
13  *
14  * %sccs.include.redist.c%
15  *
16  *	@(#)device.h	8.2 (Berkeley) 02/17/94
17  */
18 
19 #ifndef _SYS_DEVICE_H_
20 #define	_SYS_DEVICE_H_
21 
22 /*
23  * Minimal device structures.
24  * Note that all ``system'' device types are listed here.
25  */
26 enum devclass {
27 	DV_DULL,		/* generic, no special info */
28 	DV_CPU,			/* CPU (carries resource utilization) */
29 	DV_DISK,		/* disk drive (label, etc) */
30 	DV_IFNET,		/* network interface */
31 	DV_TAPE,		/* tape device */
32 	DV_TTY			/* serial line interface (???) */
33 };
34 
35 struct device {
36 	enum	devclass dv_class;	/* this device's classification */
37 	struct	device *dv_next;	/* next in list of all */
38 	struct	cfdata *dv_cfdata;	/* config data that found us */
39 	int	dv_unit;		/* device unit number */
40 	char	dv_xname[16];		/* external name (name + unit) */
41 	struct	device *dv_parent;	/* pointer to parent device */
42 };
43 
44 /* `event' counters (use zero or more per device instance, as needed) */
45 struct evcnt {
46 	struct	evcnt *ev_next;		/* linked list */
47 	struct	device *ev_dev;		/* associated device */
48 	int	ev_count;		/* how many have occurred */
49 	char	ev_name[8];		/* what to call them (systat display) */
50 };
51 
52 /*
53  * Configuration data (i.e., data placed in ioconf.c).
54  */
55 struct cfdata {
56 	struct	cfdriver *cf_driver;	/* config driver */
57 	short	cf_unit;		/* unit number */
58 	short	cf_fstate;		/* finding state (below) */
59 	int	*cf_loc;		/* locators (machine dependent) */
60 	int	cf_flags;		/* flags from config */
61 	short	*cf_parents;		/* potential parents */
62 	void	(**cf_ivstubs)();	/* config-generated vectors, if any */
63 };
64 #define FSTATE_NOTFOUND	0	/* has not been found */
65 #define	FSTATE_FOUND	1	/* has been found */
66 #define	FSTATE_STAR	2	/* duplicable */
67 
68 typedef int (*cfmatch_t) __P((struct device *, struct cfdata *, void *));
69 
70 /*
71  * `configuration' driver (what the machine-independent autoconf uses).
72  * As devices are found, they are applied against all the potential matches.
73  * The one with the best match is taken, and a device structure (plus any
74  * other data desired) is allocated.  Pointers to these are placed into
75  * an array of pointers.  The array itself must be dynamic since devices
76  * can be found long after the machine is up and running.
77  */
78 struct cfdriver {
79 	void	**cd_devs;		/* devices found */
80 	char	*cd_name;		/* device name */
81 	cfmatch_t cd_match;		/* returns a match level */
82 	void	(*cd_attach) __P((struct device *, struct device *, void *));
83 	enum	devclass cd_class;	/* device classification */
84 	size_t	cd_devsize;		/* size of dev data (for malloc) */
85 	void	*cd_aux;		/* additional driver, if any */
86 	int	cd_ndevs;		/* size of cd_devs array */
87 };
88 
89 /*
90  * Configuration printing functions, and their return codes.  The second
91  * argument is NULL if the device was configured; otherwise it is the name
92  * of the parent device.  The return value is ignored if the device was
93  * configured, so most functions can return UNCONF unconditionally.
94  */
95 typedef int (*cfprint_t) __P((void *, char *));
96 #define	QUIET	0		/* print nothing */
97 #define	UNCONF	1		/* print " not configured\n" */
98 #define	UNSUPP	2		/* print " not supported\n" */
99 
100 /*
101  * Pseudo-device attach information (function + number of pseudo-devs).
102  */
103 struct pdevinit {
104 	void	(*pdev_attach) __P((int));
105 	int	pdev_count;
106 };
107 
108 struct	device *alldevs;	/* head of list of all devices */
109 struct	evcnt *allevents;	/* head of list of all events */
110 
111 struct cfdata *config_search __P((cfmatch_t, struct device *, void *));
112 struct cfdata *config_rootsearch __P((cfmatch_t, char *, void *));
113 int config_found __P((struct device *, void *, cfprint_t));
114 int config_rootfound __P((char *, void *));
115 void config_attach __P((struct device *, struct cfdata *, void *, cfprint_t));
116 void evcnt_attach __P((struct device *, const char *, struct evcnt *));
117 #endif /* !_SYS_DEVICE_H_ */
118