xref: /minix3/minix/include/minix/type.h (revision 1f3ef2b206fbc798d1aa54783fe2c426e1276fb5)
1 #ifndef _TYPE_H
2 #define _TYPE_H
3 
4 #include <sys/types.h>
5 #include <sys/endian.h>
6 
7 #include <machine/multiboot.h>
8 
9 #ifndef _MINIX_SYS_CONFIG_H
10 #include <minix/sys_config.h>
11 #endif
12 
13 #include <sys/sigtypes.h>
14 
15 #include <stdint.h>
16 #include <stddef.h>
17 
18 /* Type definitions. */
19 typedef unsigned int vir_clicks; 	/*  virtual addr/length in clicks */
20 typedef unsigned long phys_bytes;	/* physical addr/length in bytes */
21 typedef unsigned int phys_clicks;	/* physical addr/length in clicks */
22 typedef int endpoint_t;			/* process identifier */
23 typedef int32_t cp_grant_id_t;		/* A grant ID. */
24 typedef long unsigned int vir_bytes;	/* virtual addresses/lengths in bytes */
25 
26 /* Structure for virtual copying by means of a vector with requests. */
27 struct vir_addr {
28   endpoint_t proc_nr_e; /* NONE for phys, otherwise process endpoint */
29   vir_bytes offset;
30 };
31 
32 #define phys_cp_req vir_cp_req
33 struct vir_cp_req {
34   struct vir_addr src;
35   struct vir_addr dst;
36   phys_bytes count;
37 };
38 
39 /* Structures for SYS_VUMAP. */
40 struct vumap_vir {
41   union {
42 	cp_grant_id_t u_grant;	/* grant identifier, for non-SELF endpoint */
43 	vir_bytes u_addr;	/* local virtual address, for SELF endpoint */
44   } vv_u;
45   size_t vv_size;		/* size in bytes */
46 };
47 #define vv_grant	vv_u.u_grant
48 #define vv_addr		vv_u.u_addr
49 
50 struct vumap_phys {
51   phys_bytes vp_addr;		/* physical address */
52   size_t vp_size;		/* size in bytes */
53 };
54 
55 /* I/O vector structures used in protocols between services. */
56 typedef struct {
57   vir_bytes iov_addr;		/* address of an I/O buffer */
58   vir_bytes iov_size;		/* sizeof an I/O buffer */
59 } iovec_t;
60 
61 typedef struct {
62   cp_grant_id_t iov_grant;	/* grant ID of an I/O buffer */
63   vir_bytes iov_size;		/* sizeof an I/O buffer */
64 } iovec_s_t;
65 
66 /* PM passes the address of a structure of this type to KERNEL when
67  * sys_sigsend() is invoked as part of the signal catching mechanism.
68  * The structure contain all the information that KERNEL needs to build
69  * the signal stack.
70  */
71 struct sigmsg {
72   int sm_signo;			/* signal number being caught */
73   sigset_t sm_mask;		/* mask to restore when handler returns */
74   vir_bytes sm_sighandler;	/* address of handler */
75   vir_bytes sm_sigreturn;	/* address of _sigreturn in C library */
76   vir_bytes sm_stkptr;		/* user stack pointer */
77 };
78 
79 /* Structure used for computing per-process average CPU utilization. */
80 struct cpuavg {
81 	clock_t ca_base;	/* start of current per-second slot, or 0 */
82 	uint32_t ca_run;	/* running ticks since start of slot, FSCALE */
83 	uint32_t ca_last;	/* running ticks during last second, FSCALE */
84 	uint32_t ca_avg;	/* decaying CPU utilization average, FSCALE */
85 };
86 
87 /* Load data accounted every this no. of seconds. */
88 #define _LOAD_UNIT_SECS		 6 	/* Changing this breaks ABI. */
89 
90 /* Load data history is kept for this long. */
91 #define _LOAD_HISTORY_MINUTES	15	/* Changing this breaks ABI. */
92 #define _LOAD_HISTORY_SECONDS	(60*_LOAD_HISTORY_MINUTES)
93 
94 /* We need this many slots to store the load history. */
95 #define _LOAD_HISTORY	(_LOAD_HISTORY_SECONDS/_LOAD_UNIT_SECS)
96 
97 /* Runnable processes and other load-average information. */
98 struct loadinfo {
99   u16_t proc_load_history[_LOAD_HISTORY];	/* history of proc_s_cur */
100   u16_t proc_last_slot;
101   clock_t last_clock;
102 };
103 
104 struct kclockinfo {
105   time_t boottime;		/* number of seconds since UNIX epoch */
106 #if BYTE_ORDER == LITTLE_ENDIAN
107   clock_t uptime;		/* number of clock ticks since system boot */
108   uint32_t _rsvd1;		/* reserved for 64-bit uptime */
109   clock_t realtime;		/* real time in clock ticks since boot */
110   uint32_t _rsvd2;		/* reserved for 64-bit real time */
111 #elif BYTE_ORDER == BIG_ENDIAN
112   uint32_t _rsvd1;		/* reserved for 64-bit uptime */
113   clock_t uptime;		/* number of clock ticks since system boot */
114   uint32_t _rsvd2;		/* reserved for 64-bit real time */
115   clock_t realtime;		/* real time in clock ticks since boot */
116 #else
117 #error "unknown endianness"
118 #endif
119   uint32_t hz;			/* clock frequency in ticks per second */
120 };
121 
122 struct machine {
123   unsigned processors_count;	/* how many cpus are available */
124   unsigned bsp_id;		/* id of the bootstrap cpu */
125   int padding;			/* used to be protected */
126   int apic_enabled; /* does the kernel use APIC or not? */
127   phys_bytes	acpi_rsdp; /* where is the acpi RSDP */
128   unsigned int board_id;   /* Identifier for the board see   */
129                            /* include/minix/board.h for more */
130                            /* information.                   */
131 };
132 
133 struct io_range
134 {
135 	unsigned ior_base;	/* Lowest I/O port in range */
136 	unsigned ior_limit;	/* Highest I/O port in range */
137 };
138 
139 struct minix_mem_range
140 {
141 	phys_bytes mr_base;	/* Lowest memory address in range */
142 	phys_bytes mr_limit;	/* Highest memory address in range */
143 };
144 
145 #define PROC_NAME_LEN   16
146 
147 /* List of boot-time processes set in kernel/table.c. */
148 struct boot_image {
149   int proc_nr;                    	/* process number to use */
150   char proc_name[PROC_NAME_LEN];        /* name in process table */
151   endpoint_t endpoint;                  /* endpoint number when started */
152   phys_bytes start_addr;		/* Where it's in memory */
153   phys_bytes len;
154 };
155 
156 /* Memory chunks. */
157 struct memory {
158 	phys_bytes	base;
159 	phys_bytes	size;
160 };
161 
162 #define STATICINIT(v, n) \
163 	if(!(v)) {	\
164 		if(!((v) = alloc_contig(sizeof(*(v)) * (n), 0, NULL))) { \
165 			panic("allocating " #v " failed: %d", n);	\
166 		}	\
167 	}
168 
169 /* The kernel outputs diagnostic messages in a circular buffer. */
170 struct kmessages {
171   int km_next;                          /* next index to write */
172   int km_size;                          /* current size in buffer */
173   char km_buf[_KMESS_BUF_SIZE];          /* buffer for messages */
174   char kmess_buf[80*25];           /* printable copy of message buffer */
175   int blpos;				/* kmess_buf position */
176 };
177 
178 #include <minix/config.h>
179 #include <machine/interrupt.h>
180 
181 /* randomness struct: random sources after interrupts: */
182 #define RANDOM_SOURCES			16
183 #define RANDOM_ELEMENTS			64
184 
185 typedef unsigned short rand_t;
186 
187 struct k_randomness {
188   int random_elements, random_sources;
189   struct k_randomness_bin {
190         int r_next;                             /* next index to write */
191         int r_size;                             /* number of random elements */
192         rand_t r_buf[RANDOM_ELEMENTS]; /* buffer for random info */
193   } bin[RANDOM_SOURCES];
194 };
195 
196 /* ARM free-running timer information. */
197 struct arm_frclock {
198 	u64_t hz;		/* tcrr frequency */
199 	u32_t tcrr;		/* tcrr address */
200 };
201 
202 /* The userland ABI portion of general information exposed by the kernel.
203  * This structure may only ever be extended with new fields!
204  */
205 struct kuserinfo {
206 	size_t kui_size;	/* size of this structure, for ABI testing */
207 	vir_bytes kui_user_sp;	/* initial stack pointer for exec'd process */
208 };
209 
210 /* If MINIX_KIF_USERINFO is set, use this to check for a particular field. */
211 #define KUSERINFO_HAS_FIELD(kui,f) \
212 	(kui->kui_size >= offsetof(struct kuserinfo, f) + sizeof(kui->f))
213 
214 struct minix_kerninfo {
215 	/* Binaries will depend on the offsets etc. in this structure, so it
216 	 * can't be changed willy-nilly. In other words, it is ABI-restricted.
217 	 * However, various fields are to be used by services only, and are not
218 	 * to be used by userland directly. For pointers to non-userland-ABI
219 	 * structures, these structures themselves may be changed without
220 	 * breaking the userland ABI.
221 	 *
222 	 * There is currently one important legacy exception: the 'kinfo'
223 	 * structure should not be part of the userland ABI, but one of its
224 	 * fields, "user_sp" at offset 2440, is used by legacy user binaries.
225 	 * This field has since been moved into the 'kuserinfo' structure, but
226 	 * it will take another major release before we can start changing the
227 	 * layout of the 'kinfo' structure.
228 	 */
229 #define KERNINFO_MAGIC 0xfc3b84bf
230 	u32_t kerninfo_magic;
231 	u32_t minix_feature_flags;	/* features in minix kernel */
232 	u32_t ki_flags;			/* what is present in this struct */
233 	u32_t flags_unused2;
234 	u32_t flags_unused3;
235 	u32_t flags_unused4;
236 	struct kinfo		*kinfo;			/* see note above! */
237 	struct machine		*machine;		/* NOT userland ABI */
238 	struct kmessages	*kmessages;		/* NOT userland ABI */
239 	struct loadinfo		*loadinfo;		/* NOT userland ABI */
240 	struct minix_ipcvecs	*minix_ipcvecs;		/* userland ABI */
241 	struct kuserinfo	*kuserinfo;		/* userland ABI */
242 	struct arm_frclock	*arm_frclock;		/* NOT userland ABI */
243 	volatile struct kclockinfo	*kclockinfo;	/* NOT userland ABI */
244 };
245 
246 #define MINIX_KIF_IPCVECS	(1L << 0)	/* minix_ipcvecs is valid */
247 #define MINIX_KIF_USERINFO	(1L << 1)	/* kuserinfo is valid */
248 
249 #endif /* _TYPE_H */
250