1 /* ProcFS - root.c - by Alen Stojanov and David van Moolenbroek */
4 #include <machine/pci.h>
5 #include <minix/dmap.h>
8 static void root_hz(void);
9 static void root_uptime(void);
10 static void root_loadavg(void);
11 static void root_kinfo(void);
12 static void root_meminfo(void);
13 static void root_pci(void);
14 static void root_dmap(void);
15 static void root_ipcvecs(void);
17 struct file root_files
[] = {
18 { "hz", REG_ALL_MODE
, (data_t
) root_hz
},
19 { "uptime", REG_ALL_MODE
, (data_t
) root_uptime
},
20 { "loadavg", REG_ALL_MODE
, (data_t
) root_loadavg
},
21 { "kinfo", REG_ALL_MODE
, (data_t
) root_kinfo
},
22 { "meminfo", REG_ALL_MODE
, (data_t
) root_meminfo
},
23 { "pci", REG_ALL_MODE
, (data_t
) root_pci
},
24 { "dmap", REG_ALL_MODE
, (data_t
) root_dmap
},
25 { "cpuinfo", REG_ALL_MODE
, (data_t
) root_cpuinfo
},
26 { "ipcvecs", REG_ALL_MODE
, (data_t
) root_ipcvecs
},
30 /*===========================================================================*
32 *===========================================================================*/
33 static void root_hz(void)
35 /* Print the system clock frequency.
38 buf_printf("%lu\n", (long) sys_hz());
41 /*===========================================================================*
43 *===========================================================================*/
44 static void root_loadavg(void)
46 /* Print load averages.
51 if (procfs_getloadavg(loads
, 3) != 3)
54 avg
[0] = ldiv(100L * loads
[0].proc_load
/ loads
[0].ticks
, 100);
55 avg
[1] = ldiv(100L * loads
[1].proc_load
/ loads
[1].ticks
, 100);
56 avg
[2] = ldiv(100L * loads
[2].proc_load
/ loads
[2].ticks
, 100);
58 buf_printf("%ld.%0.2ld %ld.%02ld %ld.%02ld\n",
59 avg
[0].quot
, avg
[0].rem
, avg
[1].quot
, avg
[1].rem
,
60 avg
[2].quot
, avg
[2].rem
);
63 /*===========================================================================*
65 *===========================================================================*/
66 static void root_uptime(void)
68 /* Print the current uptime.
73 if (getuptime(&ticks
) != OK
)
75 division
= ldiv(100L * ticks
/ sys_hz(), 100L);
77 buf_printf("%ld.%0.2ld\n", division
.quot
, division
.rem
);
80 /*===========================================================================*
82 *===========================================================================*/
83 static void root_kinfo(void)
85 /* Print general kernel information.
89 if (sys_getkinfo(&kinfo
) != OK
)
92 buf_printf("%u %u\n", kinfo
.nr_procs
, kinfo
.nr_tasks
);
95 /*===========================================================================*
97 *===========================================================================*/
98 static void root_meminfo(void)
100 /* Print general memory information.
102 struct vm_stats_info vsi
;
104 if (vm_info_stats(&vsi
) != OK
)
107 buf_printf("%u %lu %lu %lu %lu\n", vsi
.vsi_pagesize
,
108 vsi
.vsi_total
, vsi
.vsi_free
, vsi
.vsi_largest
, vsi
.vsi_cached
);
111 /*===========================================================================*
113 *===========================================================================*/
114 static void root_pci(void)
116 /* Print information about PCI devices present in the system.
120 char *slot_name
, *dev_name
;
122 static int first
= TRUE
;
124 /* This should be taken care of behind the scenes by the PCI lib. */
130 /* Iterate over all devices, printing info for each of them. */
131 r
= pci_first_dev(&devind
, &vid
, &did
);
133 slot_name
= pci_slot_name(devind
);
134 dev_name
= pci_dev_name(vid
, did
);
136 bcr
= pci_attr_r8(devind
, PCI_BCR
);
137 scr
= pci_attr_r8(devind
, PCI_SCR
);
138 pifr
= pci_attr_r8(devind
, PCI_PIFR
);
140 buf_printf("%s %x/%x/%x %04X:%04X %s\n",
141 slot_name
? slot_name
: "-",
142 bcr
, scr
, pifr
, vid
, did
,
143 dev_name
? dev_name
: "");
145 r
= pci_next_dev(&devind
, &vid
, &did
);
149 /*===========================================================================*
151 *===========================================================================*/
152 static void root_dmap(void)
154 struct dmap dmap
[NR_DEVICES
];
157 if (getsysinfo(VFS_PROC_NR
, SI_DMAP_TAB
, dmap
, sizeof(dmap
)) != OK
)
160 for (i
= 0; i
< NR_DEVICES
; i
++) {
161 if (dmap
[i
].dmap_driver
== NONE
)
164 buf_printf("%u %s %u\n", i
, dmap
[i
].dmap_label
,
165 dmap
[i
].dmap_driver
);
169 /*===========================================================================*
171 *===========================================================================*/
172 static void root_ipcvecs(void)
174 extern struct minix_kerninfo
*_minix_kerninfo
;
175 extern struct minix_ipcvecs _minix_ipcvecs
;
177 /* only print this if the kernel provides the info; otherwise binaries
178 * will be using their own in-libc vectors that are normal symbols in the
181 if(!_minix_kerninfo
|| !(_minix_kerninfo
->ki_flags
& MINIX_KIF_IPCVECS
))
184 /* print the vectors with an descriptive name and the additional (k)
185 * to distinguish them from regular symbols.
187 #define PRINT_ENTRYPOINT(name) \
188 buf_printf("%08lx T %s(k)\n", _minix_ipcvecs.name ## _ptr, #name)
190 PRINT_ENTRYPOINT(sendrec
);
191 PRINT_ENTRYPOINT(send
);
192 PRINT_ENTRYPOINT(notify
);
193 PRINT_ENTRYPOINT(senda
);
194 PRINT_ENTRYPOINT(sendnb
);
195 PRINT_ENTRYPOINT(receive
);
196 PRINT_ENTRYPOINT(do_kernel_call
);