77 */
78 if (mem_node_physalign) {
79 start &= ~(btop(mem_node_physalign) - 1);
80 end = roundup(end, btop(mem_node_physalign)) - 1;
81 }
82
83 mnode = PFN_2_MEM_NODE(start);
84 ASSERT(mnode < max_mem_nodes);
85
86 if (atomic_cas_32((uint32_t *)&mem_node_config[mnode].exists, 0, 1)) {
87 /*
88 * Add slice to existing node.
89 */
90 if (start < mem_node_config[mnode].physbase)
91 mem_node_config[mnode].physbase = start;
92 if (end > mem_node_config[mnode].physmax)
93 mem_node_config[mnode].physmax = end;
94 } else {
95 mem_node_config[mnode].physbase = start;
96 mem_node_config[mnode].physmax = end;
97 atomic_add_16(&num_memnodes, 1);
98 do {
99 oldmask = memnodes_mask;
100 newmask = memnodes_mask | (1ull << mnode);
101 } while (atomic_cas_64(&memnodes_mask, oldmask, newmask) !=
102 oldmask);
103 }
104 /*
105 * Let the common lgrp framework know about the new memory
106 */
107 lgrp_config(LGRP_CONFIG_MEM_ADD, mnode, MEM_NODE_2_LGRPHAND(mnode));
108 }
109
110 /*
111 * Remove a PFN range from a memnode. On some platforms,
112 * the memnode will be created with physbase at the first
113 * allocatable PFN, but later deleted with the MC slice
114 * base address converted to a PFN, in which case we need
115 * to assume physbase and up.
116 */
117 void
143 ASSERT(end <= mem_node_config[mnode].physmax);
144 if (end == mem_node_config[mnode].physmax)
145 mem_node_config[mnode].physmax = start - 1;
146 } else {
147
148 /*
149 * Let the common lgrp framework know the mnode is
150 * leaving
151 */
152 lgrp_config(LGRP_CONFIG_MEM_DEL, mnode,
153 MEM_NODE_2_LGRPHAND(mnode));
154
155 /*
156 * Delete the whole node.
157 */
158 ASSERT(MNODE_PGCNT(mnode) == 0);
159 do {
160 omask = memnodes_mask;
161 nmask = omask & ~(1ull << mnode);
162 } while (atomic_cas_64(&memnodes_mask, omask, nmask) != omask);
163 atomic_add_16(&num_memnodes, -1);
164 mem_node_config[mnode].exists = 0;
165 }
166 }
167
168 void
169 mem_node_add_range(pfn_t start, pfn_t end)
170 {
171 if (&plat_slice_add != NULL)
172 plat_slice_add(start, end);
173 else
174 mem_node_add_slice(start, end);
175 }
176
177 void
178 mem_node_del_range(pfn_t start, pfn_t end)
179 {
180 if (&plat_slice_del != NULL)
181 plat_slice_del(start, end);
182 else
183 mem_node_del_slice(start, end);
213 int
214 mem_node_alloc()
215 {
216 int mnode;
217 mnodeset_t newmask, oldmask;
218
219 /*
220 * Find an unused memnode. Update it atomically to prevent
221 * a first time memnode creation race.
222 */
223 for (mnode = 0; mnode < max_mem_nodes; mnode++)
224 if (atomic_cas_32((uint32_t *)&mem_node_config[mnode].exists,
225 0, 1) == 0)
226 break;
227
228 if (mnode >= max_mem_nodes)
229 panic("Out of free memnodes\n");
230
231 mem_node_config[mnode].physbase = (uint64_t)-1;
232 mem_node_config[mnode].physmax = 0;
233 atomic_add_16(&num_memnodes, 1);
234 do {
235 oldmask = memnodes_mask;
236 newmask = memnodes_mask | (1ull << mnode);
237 } while (atomic_cas_64(&memnodes_mask, oldmask, newmask) != oldmask);
238
239 return (mnode);
240 }
241
242 /*
243 * Find the intersection between a memnode and a memlist
244 * and returns the number of pages that overlap.
245 *
246 * Grab the memlist lock to protect the list from DR operations.
247 */
248 pgcnt_t
249 mem_node_memlist_pages(int mnode, struct memlist *mlist)
250 {
251 pfn_t base, end;
252 pfn_t cur_base, cur_end;
253 pgcnt_t npgs = 0;
|
77 */
78 if (mem_node_physalign) {
79 start &= ~(btop(mem_node_physalign) - 1);
80 end = roundup(end, btop(mem_node_physalign)) - 1;
81 }
82
83 mnode = PFN_2_MEM_NODE(start);
84 ASSERT(mnode < max_mem_nodes);
85
86 if (atomic_cas_32((uint32_t *)&mem_node_config[mnode].exists, 0, 1)) {
87 /*
88 * Add slice to existing node.
89 */
90 if (start < mem_node_config[mnode].physbase)
91 mem_node_config[mnode].physbase = start;
92 if (end > mem_node_config[mnode].physmax)
93 mem_node_config[mnode].physmax = end;
94 } else {
95 mem_node_config[mnode].physbase = start;
96 mem_node_config[mnode].physmax = end;
97 atomic_inc_16(&num_memnodes);
98 do {
99 oldmask = memnodes_mask;
100 newmask = memnodes_mask | (1ull << mnode);
101 } while (atomic_cas_64(&memnodes_mask, oldmask, newmask) !=
102 oldmask);
103 }
104 /*
105 * Let the common lgrp framework know about the new memory
106 */
107 lgrp_config(LGRP_CONFIG_MEM_ADD, mnode, MEM_NODE_2_LGRPHAND(mnode));
108 }
109
110 /*
111 * Remove a PFN range from a memnode. On some platforms,
112 * the memnode will be created with physbase at the first
113 * allocatable PFN, but later deleted with the MC slice
114 * base address converted to a PFN, in which case we need
115 * to assume physbase and up.
116 */
117 void
143 ASSERT(end <= mem_node_config[mnode].physmax);
144 if (end == mem_node_config[mnode].physmax)
145 mem_node_config[mnode].physmax = start - 1;
146 } else {
147
148 /*
149 * Let the common lgrp framework know the mnode is
150 * leaving
151 */
152 lgrp_config(LGRP_CONFIG_MEM_DEL, mnode,
153 MEM_NODE_2_LGRPHAND(mnode));
154
155 /*
156 * Delete the whole node.
157 */
158 ASSERT(MNODE_PGCNT(mnode) == 0);
159 do {
160 omask = memnodes_mask;
161 nmask = omask & ~(1ull << mnode);
162 } while (atomic_cas_64(&memnodes_mask, omask, nmask) != omask);
163 atomic_dec_16(&num_memnodes);
164 mem_node_config[mnode].exists = 0;
165 }
166 }
167
168 void
169 mem_node_add_range(pfn_t start, pfn_t end)
170 {
171 if (&plat_slice_add != NULL)
172 plat_slice_add(start, end);
173 else
174 mem_node_add_slice(start, end);
175 }
176
177 void
178 mem_node_del_range(pfn_t start, pfn_t end)
179 {
180 if (&plat_slice_del != NULL)
181 plat_slice_del(start, end);
182 else
183 mem_node_del_slice(start, end);
213 int
214 mem_node_alloc()
215 {
216 int mnode;
217 mnodeset_t newmask, oldmask;
218
219 /*
220 * Find an unused memnode. Update it atomically to prevent
221 * a first time memnode creation race.
222 */
223 for (mnode = 0; mnode < max_mem_nodes; mnode++)
224 if (atomic_cas_32((uint32_t *)&mem_node_config[mnode].exists,
225 0, 1) == 0)
226 break;
227
228 if (mnode >= max_mem_nodes)
229 panic("Out of free memnodes\n");
230
231 mem_node_config[mnode].physbase = (uint64_t)-1;
232 mem_node_config[mnode].physmax = 0;
233 atomic_inc_16(&num_memnodes);
234 do {
235 oldmask = memnodes_mask;
236 newmask = memnodes_mask | (1ull << mnode);
237 } while (atomic_cas_64(&memnodes_mask, oldmask, newmask) != oldmask);
238
239 return (mnode);
240 }
241
242 /*
243 * Find the intersection between a memnode and a memlist
244 * and returns the number of pages that overlap.
245 *
246 * Grab the memlist lock to protect the list from DR operations.
247 */
248 pgcnt_t
249 mem_node_memlist_pages(int mnode, struct memlist *mlist)
250 {
251 pfn_t base, end;
252 pfn_t cur_base, cur_end;
253 pgcnt_t npgs = 0;
|