1*433d6423SLionel Sambuc /* ProcFS - root.c - by Alen Stojanov and David van Moolenbroek */ 2*433d6423SLionel Sambuc 3*433d6423SLionel Sambuc #include "inc.h" 4*433d6423SLionel Sambuc 5*433d6423SLionel Sambuc #if defined (__i386__) 6*433d6423SLionel Sambuc #include <machine/pci.h> 7*433d6423SLionel Sambuc #endif 8*433d6423SLionel Sambuc #include <minix/dmap.h> 9*433d6423SLionel Sambuc #include "cpuinfo.h" 10*433d6423SLionel Sambuc 11*433d6423SLionel Sambuc static void root_hz(void); 12*433d6423SLionel Sambuc static void root_uptime(void); 13*433d6423SLionel Sambuc static void root_loadavg(void); 14*433d6423SLionel Sambuc static void root_kinfo(void); 15*433d6423SLionel Sambuc static void root_meminfo(void); 16*433d6423SLionel Sambuc #if defined(__i386__) 17*433d6423SLionel Sambuc static void root_pci(void); 18*433d6423SLionel Sambuc #endif 19*433d6423SLionel Sambuc static void root_dmap(void); 20*433d6423SLionel Sambuc static void root_ipcvecs(void); 21*433d6423SLionel Sambuc static void root_mounts(void); 22*433d6423SLionel Sambuc 23*433d6423SLionel Sambuc struct file root_files[] = { 24*433d6423SLionel Sambuc { "hz", REG_ALL_MODE, (data_t) root_hz }, 25*433d6423SLionel Sambuc { "uptime", REG_ALL_MODE, (data_t) root_uptime }, 26*433d6423SLionel Sambuc { "loadavg", REG_ALL_MODE, (data_t) root_loadavg }, 27*433d6423SLionel Sambuc { "kinfo", REG_ALL_MODE, (data_t) root_kinfo }, 28*433d6423SLionel Sambuc { "meminfo", REG_ALL_MODE, (data_t) root_meminfo }, 29*433d6423SLionel Sambuc #if defined(__i386__) 30*433d6423SLionel Sambuc { "pci", REG_ALL_MODE, (data_t) root_pci }, 31*433d6423SLionel Sambuc #endif 32*433d6423SLionel Sambuc { "dmap", REG_ALL_MODE, (data_t) root_dmap }, 33*433d6423SLionel Sambuc #if defined(__i386__) 34*433d6423SLionel Sambuc { "cpuinfo", REG_ALL_MODE, (data_t) root_cpuinfo }, 35*433d6423SLionel Sambuc #endif 36*433d6423SLionel Sambuc { "ipcvecs", REG_ALL_MODE, (data_t) root_ipcvecs }, 37*433d6423SLionel Sambuc { "mounts", REG_ALL_MODE, (data_t) root_mounts }, 38*433d6423SLionel Sambuc { NULL, 0, NULL } 39*433d6423SLionel Sambuc }; 40*433d6423SLionel Sambuc 41*433d6423SLionel Sambuc /*===========================================================================* 42*433d6423SLionel Sambuc * root_hz * 43*433d6423SLionel Sambuc *===========================================================================*/ 44*433d6423SLionel Sambuc static void root_hz(void) 45*433d6423SLionel Sambuc { 46*433d6423SLionel Sambuc /* Print the system clock frequency. 47*433d6423SLionel Sambuc */ 48*433d6423SLionel Sambuc 49*433d6423SLionel Sambuc buf_printf("%lu\n", (long) sys_hz()); 50*433d6423SLionel Sambuc } 51*433d6423SLionel Sambuc 52*433d6423SLionel Sambuc /*===========================================================================* 53*433d6423SLionel Sambuc * root_loadavg * 54*433d6423SLionel Sambuc *===========================================================================*/ 55*433d6423SLionel Sambuc static void root_loadavg(void) 56*433d6423SLionel Sambuc { 57*433d6423SLionel Sambuc /* Print load averages. 58*433d6423SLionel Sambuc */ 59*433d6423SLionel Sambuc struct load loads[3]; 60*433d6423SLionel Sambuc ldiv_t avg[3]; 61*433d6423SLionel Sambuc 62*433d6423SLionel Sambuc if (procfs_getloadavg(loads, 3) != 3) 63*433d6423SLionel Sambuc return; 64*433d6423SLionel Sambuc 65*433d6423SLionel Sambuc avg[0] = ldiv(100L * loads[0].proc_load / loads[0].ticks, 100); 66*433d6423SLionel Sambuc avg[1] = ldiv(100L * loads[1].proc_load / loads[1].ticks, 100); 67*433d6423SLionel Sambuc avg[2] = ldiv(100L * loads[2].proc_load / loads[2].ticks, 100); 68*433d6423SLionel Sambuc 69*433d6423SLionel Sambuc buf_printf("%ld.%02ld %ld.%02ld %ld.%02ld\n", 70*433d6423SLionel Sambuc avg[0].quot, avg[0].rem, avg[1].quot, avg[1].rem, 71*433d6423SLionel Sambuc avg[2].quot, avg[2].rem); 72*433d6423SLionel Sambuc } 73*433d6423SLionel Sambuc 74*433d6423SLionel Sambuc /*===========================================================================* 75*433d6423SLionel Sambuc * root_uptime * 76*433d6423SLionel Sambuc *===========================================================================*/ 77*433d6423SLionel Sambuc static void root_uptime(void) 78*433d6423SLionel Sambuc { 79*433d6423SLionel Sambuc /* Print the current uptime. 80*433d6423SLionel Sambuc */ 81*433d6423SLionel Sambuc clock_t ticks; 82*433d6423SLionel Sambuc ldiv_t division; 83*433d6423SLionel Sambuc 84*433d6423SLionel Sambuc if (getticks(&ticks) != OK) 85*433d6423SLionel Sambuc return; 86*433d6423SLionel Sambuc division = ldiv(100L * ticks / sys_hz(), 100L); 87*433d6423SLionel Sambuc 88*433d6423SLionel Sambuc buf_printf("%ld.%0.2ld\n", division.quot, division.rem); 89*433d6423SLionel Sambuc } 90*433d6423SLionel Sambuc 91*433d6423SLionel Sambuc /*===========================================================================* 92*433d6423SLionel Sambuc * root_kinfo * 93*433d6423SLionel Sambuc *===========================================================================*/ 94*433d6423SLionel Sambuc static void root_kinfo(void) 95*433d6423SLionel Sambuc { 96*433d6423SLionel Sambuc /* Print general kernel information. 97*433d6423SLionel Sambuc */ 98*433d6423SLionel Sambuc struct kinfo kinfo; 99*433d6423SLionel Sambuc 100*433d6423SLionel Sambuc if (sys_getkinfo(&kinfo) != OK) 101*433d6423SLionel Sambuc return; 102*433d6423SLionel Sambuc 103*433d6423SLionel Sambuc buf_printf("%u %u\n", kinfo.nr_procs, kinfo.nr_tasks); 104*433d6423SLionel Sambuc } 105*433d6423SLionel Sambuc 106*433d6423SLionel Sambuc /*===========================================================================* 107*433d6423SLionel Sambuc * root_meminfo * 108*433d6423SLionel Sambuc *===========================================================================*/ 109*433d6423SLionel Sambuc static void root_meminfo(void) 110*433d6423SLionel Sambuc { 111*433d6423SLionel Sambuc /* Print general memory information. 112*433d6423SLionel Sambuc */ 113*433d6423SLionel Sambuc struct vm_stats_info vsi; 114*433d6423SLionel Sambuc 115*433d6423SLionel Sambuc if (vm_info_stats(&vsi) != OK) 116*433d6423SLionel Sambuc return; 117*433d6423SLionel Sambuc 118*433d6423SLionel Sambuc buf_printf("%u %lu %lu %lu %lu\n", vsi.vsi_pagesize, 119*433d6423SLionel Sambuc vsi.vsi_total, vsi.vsi_free, vsi.vsi_largest, vsi.vsi_cached); 120*433d6423SLionel Sambuc } 121*433d6423SLionel Sambuc 122*433d6423SLionel Sambuc /*===========================================================================* 123*433d6423SLionel Sambuc * root_pci * 124*433d6423SLionel Sambuc *===========================================================================*/ 125*433d6423SLionel Sambuc #if defined(__i386__) 126*433d6423SLionel Sambuc static void root_pci(void) 127*433d6423SLionel Sambuc { 128*433d6423SLionel Sambuc /* Print information about PCI devices present in the system. 129*433d6423SLionel Sambuc */ 130*433d6423SLionel Sambuc u16_t vid, did; 131*433d6423SLionel Sambuc u8_t bcr, scr, pifr; 132*433d6423SLionel Sambuc char *slot_name, *dev_name; 133*433d6423SLionel Sambuc int r, devind; 134*433d6423SLionel Sambuc static int first = TRUE; 135*433d6423SLionel Sambuc 136*433d6423SLionel Sambuc /* This should be taken care of behind the scenes by the PCI lib. */ 137*433d6423SLionel Sambuc if (first) { 138*433d6423SLionel Sambuc pci_init(); 139*433d6423SLionel Sambuc first = FALSE; 140*433d6423SLionel Sambuc } 141*433d6423SLionel Sambuc 142*433d6423SLionel Sambuc /* Iterate over all devices, printing info for each of them. */ 143*433d6423SLionel Sambuc r = pci_first_dev(&devind, &vid, &did); 144*433d6423SLionel Sambuc while (r == 1) { 145*433d6423SLionel Sambuc slot_name = pci_slot_name(devind); 146*433d6423SLionel Sambuc dev_name = pci_dev_name(vid, did); 147*433d6423SLionel Sambuc 148*433d6423SLionel Sambuc bcr = pci_attr_r8(devind, PCI_BCR); 149*433d6423SLionel Sambuc scr = pci_attr_r8(devind, PCI_SCR); 150*433d6423SLionel Sambuc pifr = pci_attr_r8(devind, PCI_PIFR); 151*433d6423SLionel Sambuc 152*433d6423SLionel Sambuc buf_printf("%s %x/%x/%x %04X:%04X %s\n", 153*433d6423SLionel Sambuc slot_name ? slot_name : "-", 154*433d6423SLionel Sambuc bcr, scr, pifr, vid, did, 155*433d6423SLionel Sambuc dev_name ? dev_name : ""); 156*433d6423SLionel Sambuc 157*433d6423SLionel Sambuc r = pci_next_dev(&devind, &vid, &did); 158*433d6423SLionel Sambuc } 159*433d6423SLionel Sambuc } 160*433d6423SLionel Sambuc #endif /* defined(__i386__) */ 161*433d6423SLionel Sambuc 162*433d6423SLionel Sambuc /*===========================================================================* 163*433d6423SLionel Sambuc * root_dmap * 164*433d6423SLionel Sambuc *===========================================================================*/ 165*433d6423SLionel Sambuc static void root_dmap(void) 166*433d6423SLionel Sambuc { 167*433d6423SLionel Sambuc struct dmap dmap[NR_DEVICES]; 168*433d6423SLionel Sambuc int i; 169*433d6423SLionel Sambuc 170*433d6423SLionel Sambuc if (getsysinfo(VFS_PROC_NR, SI_DMAP_TAB, dmap, sizeof(dmap)) != OK) 171*433d6423SLionel Sambuc return; 172*433d6423SLionel Sambuc 173*433d6423SLionel Sambuc for (i = 0; i < NR_DEVICES; i++) { 174*433d6423SLionel Sambuc if (dmap[i].dmap_driver == NONE) 175*433d6423SLionel Sambuc continue; 176*433d6423SLionel Sambuc 177*433d6423SLionel Sambuc buf_printf("%u %s %u\n", i, dmap[i].dmap_label, 178*433d6423SLionel Sambuc dmap[i].dmap_driver); 179*433d6423SLionel Sambuc } 180*433d6423SLionel Sambuc } 181*433d6423SLionel Sambuc 182*433d6423SLionel Sambuc /*===========================================================================* 183*433d6423SLionel Sambuc * root_ipcvecs * 184*433d6423SLionel Sambuc *===========================================================================*/ 185*433d6423SLionel Sambuc static void root_ipcvecs(void) 186*433d6423SLionel Sambuc { 187*433d6423SLionel Sambuc extern struct minix_kerninfo *_minix_kerninfo; 188*433d6423SLionel Sambuc extern struct minix_ipcvecs _minix_ipcvecs; 189*433d6423SLionel Sambuc 190*433d6423SLionel Sambuc /* only print this if the kernel provides the info; otherwise binaries 191*433d6423SLionel Sambuc * will be using their own in-libc vectors that are normal symbols in the 192*433d6423SLionel Sambuc * binary. 193*433d6423SLionel Sambuc */ 194*433d6423SLionel Sambuc if(!_minix_kerninfo || !(_minix_kerninfo->ki_flags & MINIX_KIF_IPCVECS)) 195*433d6423SLionel Sambuc return; 196*433d6423SLionel Sambuc 197*433d6423SLionel Sambuc /* print the vectors with an descriptive name and the additional (k) 198*433d6423SLionel Sambuc * to distinguish them from regular symbols. 199*433d6423SLionel Sambuc */ 200*433d6423SLionel Sambuc #define PRINT_ENTRYPOINT(name) \ 201*433d6423SLionel Sambuc buf_printf("%08lx T %s(k)\n", _minix_ipcvecs.name, #name) 202*433d6423SLionel Sambuc 203*433d6423SLionel Sambuc PRINT_ENTRYPOINT(sendrec); 204*433d6423SLionel Sambuc PRINT_ENTRYPOINT(send); 205*433d6423SLionel Sambuc PRINT_ENTRYPOINT(notify); 206*433d6423SLionel Sambuc PRINT_ENTRYPOINT(senda); 207*433d6423SLionel Sambuc PRINT_ENTRYPOINT(sendnb); 208*433d6423SLionel Sambuc PRINT_ENTRYPOINT(receive); 209*433d6423SLionel Sambuc PRINT_ENTRYPOINT(do_kernel_call); 210*433d6423SLionel Sambuc } 211*433d6423SLionel Sambuc 212*433d6423SLionel Sambuc /*===========================================================================* 213*433d6423SLionel Sambuc * root_mounts * 214*433d6423SLionel Sambuc *===========================================================================*/ 215*433d6423SLionel Sambuc static void 216*433d6423SLionel Sambuc root_mounts(void) 217*433d6423SLionel Sambuc { 218*433d6423SLionel Sambuc struct statvfs buf[NR_MNTS]; 219*433d6423SLionel Sambuc int i, count; 220*433d6423SLionel Sambuc 221*433d6423SLionel Sambuc if ((count = getvfsstat(buf, sizeof(buf), ST_NOWAIT)) < 0) 222*433d6423SLionel Sambuc return; 223*433d6423SLionel Sambuc 224*433d6423SLionel Sambuc for (i = 0; i < count; i++) { 225*433d6423SLionel Sambuc buf_printf("%s on %s type %s (%s)\n", buf[i].f_mntfromname, 226*433d6423SLionel Sambuc buf[i].f_mntonname, buf[i].f_fstypename, 227*433d6423SLionel Sambuc (buf[i].f_flag & ST_RDONLY) ? "ro" : "rw"); 228*433d6423SLionel Sambuc } 229*433d6423SLionel Sambuc } 230