]>
Commit | Line | Data |
---|---|---|
b6a0aa05 | 1 | #include "qemu/osdep.h" |
3ef77aca IM |
2 | #include "hw/acpi/memory_hotplug.h" |
3 | #include "hw/acpi/pc-hotplug.h" | |
4 | #include "hw/mem/pc-dimm.h" | |
5 | #include "hw/boards.h" | |
c06b2ffb | 6 | #include "hw/qdev-core.h" |
dfe292ff | 7 | #include "trace.h" |
5f41fbba | 8 | #include "qapi-event.h" |
3ef77aca | 9 | |
c9c08545 IM |
10 | #define MEMORY_SLOTS_NUMBER "MDNR" |
11 | #define MEMORY_HOTPLUG_IO_REGION "HPMR" | |
12 | #define MEMORY_SLOT_ADDR_LOW "MRBL" | |
13 | #define MEMORY_SLOT_ADDR_HIGH "MRBH" | |
14 | #define MEMORY_SLOT_SIZE_LOW "MRLL" | |
15 | #define MEMORY_SLOT_SIZE_HIGH "MRLH" | |
16 | #define MEMORY_SLOT_PROXIMITY "MPX" | |
17 | #define MEMORY_SLOT_ENABLED "MES" | |
18 | #define MEMORY_SLOT_INSERT_EVENT "MINS" | |
19 | #define MEMORY_SLOT_REMOVE_EVENT "MRMV" | |
20 | #define MEMORY_SLOT_EJECT "MEJ" | |
21 | #define MEMORY_SLOT_SLECTOR "MSEL" | |
22 | #define MEMORY_SLOT_OST_EVENT "MOEV" | |
23 | #define MEMORY_SLOT_OST_STATUS "MOSC" | |
24 | #define MEMORY_SLOT_LOCK "MLCK" | |
25 | #define MEMORY_SLOT_STATUS_METHOD "MRST" | |
26 | #define MEMORY_SLOT_CRS_METHOD "MCRS" | |
27 | #define MEMORY_SLOT_OST_METHOD "MOST" | |
28 | #define MEMORY_SLOT_PROXIMITY_METHOD "MPXM" | |
29 | #define MEMORY_SLOT_EJECT_METHOD "MEJ0" | |
30 | #define MEMORY_SLOT_NOTIFY_METHOD "MTFY" | |
31 | #define MEMORY_SLOT_SCAN_METHOD "MSCN" | |
32 | #define MEMORY_HOTPLUG_DEVICE "MHPD" | |
33 | ||
43f50410 IM |
34 | static ACPIOSTInfo *acpi_memory_device_status(int slot, MemStatus *mdev) |
35 | { | |
36 | ACPIOSTInfo *info = g_new0(ACPIOSTInfo, 1); | |
37 | ||
38 | info->slot_type = ACPI_SLOT_TYPE_DIMM; | |
39 | info->slot = g_strdup_printf("%d", slot); | |
40 | info->source = mdev->ost_event; | |
41 | info->status = mdev->ost_status; | |
42 | if (mdev->dimm) { | |
43 | DeviceState *dev = DEVICE(mdev->dimm); | |
44 | if (dev->id) { | |
45 | info->device = g_strdup(dev->id); | |
46 | info->has_device = true; | |
47 | } | |
48 | } | |
49 | return info; | |
50 | } | |
51 | ||
52 | void acpi_memory_ospm_status(MemHotplugState *mem_st, ACPIOSTInfoList ***list) | |
53 | { | |
54 | int i; | |
55 | ||
56 | for (i = 0; i < mem_st->dev_count; i++) { | |
57 | ACPIOSTInfoList *elem = g_new0(ACPIOSTInfoList, 1); | |
58 | elem->value = acpi_memory_device_status(i, &mem_st->devs[i]); | |
59 | elem->next = NULL; | |
60 | **list = elem; | |
61 | *list = &elem->next; | |
62 | } | |
63 | } | |
64 | ||
3ef77aca IM |
65 | static uint64_t acpi_memory_hotplug_read(void *opaque, hwaddr addr, |
66 | unsigned int size) | |
67 | { | |
68 | uint32_t val = 0; | |
69 | MemHotplugState *mem_st = opaque; | |
70 | MemStatus *mdev; | |
71 | Object *o; | |
72 | ||
73 | if (mem_st->selector >= mem_st->dev_count) { | |
dfe292ff | 74 | trace_mhp_acpi_invalid_slot_selected(mem_st->selector); |
3ef77aca IM |
75 | return 0; |
76 | } | |
77 | ||
78 | mdev = &mem_st->devs[mem_st->selector]; | |
79 | o = OBJECT(mdev->dimm); | |
80 | switch (addr) { | |
81 | case 0x0: /* Lo part of phys address where DIMM is mapped */ | |
82 | val = o ? object_property_get_int(o, PC_DIMM_ADDR_PROP, NULL) : 0; | |
dfe292ff | 83 | trace_mhp_acpi_read_addr_lo(mem_st->selector, val); |
3ef77aca IM |
84 | break; |
85 | case 0x4: /* Hi part of phys address where DIMM is mapped */ | |
86 | val = o ? object_property_get_int(o, PC_DIMM_ADDR_PROP, NULL) >> 32 : 0; | |
dfe292ff | 87 | trace_mhp_acpi_read_addr_hi(mem_st->selector, val); |
3ef77aca IM |
88 | break; |
89 | case 0x8: /* Lo part of DIMM size */ | |
90 | val = o ? object_property_get_int(o, PC_DIMM_SIZE_PROP, NULL) : 0; | |
dfe292ff | 91 | trace_mhp_acpi_read_size_lo(mem_st->selector, val); |
3ef77aca IM |
92 | break; |
93 | case 0xc: /* Hi part of DIMM size */ | |
94 | val = o ? object_property_get_int(o, PC_DIMM_SIZE_PROP, NULL) >> 32 : 0; | |
dfe292ff | 95 | trace_mhp_acpi_read_size_hi(mem_st->selector, val); |
3ef77aca IM |
96 | break; |
97 | case 0x10: /* node proximity for _PXM method */ | |
98 | val = o ? object_property_get_int(o, PC_DIMM_NODE_PROP, NULL) : 0; | |
dfe292ff | 99 | trace_mhp_acpi_read_pxm(mem_st->selector, val); |
3ef77aca IM |
100 | break; |
101 | case 0x14: /* pack and return is_* fields */ | |
102 | val |= mdev->is_enabled ? 1 : 0; | |
103 | val |= mdev->is_inserting ? 2 : 0; | |
64fec58e | 104 | val |= mdev->is_removing ? 4 : 0; |
dfe292ff | 105 | trace_mhp_acpi_read_flags(mem_st->selector, val); |
3ef77aca IM |
106 | break; |
107 | default: | |
108 | val = ~0; | |
109 | break; | |
110 | } | |
111 | return val; | |
112 | } | |
113 | ||
114 | static void acpi_memory_hotplug_write(void *opaque, hwaddr addr, uint64_t data, | |
115 | unsigned int size) | |
116 | { | |
117 | MemHotplugState *mem_st = opaque; | |
118 | MemStatus *mdev; | |
5f41fbba | 119 | ACPIOSTInfo *info; |
c06b2ffb ZG |
120 | DeviceState *dev = NULL; |
121 | HotplugHandler *hotplug_ctrl = NULL; | |
bc09e061 | 122 | Error *local_err = NULL; |
3ef77aca IM |
123 | |
124 | if (!mem_st->dev_count) { | |
125 | return; | |
126 | } | |
127 | ||
128 | if (addr) { | |
129 | if (mem_st->selector >= mem_st->dev_count) { | |
dfe292ff | 130 | trace_mhp_acpi_invalid_slot_selected(mem_st->selector); |
3ef77aca IM |
131 | return; |
132 | } | |
133 | } | |
134 | ||
135 | switch (addr) { | |
136 | case 0x0: /* DIMM slot selector */ | |
137 | mem_st->selector = data; | |
dfe292ff | 138 | trace_mhp_acpi_write_slot(mem_st->selector); |
3ef77aca IM |
139 | break; |
140 | case 0x4: /* _OST event */ | |
141 | mdev = &mem_st->devs[mem_st->selector]; | |
142 | if (data == 1) { | |
143 | /* TODO: handle device insert OST event */ | |
144 | } else if (data == 3) { | |
145 | /* TODO: handle device remove OST event */ | |
146 | } | |
147 | mdev->ost_event = data; | |
dfe292ff | 148 | trace_mhp_acpi_write_ost_ev(mem_st->selector, mdev->ost_event); |
3ef77aca IM |
149 | break; |
150 | case 0x8: /* _OST status */ | |
151 | mdev = &mem_st->devs[mem_st->selector]; | |
152 | mdev->ost_status = data; | |
dfe292ff | 153 | trace_mhp_acpi_write_ost_status(mem_st->selector, mdev->ost_status); |
3ef77aca | 154 | /* TODO: implement memory removal on guest signal */ |
5f41fbba IM |
155 | |
156 | info = acpi_memory_device_status(mem_st->selector, mdev); | |
157 | qapi_event_send_acpi_device_ost(info, &error_abort); | |
158 | qapi_free_ACPIOSTInfo(info); | |
3ef77aca | 159 | break; |
c06b2ffb | 160 | case 0x14: /* set is_* fields */ |
3ef77aca IM |
161 | mdev = &mem_st->devs[mem_st->selector]; |
162 | if (data & 2) { /* clear insert event */ | |
163 | mdev->is_inserting = false; | |
dfe292ff | 164 | trace_mhp_acpi_clear_insert_evt(mem_st->selector); |
c06b2ffb ZG |
165 | } else if (data & 4) { |
166 | mdev->is_removing = false; | |
167 | trace_mhp_acpi_clear_remove_evt(mem_st->selector); | |
168 | } else if (data & 8) { | |
169 | if (!mdev->is_enabled) { | |
170 | trace_mhp_acpi_ejecting_invalid_slot(mem_st->selector); | |
171 | break; | |
172 | } | |
173 | ||
174 | dev = DEVICE(mdev->dimm); | |
175 | hotplug_ctrl = qdev_get_hotplug_handler(dev); | |
176 | /* call pc-dimm unplug cb */ | |
bc09e061 ZG |
177 | hotplug_handler_unplug(hotplug_ctrl, dev, &local_err); |
178 | if (local_err) { | |
179 | trace_mhp_acpi_pc_dimm_delete_failed(mem_st->selector); | |
180 | qapi_event_send_mem_unplug_error(dev->id, | |
181 | error_get_pretty(local_err), | |
182 | &error_abort); | |
903a41d3 | 183 | error_free(local_err); |
bc09e061 ZG |
184 | break; |
185 | } | |
c06b2ffb | 186 | trace_mhp_acpi_pc_dimm_deleted(mem_st->selector); |
3ef77aca IM |
187 | } |
188 | break; | |
c06b2ffb ZG |
189 | default: |
190 | break; | |
3ef77aca IM |
191 | } |
192 | ||
193 | } | |
194 | static const MemoryRegionOps acpi_memory_hotplug_ops = { | |
195 | .read = acpi_memory_hotplug_read, | |
196 | .write = acpi_memory_hotplug_write, | |
197 | .endianness = DEVICE_LITTLE_ENDIAN, | |
198 | .valid = { | |
199 | .min_access_size = 1, | |
200 | .max_access_size = 4, | |
201 | }, | |
202 | }; | |
203 | ||
204 | void acpi_memory_hotplug_init(MemoryRegion *as, Object *owner, | |
205 | MemHotplugState *state) | |
206 | { | |
207 | MachineState *machine = MACHINE(qdev_get_machine()); | |
208 | ||
209 | state->dev_count = machine->ram_slots; | |
210 | if (!state->dev_count) { | |
211 | return; | |
212 | } | |
213 | ||
214 | state->devs = g_malloc0(sizeof(*state->devs) * state->dev_count); | |
215 | memory_region_init_io(&state->io, owner, &acpi_memory_hotplug_ops, state, | |
22dc50d7 | 216 | "acpi-mem-hotplug", ACPI_MEMORY_HOTPLUG_IO_LEN); |
3ef77aca IM |
217 | memory_region_add_subregion(as, ACPI_MEMORY_HOTPLUG_BASE, &state->io); |
218 | } | |
219 | ||
4aae99b6 TC |
220 | /** |
221 | * acpi_memory_slot_status: | |
222 | * @mem_st: memory hotplug state | |
223 | * @dev: device | |
224 | * @errp: set in case of an error | |
225 | * | |
226 | * Obtain a single memory slot status. | |
227 | * | |
228 | * This function will be called by memory unplug request cb and unplug cb. | |
229 | */ | |
230 | static MemStatus * | |
231 | acpi_memory_slot_status(MemHotplugState *mem_st, | |
232 | DeviceState *dev, Error **errp) | |
3ef77aca | 233 | { |
3ef77aca | 234 | Error *local_err = NULL; |
1d515701 TC |
235 | int slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, |
236 | &local_err); | |
3ef77aca IM |
237 | |
238 | if (local_err) { | |
239 | error_propagate(errp, local_err); | |
4aae99b6 | 240 | return NULL; |
3ef77aca IM |
241 | } |
242 | ||
243 | if (slot >= mem_st->dev_count) { | |
244 | char *dev_path = object_get_canonical_path(OBJECT(dev)); | |
4aae99b6 | 245 | error_setg(errp, "acpi_memory_slot_status: " |
3ef77aca IM |
246 | "device [%s] returned invalid memory slot[%d]", |
247 | dev_path, slot); | |
248 | g_free(dev_path); | |
4aae99b6 TC |
249 | return NULL; |
250 | } | |
251 | ||
252 | return &mem_st->devs[slot]; | |
253 | } | |
254 | ||
0058c082 | 255 | void acpi_memory_plug_cb(HotplugHandler *hotplug_dev, MemHotplugState *mem_st, |
4aae99b6 TC |
256 | DeviceState *dev, Error **errp) |
257 | { | |
258 | MemStatus *mdev; | |
75f27498 XG |
259 | DeviceClass *dc = DEVICE_GET_CLASS(dev); |
260 | ||
261 | if (!dc->hotpluggable) { | |
262 | return; | |
263 | } | |
4aae99b6 TC |
264 | |
265 | mdev = acpi_memory_slot_status(mem_st, dev, errp); | |
266 | if (!mdev) { | |
3ef77aca IM |
267 | return; |
268 | } | |
269 | ||
3ef77aca | 270 | mdev->dimm = dev; |
75f27498 | 271 | mdev->is_enabled = true; |
4828b10b | 272 | if (dev->hotplugged) { |
75f27498 XG |
273 | mdev->is_inserting = true; |
274 | acpi_send_event(DEVICE(hotplug_dev), ACPI_MEMORY_HOTPLUG_STATUS); | |
4828b10b | 275 | } |
3ef77aca | 276 | } |
f816a62d | 277 | |
0058c082 | 278 | void acpi_memory_unplug_request_cb(HotplugHandler *hotplug_dev, |
64fec58e TC |
279 | MemHotplugState *mem_st, |
280 | DeviceState *dev, Error **errp) | |
281 | { | |
282 | MemStatus *mdev; | |
283 | ||
284 | mdev = acpi_memory_slot_status(mem_st, dev, errp); | |
285 | if (!mdev) { | |
286 | return; | |
287 | } | |
288 | ||
289 | mdev->is_removing = true; | |
0058c082 | 290 | acpi_send_event(DEVICE(hotplug_dev), ACPI_MEMORY_HOTPLUG_STATUS); |
64fec58e TC |
291 | } |
292 | ||
f7d3e29d TC |
293 | void acpi_memory_unplug_cb(MemHotplugState *mem_st, |
294 | DeviceState *dev, Error **errp) | |
295 | { | |
296 | MemStatus *mdev; | |
297 | ||
298 | mdev = acpi_memory_slot_status(mem_st, dev, errp); | |
299 | if (!mdev) { | |
300 | return; | |
301 | } | |
302 | ||
303 | mdev->is_enabled = false; | |
304 | mdev->dimm = NULL; | |
305 | } | |
306 | ||
f816a62d IM |
307 | static const VMStateDescription vmstate_memhp_sts = { |
308 | .name = "memory hotplug device state", | |
309 | .version_id = 1, | |
310 | .minimum_version_id = 1, | |
311 | .minimum_version_id_old = 1, | |
312 | .fields = (VMStateField[]) { | |
313 | VMSTATE_BOOL(is_enabled, MemStatus), | |
314 | VMSTATE_BOOL(is_inserting, MemStatus), | |
315 | VMSTATE_UINT32(ost_event, MemStatus), | |
316 | VMSTATE_UINT32(ost_status, MemStatus), | |
317 | VMSTATE_END_OF_LIST() | |
318 | } | |
319 | }; | |
320 | ||
321 | const VMStateDescription vmstate_memory_hotplug = { | |
322 | .name = "memory hotplug state", | |
323 | .version_id = 1, | |
324 | .minimum_version_id = 1, | |
325 | .minimum_version_id_old = 1, | |
326 | .fields = (VMStateField[]) { | |
327 | VMSTATE_UINT32(selector, MemHotplugState), | |
328 | VMSTATE_STRUCT_VARRAY_POINTER_UINT32(devs, MemHotplugState, dev_count, | |
329 | vmstate_memhp_sts, MemStatus), | |
330 | VMSTATE_END_OF_LIST() | |
331 | } | |
332 | }; | |
a2088da3 | 333 | |
8dfba500 | 334 | void build_memory_hotplug_aml(Aml *table, uint32_t nr_mem, |
d1957dac IM |
335 | uint16_t io_base, uint16_t io_len, |
336 | const char *res_root, | |
337 | const char *event_handler_method) | |
a2088da3 | 338 | { |
8b35ab27 | 339 | int i; |
a2088da3 IM |
340 | Aml *ifctx; |
341 | Aml *method; | |
8b35ab27 | 342 | Aml *sb_scope; |
a2088da3 | 343 | Aml *mem_ctrl_dev; |
d1957dac IM |
344 | char *scan_path; |
345 | char *mhp_res_path = g_strdup_printf("%s." MEMORY_HOTPLUG_DEVICE, res_root); | |
a2088da3 | 346 | |
d1957dac | 347 | mem_ctrl_dev = aml_device("%s", mhp_res_path); |
a2088da3 | 348 | { |
8dfba500 IM |
349 | Aml *crs; |
350 | Aml *field; | |
a2088da3 IM |
351 | Aml *one = aml_int(1); |
352 | Aml *zero = aml_int(0); | |
353 | Aml *ret_val = aml_local(0); | |
354 | Aml *slot_arg0 = aml_arg(0); | |
355 | Aml *slots_nr = aml_name(MEMORY_SLOTS_NUMBER); | |
356 | Aml *ctrl_lock = aml_name(MEMORY_SLOT_LOCK); | |
357 | Aml *slot_selector = aml_name(MEMORY_SLOT_SLECTOR); | |
358 | ||
359 | aml_append(mem_ctrl_dev, aml_name_decl("_HID", aml_string("PNP0A06"))); | |
360 | aml_append(mem_ctrl_dev, | |
361 | aml_name_decl("_UID", aml_string("Memory hotplug resources"))); | |
362 | ||
8dfba500 IM |
363 | assert(nr_mem <= ACPI_MAX_RAM_SLOTS); |
364 | aml_append(mem_ctrl_dev, | |
365 | aml_name_decl(MEMORY_SLOTS_NUMBER, aml_int(nr_mem)) | |
366 | ); | |
367 | ||
368 | crs = aml_resource_template(); | |
369 | aml_append(crs, | |
370 | aml_io(AML_DECODE16, io_base, io_base, 0, io_len) | |
371 | ); | |
372 | aml_append(mem_ctrl_dev, aml_name_decl("_CRS", crs)); | |
373 | ||
374 | aml_append(mem_ctrl_dev, aml_operation_region( | |
375 | MEMORY_HOTPLUG_IO_REGION, AML_SYSTEM_IO, | |
376 | aml_int(io_base), io_len) | |
377 | ); | |
378 | ||
379 | field = aml_field(MEMORY_HOTPLUG_IO_REGION, AML_DWORD_ACC, | |
380 | AML_NOLOCK, AML_PRESERVE); | |
381 | aml_append(field, /* read only */ | |
382 | aml_named_field(MEMORY_SLOT_ADDR_LOW, 32)); | |
383 | aml_append(field, /* read only */ | |
384 | aml_named_field(MEMORY_SLOT_ADDR_HIGH, 32)); | |
385 | aml_append(field, /* read only */ | |
386 | aml_named_field(MEMORY_SLOT_SIZE_LOW, 32)); | |
387 | aml_append(field, /* read only */ | |
388 | aml_named_field(MEMORY_SLOT_SIZE_HIGH, 32)); | |
389 | aml_append(field, /* read only */ | |
390 | aml_named_field(MEMORY_SLOT_PROXIMITY, 32)); | |
391 | aml_append(mem_ctrl_dev, field); | |
392 | ||
393 | field = aml_field(MEMORY_HOTPLUG_IO_REGION, AML_BYTE_ACC, | |
394 | AML_NOLOCK, AML_WRITE_AS_ZEROS); | |
395 | aml_append(field, aml_reserved_field(160 /* bits, Offset(20) */)); | |
396 | aml_append(field, /* 1 if enabled, read only */ | |
397 | aml_named_field(MEMORY_SLOT_ENABLED, 1)); | |
398 | aml_append(field, | |
399 | /*(read) 1 if has a insert event. (write) 1 to clear event */ | |
400 | aml_named_field(MEMORY_SLOT_INSERT_EVENT, 1)); | |
401 | aml_append(field, | |
402 | /* (read) 1 if has a remove event. (write) 1 to clear event */ | |
403 | aml_named_field(MEMORY_SLOT_REMOVE_EVENT, 1)); | |
404 | aml_append(field, | |
405 | /* initiates device eject, write only */ | |
406 | aml_named_field(MEMORY_SLOT_EJECT, 1)); | |
407 | aml_append(mem_ctrl_dev, field); | |
408 | ||
409 | field = aml_field(MEMORY_HOTPLUG_IO_REGION, AML_DWORD_ACC, | |
410 | AML_NOLOCK, AML_PRESERVE); | |
411 | aml_append(field, /* DIMM selector, write only */ | |
412 | aml_named_field(MEMORY_SLOT_SLECTOR, 32)); | |
413 | aml_append(field, /* _OST event code, write only */ | |
414 | aml_named_field(MEMORY_SLOT_OST_EVENT, 32)); | |
415 | aml_append(field, /* _OST status code, write only */ | |
416 | aml_named_field(MEMORY_SLOT_OST_STATUS, 32)); | |
417 | aml_append(mem_ctrl_dev, field); | |
418 | ||
a2088da3 IM |
419 | method = aml_method("_STA", 0, AML_NOTSERIALIZED); |
420 | ifctx = aml_if(aml_equal(slots_nr, zero)); | |
421 | { | |
422 | aml_append(ifctx, aml_return(zero)); | |
423 | } | |
424 | aml_append(method, ifctx); | |
425 | /* present, functioning, decoding, not shown in UI */ | |
426 | aml_append(method, aml_return(aml_int(0xB))); | |
427 | aml_append(mem_ctrl_dev, method); | |
428 | ||
429 | aml_append(mem_ctrl_dev, aml_mutex(MEMORY_SLOT_LOCK, 0)); | |
430 | ||
431 | method = aml_method(MEMORY_SLOT_SCAN_METHOD, 0, AML_NOTSERIALIZED); | |
432 | { | |
433 | Aml *else_ctx; | |
434 | Aml *while_ctx; | |
435 | Aml *idx = aml_local(0); | |
436 | Aml *eject_req = aml_int(3); | |
437 | Aml *dev_chk = aml_int(1); | |
438 | ||
439 | ifctx = aml_if(aml_equal(slots_nr, zero)); | |
440 | { | |
441 | aml_append(ifctx, aml_return(zero)); | |
442 | } | |
443 | aml_append(method, ifctx); | |
444 | ||
445 | aml_append(method, aml_store(zero, idx)); | |
446 | aml_append(method, aml_acquire(ctrl_lock, 0xFFFF)); | |
447 | /* build AML that: | |
448 | * loops over all slots and Notifies DIMMs with | |
449 | * Device Check or Eject Request notifications if | |
450 | * slot has corresponding status bit set and clears | |
451 | * slot status. | |
452 | */ | |
453 | while_ctx = aml_while(aml_lless(idx, slots_nr)); | |
454 | { | |
455 | Aml *ins_evt = aml_name(MEMORY_SLOT_INSERT_EVENT); | |
456 | Aml *rm_evt = aml_name(MEMORY_SLOT_REMOVE_EVENT); | |
457 | ||
458 | aml_append(while_ctx, aml_store(idx, slot_selector)); | |
459 | ifctx = aml_if(aml_equal(ins_evt, one)); | |
460 | { | |
461 | aml_append(ifctx, | |
462 | aml_call2(MEMORY_SLOT_NOTIFY_METHOD, | |
463 | idx, dev_chk)); | |
464 | aml_append(ifctx, aml_store(one, ins_evt)); | |
465 | } | |
466 | aml_append(while_ctx, ifctx); | |
467 | ||
468 | else_ctx = aml_else(); | |
469 | ifctx = aml_if(aml_equal(rm_evt, one)); | |
470 | { | |
471 | aml_append(ifctx, | |
472 | aml_call2(MEMORY_SLOT_NOTIFY_METHOD, | |
473 | idx, eject_req)); | |
474 | aml_append(ifctx, aml_store(one, rm_evt)); | |
475 | } | |
476 | aml_append(else_ctx, ifctx); | |
477 | aml_append(while_ctx, else_ctx); | |
478 | ||
479 | aml_append(while_ctx, aml_add(idx, one, idx)); | |
480 | } | |
481 | aml_append(method, while_ctx); | |
482 | aml_append(method, aml_release(ctrl_lock)); | |
483 | aml_append(method, aml_return(one)); | |
484 | } | |
485 | aml_append(mem_ctrl_dev, method); | |
486 | ||
487 | method = aml_method(MEMORY_SLOT_STATUS_METHOD, 1, AML_NOTSERIALIZED); | |
488 | { | |
489 | Aml *slot_enabled = aml_name(MEMORY_SLOT_ENABLED); | |
490 | ||
491 | aml_append(method, aml_store(zero, ret_val)); | |
492 | aml_append(method, aml_acquire(ctrl_lock, 0xFFFF)); | |
493 | aml_append(method, | |
494 | aml_store(aml_to_integer(slot_arg0), slot_selector)); | |
495 | ||
496 | ifctx = aml_if(aml_equal(slot_enabled, one)); | |
497 | { | |
498 | aml_append(ifctx, aml_store(aml_int(0xF), ret_val)); | |
499 | } | |
500 | aml_append(method, ifctx); | |
501 | ||
502 | aml_append(method, aml_release(ctrl_lock)); | |
503 | aml_append(method, aml_return(ret_val)); | |
504 | } | |
505 | aml_append(mem_ctrl_dev, method); | |
506 | ||
507 | method = aml_method(MEMORY_SLOT_CRS_METHOD, 1, AML_SERIALIZED); | |
508 | { | |
509 | Aml *mr64 = aml_name("MR64"); | |
510 | Aml *mr32 = aml_name("MR32"); | |
511 | Aml *crs_tmpl = aml_resource_template(); | |
512 | Aml *minl = aml_name("MINL"); | |
513 | Aml *minh = aml_name("MINH"); | |
514 | Aml *maxl = aml_name("MAXL"); | |
515 | Aml *maxh = aml_name("MAXH"); | |
516 | Aml *lenl = aml_name("LENL"); | |
517 | Aml *lenh = aml_name("LENH"); | |
518 | ||
519 | aml_append(method, aml_acquire(ctrl_lock, 0xFFFF)); | |
520 | aml_append(method, aml_store(aml_to_integer(slot_arg0), | |
521 | slot_selector)); | |
522 | ||
523 | aml_append(crs_tmpl, | |
524 | aml_qword_memory(AML_POS_DECODE, AML_MIN_FIXED, AML_MAX_FIXED, | |
525 | AML_CACHEABLE, AML_READ_WRITE, | |
526 | 0, 0x0, 0xFFFFFFFFFFFFFFFEULL, 0, | |
527 | 0xFFFFFFFFFFFFFFFFULL)); | |
528 | aml_append(method, aml_name_decl("MR64", crs_tmpl)); | |
529 | aml_append(method, | |
530 | aml_create_dword_field(mr64, aml_int(14), "MINL")); | |
531 | aml_append(method, | |
532 | aml_create_dword_field(mr64, aml_int(18), "MINH")); | |
533 | aml_append(method, | |
534 | aml_create_dword_field(mr64, aml_int(38), "LENL")); | |
535 | aml_append(method, | |
536 | aml_create_dword_field(mr64, aml_int(42), "LENH")); | |
537 | aml_append(method, | |
538 | aml_create_dword_field(mr64, aml_int(22), "MAXL")); | |
539 | aml_append(method, | |
540 | aml_create_dword_field(mr64, aml_int(26), "MAXH")); | |
541 | ||
542 | aml_append(method, | |
543 | aml_store(aml_name(MEMORY_SLOT_ADDR_HIGH), minh)); | |
544 | aml_append(method, | |
545 | aml_store(aml_name(MEMORY_SLOT_ADDR_LOW), minl)); | |
546 | aml_append(method, | |
547 | aml_store(aml_name(MEMORY_SLOT_SIZE_HIGH), lenh)); | |
548 | aml_append(method, | |
549 | aml_store(aml_name(MEMORY_SLOT_SIZE_LOW), lenl)); | |
550 | ||
551 | /* 64-bit math: MAX = MIN + LEN - 1 */ | |
552 | aml_append(method, aml_add(minl, lenl, maxl)); | |
553 | aml_append(method, aml_add(minh, lenh, maxh)); | |
554 | ifctx = aml_if(aml_lless(maxl, minl)); | |
555 | { | |
556 | aml_append(ifctx, aml_add(maxh, one, maxh)); | |
557 | } | |
558 | aml_append(method, ifctx); | |
559 | ifctx = aml_if(aml_lless(maxl, one)); | |
560 | { | |
561 | aml_append(ifctx, aml_subtract(maxh, one, maxh)); | |
562 | } | |
563 | aml_append(method, ifctx); | |
564 | aml_append(method, aml_subtract(maxl, one, maxl)); | |
565 | ||
566 | /* return 32-bit _CRS if addr/size is in low mem */ | |
567 | /* TODO: remove it since all hotplugged DIMMs are in high mem */ | |
568 | ifctx = aml_if(aml_equal(maxh, zero)); | |
569 | { | |
570 | crs_tmpl = aml_resource_template(); | |
571 | aml_append(crs_tmpl, | |
572 | aml_dword_memory(AML_POS_DECODE, AML_MIN_FIXED, | |
573 | AML_MAX_FIXED, AML_CACHEABLE, | |
574 | AML_READ_WRITE, | |
575 | 0, 0x0, 0xFFFFFFFE, 0, | |
576 | 0xFFFFFFFF)); | |
577 | aml_append(ifctx, aml_name_decl("MR32", crs_tmpl)); | |
578 | aml_append(ifctx, | |
579 | aml_create_dword_field(mr32, aml_int(10), "MIN")); | |
580 | aml_append(ifctx, | |
581 | aml_create_dword_field(mr32, aml_int(14), "MAX")); | |
582 | aml_append(ifctx, | |
583 | aml_create_dword_field(mr32, aml_int(22), "LEN")); | |
584 | aml_append(ifctx, aml_store(minl, aml_name("MIN"))); | |
585 | aml_append(ifctx, aml_store(maxl, aml_name("MAX"))); | |
586 | aml_append(ifctx, aml_store(lenl, aml_name("LEN"))); | |
587 | ||
588 | aml_append(ifctx, aml_release(ctrl_lock)); | |
589 | aml_append(ifctx, aml_return(mr32)); | |
590 | } | |
591 | aml_append(method, ifctx); | |
592 | ||
593 | aml_append(method, aml_release(ctrl_lock)); | |
594 | aml_append(method, aml_return(mr64)); | |
595 | } | |
596 | aml_append(mem_ctrl_dev, method); | |
597 | ||
598 | method = aml_method(MEMORY_SLOT_PROXIMITY_METHOD, 1, | |
599 | AML_NOTSERIALIZED); | |
600 | { | |
601 | Aml *proximity = aml_name(MEMORY_SLOT_PROXIMITY); | |
602 | ||
603 | aml_append(method, aml_acquire(ctrl_lock, 0xFFFF)); | |
604 | aml_append(method, aml_store(aml_to_integer(slot_arg0), | |
605 | slot_selector)); | |
606 | aml_append(method, aml_store(proximity, ret_val)); | |
607 | aml_append(method, aml_release(ctrl_lock)); | |
608 | aml_append(method, aml_return(ret_val)); | |
609 | } | |
610 | aml_append(mem_ctrl_dev, method); | |
611 | ||
612 | method = aml_method(MEMORY_SLOT_OST_METHOD, 4, AML_NOTSERIALIZED); | |
613 | { | |
614 | Aml *ost_evt = aml_name(MEMORY_SLOT_OST_EVENT); | |
615 | Aml *ost_status = aml_name(MEMORY_SLOT_OST_STATUS); | |
616 | ||
617 | aml_append(method, aml_acquire(ctrl_lock, 0xFFFF)); | |
618 | aml_append(method, aml_store(aml_to_integer(slot_arg0), | |
619 | slot_selector)); | |
620 | aml_append(method, aml_store(aml_arg(1), ost_evt)); | |
621 | aml_append(method, aml_store(aml_arg(2), ost_status)); | |
622 | aml_append(method, aml_release(ctrl_lock)); | |
623 | } | |
624 | aml_append(mem_ctrl_dev, method); | |
625 | ||
626 | method = aml_method(MEMORY_SLOT_EJECT_METHOD, 2, AML_NOTSERIALIZED); | |
627 | { | |
628 | Aml *eject = aml_name(MEMORY_SLOT_EJECT); | |
629 | ||
630 | aml_append(method, aml_acquire(ctrl_lock, 0xFFFF)); | |
631 | aml_append(method, aml_store(aml_to_integer(slot_arg0), | |
632 | slot_selector)); | |
633 | aml_append(method, aml_store(one, eject)); | |
634 | aml_append(method, aml_release(ctrl_lock)); | |
635 | } | |
636 | aml_append(mem_ctrl_dev, method); | |
637 | } | |
d1957dac | 638 | aml_append(table, mem_ctrl_dev); |
75ff0f0c | 639 | |
8b35ab27 | 640 | sb_scope = aml_scope("_SB"); |
75ff0f0c | 641 | /* build memory devices */ |
75ff0f0c | 642 | for (i = 0; i < nr_mem; i++) { |
8b35ab27 | 643 | Aml *dev; |
d1957dac | 644 | char *s; |
75ff0f0c IM |
645 | |
646 | dev = aml_device("MP%02X", i); | |
647 | aml_append(dev, aml_name_decl("_UID", aml_string("0x%02X", i))); | |
648 | aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0C80"))); | |
649 | ||
650 | method = aml_method("_CRS", 0, AML_NOTSERIALIZED); | |
d1957dac | 651 | s = g_strdup_printf("%s.%s", mhp_res_path, MEMORY_SLOT_CRS_METHOD); |
75ff0f0c | 652 | aml_append(method, aml_return(aml_call1(s, aml_name("_UID")))); |
d1957dac | 653 | g_free(s); |
75ff0f0c IM |
654 | aml_append(dev, method); |
655 | ||
656 | method = aml_method("_STA", 0, AML_NOTSERIALIZED); | |
d1957dac | 657 | s = g_strdup_printf("%s.%s", mhp_res_path, MEMORY_SLOT_STATUS_METHOD); |
75ff0f0c | 658 | aml_append(method, aml_return(aml_call1(s, aml_name("_UID")))); |
d1957dac | 659 | g_free(s); |
75ff0f0c IM |
660 | aml_append(dev, method); |
661 | ||
662 | method = aml_method("_PXM", 0, AML_NOTSERIALIZED); | |
d1957dac IM |
663 | s = g_strdup_printf("%s.%s", mhp_res_path, |
664 | MEMORY_SLOT_PROXIMITY_METHOD); | |
75ff0f0c | 665 | aml_append(method, aml_return(aml_call1(s, aml_name("_UID")))); |
d1957dac | 666 | g_free(s); |
75ff0f0c IM |
667 | aml_append(dev, method); |
668 | ||
669 | method = aml_method("_OST", 3, AML_NOTSERIALIZED); | |
d1957dac | 670 | s = g_strdup_printf("%s.%s", mhp_res_path, MEMORY_SLOT_OST_METHOD); |
75ff0f0c IM |
671 | aml_append(method, aml_return(aml_call4( |
672 | s, aml_name("_UID"), aml_arg(0), aml_arg(1), aml_arg(2) | |
673 | ))); | |
d1957dac | 674 | g_free(s); |
75ff0f0c IM |
675 | aml_append(dev, method); |
676 | ||
677 | method = aml_method("_EJ0", 1, AML_NOTSERIALIZED); | |
d1957dac | 678 | s = g_strdup_printf("%s.%s", mhp_res_path, MEMORY_SLOT_EJECT_METHOD); |
75ff0f0c IM |
679 | aml_append(method, aml_return(aml_call2( |
680 | s, aml_name("_UID"), aml_arg(0)))); | |
d1957dac | 681 | g_free(s); |
75ff0f0c IM |
682 | aml_append(dev, method); |
683 | ||
684 | aml_append(sb_scope, dev); | |
685 | } | |
686 | ||
687 | /* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) { | |
688 | * If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ... } | |
689 | */ | |
690 | method = aml_method(MEMORY_SLOT_NOTIFY_METHOD, 2, AML_NOTSERIALIZED); | |
691 | for (i = 0; i < nr_mem; i++) { | |
692 | ifctx = aml_if(aml_equal(aml_arg(0), aml_int(i))); | |
693 | aml_append(ifctx, | |
694 | aml_notify(aml_name("MP%.02X", i), aml_arg(1)) | |
695 | ); | |
696 | aml_append(method, ifctx); | |
697 | } | |
698 | aml_append(sb_scope, method); | |
8b35ab27 | 699 | aml_append(table, sb_scope); |
d1957dac IM |
700 | |
701 | method = aml_method(event_handler_method, 0, AML_NOTSERIALIZED); | |
702 | scan_path = g_strdup_printf("%s.%s", mhp_res_path, MEMORY_SLOT_SCAN_METHOD); | |
703 | aml_append(method, aml_call0(scan_path)); | |
704 | g_free(scan_path); | |
705 | aml_append(table, method); | |
706 | ||
707 | g_free(mhp_res_path); | |
75ff0f0c | 708 | } |