1 /* ProcFS - root.c - by Alen Stojanov and David van Moolenbroek */
4 #include <machine/pci.h>
5 #include <minix/dmap.h>
9 static void root_hz(void);
10 static void root_uptime(void);
11 static void root_loadavg(void);
12 static void root_kinfo(void);
13 static void root_meminfo(void);
14 static void root_pci(void);
15 static void root_dmap(void);
16 static void root_ipcvecs(void);
18 struct file root_files
[] = {
19 { "hz", REG_ALL_MODE
, (data_t
) root_hz
},
20 { "uptime", REG_ALL_MODE
, (data_t
) root_uptime
},
21 { "loadavg", REG_ALL_MODE
, (data_t
) root_loadavg
},
22 { "kinfo", REG_ALL_MODE
, (data_t
) root_kinfo
},
23 { "meminfo", REG_ALL_MODE
, (data_t
) root_meminfo
},
24 { "pci", REG_ALL_MODE
, (data_t
) root_pci
},
25 { "dmap", REG_ALL_MODE
, (data_t
) root_dmap
},
26 { "cpuinfo", REG_ALL_MODE
, (data_t
) root_cpuinfo
},
27 { "ipcvecs", REG_ALL_MODE
, (data_t
) root_ipcvecs
},
28 { "mounts", REG_ALL_MODE
, (data_t
) root_mounts
},
32 /*===========================================================================*
34 *===========================================================================*/
35 static void root_hz(void)
37 /* Print the system clock frequency.
40 buf_printf("%lu\n", (long) sys_hz());
43 /*===========================================================================*
45 *===========================================================================*/
46 static void root_loadavg(void)
48 /* Print load averages.
53 if (procfs_getloadavg(loads
, 3) != 3)
56 avg
[0] = ldiv(100L * loads
[0].proc_load
/ loads
[0].ticks
, 100);
57 avg
[1] = ldiv(100L * loads
[1].proc_load
/ loads
[1].ticks
, 100);
58 avg
[2] = ldiv(100L * loads
[2].proc_load
/ loads
[2].ticks
, 100);
60 buf_printf("%ld.%0.2ld %ld.%02ld %ld.%02ld\n",
61 avg
[0].quot
, avg
[0].rem
, avg
[1].quot
, avg
[1].rem
,
62 avg
[2].quot
, avg
[2].rem
);
65 /*===========================================================================*
67 *===========================================================================*/
68 static void root_uptime(void)
70 /* Print the current uptime.
75 if (getuptime(&ticks
) != OK
)
77 division
= ldiv(100L * ticks
/ sys_hz(), 100L);
79 buf_printf("%ld.%0.2ld\n", division
.quot
, division
.rem
);
82 /*===========================================================================*
84 *===========================================================================*/
85 static void root_kinfo(void)
87 /* Print general kernel information.
91 if (sys_getkinfo(&kinfo
) != OK
)
94 buf_printf("%u %u\n", kinfo
.nr_procs
, kinfo
.nr_tasks
);
97 /*===========================================================================*
99 *===========================================================================*/
100 static void root_meminfo(void)
102 /* Print general memory information.
104 struct vm_stats_info vsi
;
106 if (vm_info_stats(&vsi
) != OK
)
109 buf_printf("%u %lu %lu %lu %lu\n", vsi
.vsi_pagesize
,
110 vsi
.vsi_total
, vsi
.vsi_free
, vsi
.vsi_largest
, vsi
.vsi_cached
);
113 /*===========================================================================*
115 *===========================================================================*/
116 static void root_pci(void)
118 /* Print information about PCI devices present in the system.
122 char *slot_name
, *dev_name
;
124 static int first
= TRUE
;
126 /* This should be taken care of behind the scenes by the PCI lib. */
132 /* Iterate over all devices, printing info for each of them. */
133 r
= pci_first_dev(&devind
, &vid
, &did
);
135 slot_name
= pci_slot_name(devind
);
136 dev_name
= pci_dev_name(vid
, did
);
138 bcr
= pci_attr_r8(devind
, PCI_BCR
);
139 scr
= pci_attr_r8(devind
, PCI_SCR
);
140 pifr
= pci_attr_r8(devind
, PCI_PIFR
);
142 buf_printf("%s %x/%x/%x %04X:%04X %s\n",
143 slot_name
? slot_name
: "-",
144 bcr
, scr
, pifr
, vid
, did
,
145 dev_name
? dev_name
: "");
147 r
= pci_next_dev(&devind
, &vid
, &did
);
151 /*===========================================================================*
153 *===========================================================================*/
154 static void root_dmap(void)
156 struct dmap dmap
[NR_DEVICES
];
159 if (getsysinfo(VFS_PROC_NR
, SI_DMAP_TAB
, dmap
, sizeof(dmap
)) != OK
)
162 for (i
= 0; i
< NR_DEVICES
; i
++) {
163 if (dmap
[i
].dmap_driver
== NONE
)
166 buf_printf("%u %s %u\n", i
, dmap
[i
].dmap_label
,
167 dmap
[i
].dmap_driver
);
171 /*===========================================================================*
173 *===========================================================================*/
174 static void root_ipcvecs(void)
176 extern struct minix_kerninfo
*_minix_kerninfo
;
177 extern struct minix_ipcvecs _minix_ipcvecs
;
179 /* only print this if the kernel provides the info; otherwise binaries
180 * will be using their own in-libc vectors that are normal symbols in the
183 if(!_minix_kerninfo
|| !(_minix_kerninfo
->ki_flags
& MINIX_KIF_IPCVECS
))
186 /* print the vectors with an descriptive name and the additional (k)
187 * to distinguish them from regular symbols.
189 #define PRINT_ENTRYPOINT(name) \
190 buf_printf("%08lx T %s(k)\n", _minix_ipcvecs.name, #name)
192 PRINT_ENTRYPOINT(sendrec
);
193 PRINT_ENTRYPOINT(send
);
194 PRINT_ENTRYPOINT(notify
);
195 PRINT_ENTRYPOINT(senda
);
196 PRINT_ENTRYPOINT(sendnb
);
197 PRINT_ENTRYPOINT(receive
);
198 PRINT_ENTRYPOINT(do_kernel_call
);