Remove building with NOCRYPTO option
[minix.git] / minix / servers / mib / hw.c
blob63de32c98623c153fd86bffb2e0067492d2588dd
1 /* MIB service - hw.c - implementation of the CTL_HW subtree */
3 #include "mib.h"
5 #if defined(__i386__)
6 static const char mach[] = "i386"; /* machine (cpu) type */
7 static const char arch[] = "i386"; /* architecture */
8 #elif defined(__arm__)
9 static const char mach[] = "evbarm"; /* machine (cpu) type */
10 static const char arch[] = "evbarm"; /* architecture */
11 #else
12 #error "unknown machine architecture"
13 #endif
16 * Implementation of CTL_HW HW_PHYSMEM/HW_PHYSMEM64.
18 static ssize_t
19 mib_hw_physmem(struct mib_call * call __unused, struct mib_node * node,
20 struct mib_oldp * oldp, struct mib_newp * newp __unused)
22 struct vm_stats_info vsi;
23 u_quad_t physmem64;
24 unsigned int physmem;
26 if (vm_info_stats(&vsi) != OK)
27 return EINVAL;
29 physmem64 = (u_quad_t)vsi.vsi_total * vsi.vsi_pagesize;
31 if (node->node_size == sizeof(int)) {
32 if (physmem64 > UINT_MAX)
33 physmem = UINT_MAX;
34 else
35 physmem = (unsigned int)physmem64;
37 return mib_copyout(oldp, 0, &physmem, sizeof(physmem));
38 } else
39 return mib_copyout(oldp, 0, &physmem64, sizeof(physmem64));
43 * Implementation of CTL_HW HW_USERMEM/HW_USERMEM64.
45 static ssize_t
46 mib_hw_usermem(struct mib_call * call __unused, struct mib_node * node,
47 struct mib_oldp * oldp, struct mib_newp * newp __unused)
49 struct vm_stats_info vsi;
50 struct vm_usage_info vui;
51 u_quad_t usermem64;
52 unsigned int usermem;
54 if (vm_info_stats(&vsi) != OK)
55 return EINVAL;
57 usermem64 = (u_quad_t)vsi.vsi_total * vsi.vsi_pagesize;
59 if (vm_info_usage(KERNEL, &vui) != OK)
60 return EINVAL;
62 if (usermem64 >= vui.vui_total)
63 usermem64 -= vui.vui_total;
64 else
65 usermem64 = 0;
67 if (node->node_size == sizeof(int)) {
68 if (usermem64 > UINT_MAX)
69 usermem = UINT_MAX;
70 else
71 usermem = (unsigned int)usermem64;
73 return mib_copyout(oldp, 0, &usermem, sizeof(usermem));
74 } else
75 return mib_copyout(oldp, 0, &usermem64, sizeof(usermem64));
79 * Implementation of CTL_HW HW_NCPUONLINE.
81 static ssize_t
82 mib_hw_ncpuonline(struct mib_call * call __unused,
83 struct mib_node * node __unused, struct mib_oldp * oldp,
84 struct mib_newp * newp __unused)
86 struct machine machine;
87 int ncpuonline;
89 if (sys_getmachine(&machine) != OK)
90 return EINVAL;
92 ncpuonline = machine.processors_count;
94 return mib_copyout(oldp, 0, &ncpuonline, sizeof(ncpuonline));
97 /* The CTL_HW nodes. */
98 static struct mib_node mib_hw_table[] = {
99 /* 1*/ [HW_MACHINE] = MIB_STRING(_P | _RO, mach, "machine",
100 "Machine class"),
101 /* 2*/ /* HW_MODEL: not yet supported */
102 /* 3*/ [HW_NCPU] = MIB_INT(_P | _RO, CONFIG_MAX_CPUS,
103 "ncpu", "Number of CPUs configured"),
104 /* 4*/ [HW_BYTEORDER] = MIB_INT(_P | _RO, BYTE_ORDER, "byteorder",
105 "System byte order"),
106 /* 5*/ [HW_PHYSMEM] = MIB_FUNC(_P | _RO | CTLFLAG_UNSIGNED |
107 CTLTYPE_INT, sizeof(int), mib_hw_physmem,
108 "physmem", "Bytes of physical memory"),
109 /* 6*/ [HW_USERMEM] = MIB_FUNC(_P | _RO | CTLFLAG_UNSIGNED |
110 CTLTYPE_INT, sizeof(int), mib_hw_usermem,
111 "usermem", "Bytes of non-kernel memory"),
112 /* 7*/ [HW_PAGESIZE] = MIB_INT(_P | _RO, PAGE_SIZE, "pagesize",
113 "Software page size"),
114 /* 8*/ /* HW_DISKNAMES: not yet supported */
115 /* 9*/ /* HW_IOSTATS: not yet supported */
116 /*10*/ [HW_MACHINE_ARCH] = MIB_STRING(_P | _RO, arch, "machine_arch",
117 "Machine CPU class"),
118 /*11*/ /* HW_ALIGNBYTES: not yet supported */
119 /*12*/ /* HW_CNMAGIC: not yet supported */
120 /*13*/ [HW_PHYSMEM64] = MIB_FUNC(_P | _RO | CTLTYPE_QUAD,
121 sizeof(u_quad_t), mib_hw_physmem,
122 "physmem64", "Bytes of physical memory"),
123 /*14*/ [HW_USERMEM64] = MIB_FUNC(_P | _RO | CTLTYPE_QUAD,
124 sizeof(u_quad_t), mib_hw_usermem,
125 "usermem64", "Bytes of non-kernel memory"),
126 /*15*/ /* HW_IOSTATNAMES: not yet supported */
127 /*16*/ [HW_NCPUONLINE] = MIB_FUNC(_P | _RO | CTLTYPE_INT, sizeof(int),
128 mib_hw_ncpuonline, "ncpuonline",
129 "Number of CPUs online"),
133 * Initialize the CTL_HW subtree.
135 void
136 mib_hw_init(struct mib_node * node)
139 MIB_INIT_ENODE(node, mib_hw_table);