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);
16 struct file root_files
[] = {
17 { "hz", REG_ALL_MODE
, (data_t
) root_hz
},
18 { "uptime", REG_ALL_MODE
, (data_t
) root_uptime
},
19 { "loadavg", REG_ALL_MODE
, (data_t
) root_loadavg
},
20 { "kinfo", REG_ALL_MODE
, (data_t
) root_kinfo
},
21 { "meminfo", REG_ALL_MODE
, (data_t
) root_meminfo
},
22 { "pci", REG_ALL_MODE
, (data_t
) root_pci
},
23 { "dmap", REG_ALL_MODE
, (data_t
) root_dmap
},
24 { "cpuinfo", REG_ALL_MODE
, (data_t
) root_cpuinfo
},
28 /*===========================================================================*
30 *===========================================================================*/
31 static void root_hz(void)
33 /* Print the system clock frequency.
36 buf_printf("%lu\n", (long) sys_hz());
39 /*===========================================================================*
41 *===========================================================================*/
42 static void root_loadavg(void)
44 /* Print load averages.
49 if (procfs_getloadavg(loads
, 3) != 3)
52 avg
[0] = ldiv(100L * loads
[0].proc_load
/ loads
[0].ticks
, 100);
53 avg
[1] = ldiv(100L * loads
[1].proc_load
/ loads
[1].ticks
, 100);
54 avg
[2] = ldiv(100L * loads
[2].proc_load
/ loads
[2].ticks
, 100);
56 buf_printf("%ld.%0.2ld %ld.%02ld %ld.%02ld\n",
57 avg
[0].quot
, avg
[0].rem
, avg
[1].quot
, avg
[1].rem
,
58 avg
[2].quot
, avg
[2].rem
);
61 /*===========================================================================*
63 *===========================================================================*/
64 static void root_uptime(void)
66 /* Print the current uptime.
71 if (getuptime(&ticks
) != OK
)
73 division
= ldiv(100L * ticks
/ sys_hz(), 100L);
75 buf_printf("%ld.%0.2ld\n", division
.quot
, division
.rem
);
78 /*===========================================================================*
80 *===========================================================================*/
81 static void root_kinfo(void)
83 /* Print general kernel information.
87 if (sys_getkinfo(&kinfo
) != OK
)
90 buf_printf("%u %u\n", kinfo
.nr_procs
, kinfo
.nr_tasks
);
93 /*===========================================================================*
95 *===========================================================================*/
96 static void root_meminfo(void)
98 /* Print general memory information.
100 struct vm_stats_info vsi
;
102 if (vm_info_stats(&vsi
) != OK
)
105 buf_printf("%u %lu %lu %lu %lu\n", vsi
.vsi_pagesize
,
106 vsi
.vsi_total
, vsi
.vsi_free
, vsi
.vsi_largest
, vsi
.vsi_cached
);
109 /*===========================================================================*
111 *===========================================================================*/
112 static void root_pci(void)
114 /* Print information about PCI devices present in the system.
118 char *slot_name
, *dev_name
;
120 static int first
= TRUE
;
122 /* This should be taken care of behind the scenes by the PCI lib. */
128 /* Iterate over all devices, printing info for each of them. */
129 r
= pci_first_dev(&devind
, &vid
, &did
);
131 slot_name
= pci_slot_name(devind
);
132 dev_name
= pci_dev_name(vid
, did
);
134 bcr
= pci_attr_r8(devind
, PCI_BCR
);
135 scr
= pci_attr_r8(devind
, PCI_SCR
);
136 pifr
= pci_attr_r8(devind
, PCI_PIFR
);
138 buf_printf("%s %x/%x/%x %04X:%04X %s\n",
139 slot_name
? slot_name
: "-",
140 bcr
, scr
, pifr
, vid
, did
,
141 dev_name
? dev_name
: "");
143 r
= pci_next_dev(&devind
, &vid
, &did
);
147 /*===========================================================================*
149 *===========================================================================*/
150 static void root_dmap(void)
152 struct dmap dmap
[NR_DEVICES
];
155 if (getsysinfo(VFS_PROC_NR
, SI_DMAP_TAB
, dmap
, sizeof(dmap
)) != OK
)
158 for (i
= 0; i
< NR_DEVICES
; i
++) {
159 if (dmap
[i
].dmap_driver
== NONE
)
162 buf_printf("%u %s %u\n", i
, dmap
[i
].dmap_label
,
163 dmap
[i
].dmap_driver
);