1433d6423SLionel Sambuc /* ProcFS - root.c - by Alen Stojanov and David van Moolenbroek */ 2433d6423SLionel Sambuc 3433d6423SLionel Sambuc #include "inc.h" 4433d6423SLionel Sambuc 5433d6423SLionel Sambuc #if defined (__i386__) 6433d6423SLionel Sambuc #include <machine/pci.h> 7433d6423SLionel Sambuc #endif 8433d6423SLionel Sambuc #include <minix/dmap.h> 9433d6423SLionel Sambuc #include "cpuinfo.h" 10433d6423SLionel Sambuc 11433d6423SLionel Sambuc static void root_hz(void); 12433d6423SLionel Sambuc static void root_uptime(void); 13433d6423SLionel Sambuc static void root_loadavg(void); 14433d6423SLionel Sambuc static void root_kinfo(void); 15433d6423SLionel Sambuc static void root_meminfo(void); 16433d6423SLionel Sambuc #if defined(__i386__) 17433d6423SLionel Sambuc static void root_pci(void); 18433d6423SLionel Sambuc #endif 19433d6423SLionel Sambuc static void root_dmap(void); 20433d6423SLionel Sambuc static void root_ipcvecs(void); 21433d6423SLionel Sambuc static void root_mounts(void); 22433d6423SLionel Sambuc 23433d6423SLionel Sambuc struct file root_files[] = { 24433d6423SLionel Sambuc { "hz", REG_ALL_MODE, (data_t) root_hz }, 25433d6423SLionel Sambuc { "uptime", REG_ALL_MODE, (data_t) root_uptime }, 26433d6423SLionel Sambuc { "loadavg", REG_ALL_MODE, (data_t) root_loadavg }, 27433d6423SLionel Sambuc { "kinfo", REG_ALL_MODE, (data_t) root_kinfo }, 28433d6423SLionel Sambuc { "meminfo", REG_ALL_MODE, (data_t) root_meminfo }, 29433d6423SLionel Sambuc #if defined(__i386__) 30433d6423SLionel Sambuc { "pci", REG_ALL_MODE, (data_t) root_pci }, 31433d6423SLionel Sambuc #endif 32433d6423SLionel Sambuc { "dmap", REG_ALL_MODE, (data_t) root_dmap }, 33433d6423SLionel Sambuc #if defined(__i386__) 34433d6423SLionel Sambuc { "cpuinfo", REG_ALL_MODE, (data_t) root_cpuinfo }, 35433d6423SLionel Sambuc #endif 36433d6423SLionel Sambuc { "ipcvecs", REG_ALL_MODE, (data_t) root_ipcvecs }, 37433d6423SLionel Sambuc { "mounts", REG_ALL_MODE, (data_t) root_mounts }, 38433d6423SLionel Sambuc { NULL, 0, NULL } 39433d6423SLionel Sambuc }; 40433d6423SLionel Sambuc 41433d6423SLionel Sambuc /*===========================================================================* 42433d6423SLionel Sambuc * root_hz * 43433d6423SLionel Sambuc *===========================================================================*/ 44433d6423SLionel Sambuc static void root_hz(void) 45433d6423SLionel Sambuc { 46433d6423SLionel Sambuc /* Print the system clock frequency. 47433d6423SLionel Sambuc */ 48433d6423SLionel Sambuc 49433d6423SLionel Sambuc buf_printf("%lu\n", (long) sys_hz()); 50433d6423SLionel Sambuc } 51433d6423SLionel Sambuc 52433d6423SLionel Sambuc /*===========================================================================* 53433d6423SLionel Sambuc * root_loadavg * 54433d6423SLionel Sambuc *===========================================================================*/ 55433d6423SLionel Sambuc static void root_loadavg(void) 56433d6423SLionel Sambuc { 57433d6423SLionel Sambuc /* Print load averages. 58433d6423SLionel Sambuc */ 59433d6423SLionel Sambuc struct load loads[3]; 60433d6423SLionel Sambuc ldiv_t avg[3]; 61433d6423SLionel Sambuc 62433d6423SLionel Sambuc if (procfs_getloadavg(loads, 3) != 3) 63433d6423SLionel Sambuc return; 64433d6423SLionel Sambuc 65433d6423SLionel Sambuc avg[0] = ldiv(100L * loads[0].proc_load / loads[0].ticks, 100); 66433d6423SLionel Sambuc avg[1] = ldiv(100L * loads[1].proc_load / loads[1].ticks, 100); 67433d6423SLionel Sambuc avg[2] = ldiv(100L * loads[2].proc_load / loads[2].ticks, 100); 68433d6423SLionel Sambuc 69433d6423SLionel Sambuc buf_printf("%ld.%02ld %ld.%02ld %ld.%02ld\n", 70433d6423SLionel Sambuc avg[0].quot, avg[0].rem, avg[1].quot, avg[1].rem, 71433d6423SLionel Sambuc avg[2].quot, avg[2].rem); 72433d6423SLionel Sambuc } 73433d6423SLionel Sambuc 74433d6423SLionel Sambuc /*===========================================================================* 75433d6423SLionel Sambuc * root_uptime * 76433d6423SLionel Sambuc *===========================================================================*/ 77433d6423SLionel Sambuc static void root_uptime(void) 78433d6423SLionel Sambuc { 79433d6423SLionel Sambuc /* Print the current uptime. 80433d6423SLionel Sambuc */ 81433d6423SLionel Sambuc clock_t ticks; 82433d6423SLionel Sambuc ldiv_t division; 83433d6423SLionel Sambuc 84433d6423SLionel Sambuc if (getticks(&ticks) != OK) 85433d6423SLionel Sambuc return; 86433d6423SLionel Sambuc division = ldiv(100L * ticks / sys_hz(), 100L); 87433d6423SLionel Sambuc 88433d6423SLionel Sambuc buf_printf("%ld.%0.2ld\n", division.quot, division.rem); 89433d6423SLionel Sambuc } 90433d6423SLionel Sambuc 91433d6423SLionel Sambuc /*===========================================================================* 92433d6423SLionel Sambuc * root_kinfo * 93433d6423SLionel Sambuc *===========================================================================*/ 94433d6423SLionel Sambuc static void root_kinfo(void) 95433d6423SLionel Sambuc { 96433d6423SLionel Sambuc /* Print general kernel information. 97433d6423SLionel Sambuc */ 98433d6423SLionel Sambuc struct kinfo kinfo; 99433d6423SLionel Sambuc 100433d6423SLionel Sambuc if (sys_getkinfo(&kinfo) != OK) 101433d6423SLionel Sambuc return; 102433d6423SLionel Sambuc 103433d6423SLionel Sambuc buf_printf("%u %u\n", kinfo.nr_procs, kinfo.nr_tasks); 104433d6423SLionel Sambuc } 105433d6423SLionel Sambuc 106433d6423SLionel Sambuc /*===========================================================================* 107433d6423SLionel Sambuc * root_meminfo * 108433d6423SLionel Sambuc *===========================================================================*/ 109433d6423SLionel Sambuc static void root_meminfo(void) 110433d6423SLionel Sambuc { 111433d6423SLionel Sambuc /* Print general memory information. 112433d6423SLionel Sambuc */ 113433d6423SLionel Sambuc struct vm_stats_info vsi; 114433d6423SLionel Sambuc 115433d6423SLionel Sambuc if (vm_info_stats(&vsi) != OK) 116433d6423SLionel Sambuc return; 117433d6423SLionel Sambuc 118433d6423SLionel Sambuc buf_printf("%u %lu %lu %lu %lu\n", vsi.vsi_pagesize, 119433d6423SLionel Sambuc vsi.vsi_total, vsi.vsi_free, vsi.vsi_largest, vsi.vsi_cached); 120433d6423SLionel Sambuc } 121433d6423SLionel Sambuc 122433d6423SLionel Sambuc /*===========================================================================* 123433d6423SLionel Sambuc * root_pci * 124433d6423SLionel Sambuc *===========================================================================*/ 125433d6423SLionel Sambuc #if defined(__i386__) 126433d6423SLionel Sambuc static void root_pci(void) 127433d6423SLionel Sambuc { 128433d6423SLionel Sambuc /* Print information about PCI devices present in the system. 129433d6423SLionel Sambuc */ 130*9e77ef50SLionel Sambuc u16_t vid, did, subvid, subdid; 131*9e77ef50SLionel Sambuc u8_t bcr, scr, pifr, rev; 132433d6423SLionel Sambuc char *slot_name, *dev_name; 133433d6423SLionel Sambuc int r, devind; 134433d6423SLionel Sambuc static int first = TRUE; 135433d6423SLionel Sambuc 136433d6423SLionel Sambuc /* This should be taken care of behind the scenes by the PCI lib. */ 137433d6423SLionel Sambuc if (first) { 138433d6423SLionel Sambuc pci_init(); 139433d6423SLionel Sambuc first = FALSE; 140433d6423SLionel Sambuc } 141433d6423SLionel Sambuc 142433d6423SLionel Sambuc /* Iterate over all devices, printing info for each of them. */ 143433d6423SLionel Sambuc r = pci_first_dev(&devind, &vid, &did); 144433d6423SLionel Sambuc while (r == 1) { 145433d6423SLionel Sambuc slot_name = pci_slot_name(devind); 146433d6423SLionel Sambuc dev_name = pci_dev_name(vid, did); 147433d6423SLionel Sambuc 148433d6423SLionel Sambuc bcr = pci_attr_r8(devind, PCI_BCR); 149433d6423SLionel Sambuc scr = pci_attr_r8(devind, PCI_SCR); 150433d6423SLionel Sambuc pifr = pci_attr_r8(devind, PCI_PIFR); 151*9e77ef50SLionel Sambuc rev = pci_attr_r8(devind, PCI_REV); 152*9e77ef50SLionel Sambuc subvid = pci_attr_r16(devind, PCI_SUBVID); 153*9e77ef50SLionel Sambuc subdid = pci_attr_r16(devind, PCI_SUBDID); 154433d6423SLionel Sambuc 155*9e77ef50SLionel Sambuc buf_printf("%s %x/%x/%x/%x %04X:%04X:%04X:%04X %s\n", 156*9e77ef50SLionel Sambuc slot_name ? slot_name : "-1.-1.-1.-1", 157*9e77ef50SLionel Sambuc bcr, scr, pifr, rev, 158*9e77ef50SLionel Sambuc vid, did, subvid, subdid, 159433d6423SLionel Sambuc dev_name ? dev_name : ""); 160433d6423SLionel Sambuc 161433d6423SLionel Sambuc r = pci_next_dev(&devind, &vid, &did); 162433d6423SLionel Sambuc } 163433d6423SLionel Sambuc } 164433d6423SLionel Sambuc #endif /* defined(__i386__) */ 165433d6423SLionel Sambuc 166433d6423SLionel Sambuc /*===========================================================================* 167433d6423SLionel Sambuc * root_dmap * 168433d6423SLionel Sambuc *===========================================================================*/ 169433d6423SLionel Sambuc static void root_dmap(void) 170433d6423SLionel Sambuc { 171433d6423SLionel Sambuc struct dmap dmap[NR_DEVICES]; 172433d6423SLionel Sambuc int i; 173433d6423SLionel Sambuc 174433d6423SLionel Sambuc if (getsysinfo(VFS_PROC_NR, SI_DMAP_TAB, dmap, sizeof(dmap)) != OK) 175433d6423SLionel Sambuc return; 176433d6423SLionel Sambuc 177433d6423SLionel Sambuc for (i = 0; i < NR_DEVICES; i++) { 178433d6423SLionel Sambuc if (dmap[i].dmap_driver == NONE) 179433d6423SLionel Sambuc continue; 180433d6423SLionel Sambuc 181433d6423SLionel Sambuc buf_printf("%u %s %u\n", i, dmap[i].dmap_label, 182433d6423SLionel Sambuc dmap[i].dmap_driver); 183433d6423SLionel Sambuc } 184433d6423SLionel Sambuc } 185433d6423SLionel Sambuc 186433d6423SLionel Sambuc /*===========================================================================* 187433d6423SLionel Sambuc * root_ipcvecs * 188433d6423SLionel Sambuc *===========================================================================*/ 189433d6423SLionel Sambuc static void root_ipcvecs(void) 190433d6423SLionel Sambuc { 191433d6423SLionel Sambuc extern struct minix_kerninfo *_minix_kerninfo; 192433d6423SLionel Sambuc extern struct minix_ipcvecs _minix_ipcvecs; 193433d6423SLionel Sambuc 194433d6423SLionel Sambuc /* only print this if the kernel provides the info; otherwise binaries 195433d6423SLionel Sambuc * will be using their own in-libc vectors that are normal symbols in the 196433d6423SLionel Sambuc * binary. 197433d6423SLionel Sambuc */ 198433d6423SLionel Sambuc if(!_minix_kerninfo || !(_minix_kerninfo->ki_flags & MINIX_KIF_IPCVECS)) 199433d6423SLionel Sambuc return; 200433d6423SLionel Sambuc 201433d6423SLionel Sambuc /* print the vectors with an descriptive name and the additional (k) 202433d6423SLionel Sambuc * to distinguish them from regular symbols. 203433d6423SLionel Sambuc */ 204433d6423SLionel Sambuc #define PRINT_ENTRYPOINT(name) \ 205433d6423SLionel Sambuc buf_printf("%08lx T %s(k)\n", _minix_ipcvecs.name, #name) 206433d6423SLionel Sambuc 207433d6423SLionel Sambuc PRINT_ENTRYPOINT(sendrec); 208433d6423SLionel Sambuc PRINT_ENTRYPOINT(send); 209433d6423SLionel Sambuc PRINT_ENTRYPOINT(notify); 210433d6423SLionel Sambuc PRINT_ENTRYPOINT(senda); 211433d6423SLionel Sambuc PRINT_ENTRYPOINT(sendnb); 212433d6423SLionel Sambuc PRINT_ENTRYPOINT(receive); 213433d6423SLionel Sambuc PRINT_ENTRYPOINT(do_kernel_call); 214433d6423SLionel Sambuc } 215433d6423SLionel Sambuc 216433d6423SLionel Sambuc /*===========================================================================* 217433d6423SLionel Sambuc * root_mounts * 218433d6423SLionel Sambuc *===========================================================================*/ 219433d6423SLionel Sambuc static void 220433d6423SLionel Sambuc root_mounts(void) 221433d6423SLionel Sambuc { 222433d6423SLionel Sambuc struct statvfs buf[NR_MNTS]; 223433d6423SLionel Sambuc int i, count; 224433d6423SLionel Sambuc 225433d6423SLionel Sambuc if ((count = getvfsstat(buf, sizeof(buf), ST_NOWAIT)) < 0) 226433d6423SLionel Sambuc return; 227433d6423SLionel Sambuc 228433d6423SLionel Sambuc for (i = 0; i < count; i++) { 229433d6423SLionel Sambuc buf_printf("%s on %s type %s (%s)\n", buf[i].f_mntfromname, 230433d6423SLionel Sambuc buf[i].f_mntonname, buf[i].f_fstypename, 231433d6423SLionel Sambuc (buf[i].f_flag & ST_RDONLY) ? "ro" : "rw"); 232433d6423SLionel Sambuc } 233433d6423SLionel Sambuc } 234