1 #include "qemu/osdep.h"
2 #include "hw/acpi/memory_hotplug.h"
3 #include "hw/acpi/pc-hotplug.h"
4 #include "hw/mem/pc-dimm.h"
6 #include "hw/qdev-core.h"
7 #include "migration/vmstate.h"
9 #include "qapi/error.h"
10 #include "qapi/qapi-events-misc.h"
12 #define MEMORY_SLOTS_NUMBER "MDNR"
13 #define MEMORY_HOTPLUG_IO_REGION "HPMR"
14 #define MEMORY_SLOT_ADDR_LOW "MRBL"
15 #define MEMORY_SLOT_ADDR_HIGH "MRBH"
16 #define MEMORY_SLOT_SIZE_LOW "MRLL"
17 #define MEMORY_SLOT_SIZE_HIGH "MRLH"
18 #define MEMORY_SLOT_PROXIMITY "MPX"
19 #define MEMORY_SLOT_ENABLED "MES"
20 #define MEMORY_SLOT_INSERT_EVENT "MINS"
21 #define MEMORY_SLOT_REMOVE_EVENT "MRMV"
22 #define MEMORY_SLOT_EJECT "MEJ"
23 #define MEMORY_SLOT_SLECTOR "MSEL"
24 #define MEMORY_SLOT_OST_EVENT "MOEV"
25 #define MEMORY_SLOT_OST_STATUS "MOSC"
26 #define MEMORY_SLOT_LOCK "MLCK"
27 #define MEMORY_SLOT_STATUS_METHOD "MRST"
28 #define MEMORY_SLOT_CRS_METHOD "MCRS"
29 #define MEMORY_SLOT_OST_METHOD "MOST"
30 #define MEMORY_SLOT_PROXIMITY_METHOD "MPXM"
31 #define MEMORY_SLOT_EJECT_METHOD "MEJ0"
32 #define MEMORY_SLOT_NOTIFY_METHOD "MTFY"
33 #define MEMORY_HOTPLUG_DEVICE "MHPD"
35 static ACPIOSTInfo
*acpi_memory_device_status(int slot
, MemStatus
*mdev
)
37 ACPIOSTInfo
*info
= g_new0(ACPIOSTInfo
, 1);
39 info
->slot_type
= ACPI_SLOT_TYPE_DIMM
;
40 info
->slot
= g_strdup_printf("%d", slot
);
41 info
->source
= mdev
->ost_event
;
42 info
->status
= mdev
->ost_status
;
44 DeviceState
*dev
= DEVICE(mdev
->dimm
);
46 info
->device
= g_strdup(dev
->id
);
47 info
->has_device
= true;
53 void acpi_memory_ospm_status(MemHotplugState
*mem_st
, ACPIOSTInfoList
***list
)
57 for (i
= 0; i
< mem_st
->dev_count
; i
++) {
58 ACPIOSTInfoList
*elem
= g_new0(ACPIOSTInfoList
, 1);
59 elem
->value
= acpi_memory_device_status(i
, &mem_st
->devs
[i
]);
66 static uint64_t acpi_memory_hotplug_read(void *opaque
, hwaddr addr
,
70 MemHotplugState
*mem_st
= opaque
;
74 if (mem_st
->selector
>= mem_st
->dev_count
) {
75 trace_mhp_acpi_invalid_slot_selected(mem_st
->selector
);
79 mdev
= &mem_st
->devs
[mem_st
->selector
];
80 o
= OBJECT(mdev
->dimm
);
82 case 0x0: /* Lo part of phys address where DIMM is mapped */
83 val
= o
? object_property_get_uint(o
, PC_DIMM_ADDR_PROP
, NULL
) : 0;
84 trace_mhp_acpi_read_addr_lo(mem_st
->selector
, val
);
86 case 0x4: /* Hi part of phys address where DIMM is mapped */
88 o
? object_property_get_uint(o
, PC_DIMM_ADDR_PROP
, NULL
) >> 32 : 0;
89 trace_mhp_acpi_read_addr_hi(mem_st
->selector
, val
);
91 case 0x8: /* Lo part of DIMM size */
92 val
= o
? object_property_get_uint(o
, PC_DIMM_SIZE_PROP
, NULL
) : 0;
93 trace_mhp_acpi_read_size_lo(mem_st
->selector
, val
);
95 case 0xc: /* Hi part of DIMM size */
97 o
? object_property_get_uint(o
, PC_DIMM_SIZE_PROP
, NULL
) >> 32 : 0;
98 trace_mhp_acpi_read_size_hi(mem_st
->selector
, val
);
100 case 0x10: /* node proximity for _PXM method */
101 val
= o
? object_property_get_uint(o
, PC_DIMM_NODE_PROP
, NULL
) : 0;
102 trace_mhp_acpi_read_pxm(mem_st
->selector
, val
);
104 case 0x14: /* pack and return is_* fields */
105 val
|= mdev
->is_enabled
? 1 : 0;
106 val
|= mdev
->is_inserting
? 2 : 0;
107 val
|= mdev
->is_removing
? 4 : 0;
108 trace_mhp_acpi_read_flags(mem_st
->selector
, val
);
117 static void acpi_memory_hotplug_write(void *opaque
, hwaddr addr
, uint64_t data
,
120 MemHotplugState
*mem_st
= opaque
;
123 DeviceState
*dev
= NULL
;
124 HotplugHandler
*hotplug_ctrl
= NULL
;
125 Error
*local_err
= NULL
;
127 if (!mem_st
->dev_count
) {
132 if (mem_st
->selector
>= mem_st
->dev_count
) {
133 trace_mhp_acpi_invalid_slot_selected(mem_st
->selector
);
139 case 0x0: /* DIMM slot selector */
140 mem_st
->selector
= data
;
141 trace_mhp_acpi_write_slot(mem_st
->selector
);
143 case 0x4: /* _OST event */
144 mdev
= &mem_st
->devs
[mem_st
->selector
];
146 /* TODO: handle device insert OST event */
147 } else if (data
== 3) {
148 /* TODO: handle device remove OST event */
150 mdev
->ost_event
= data
;
151 trace_mhp_acpi_write_ost_ev(mem_st
->selector
, mdev
->ost_event
);
153 case 0x8: /* _OST status */
154 mdev
= &mem_st
->devs
[mem_st
->selector
];
155 mdev
->ost_status
= data
;
156 trace_mhp_acpi_write_ost_status(mem_st
->selector
, mdev
->ost_status
);
157 /* TODO: implement memory removal on guest signal */
159 info
= acpi_memory_device_status(mem_st
->selector
, mdev
);
160 qapi_event_send_acpi_device_ost(info
);
161 qapi_free_ACPIOSTInfo(info
);
163 case 0x14: /* set is_* fields */
164 mdev
= &mem_st
->devs
[mem_st
->selector
];
165 if (data
& 2) { /* clear insert event */
166 mdev
->is_inserting
= false;
167 trace_mhp_acpi_clear_insert_evt(mem_st
->selector
);
168 } else if (data
& 4) {
169 mdev
->is_removing
= false;
170 trace_mhp_acpi_clear_remove_evt(mem_st
->selector
);
171 } else if (data
& 8) {
172 if (!mdev
->is_enabled
) {
173 trace_mhp_acpi_ejecting_invalid_slot(mem_st
->selector
);
177 dev
= DEVICE(mdev
->dimm
);
178 hotplug_ctrl
= qdev_get_hotplug_handler(dev
);
179 /* call pc-dimm unplug cb */
180 hotplug_handler_unplug(hotplug_ctrl
, dev
, &local_err
);
182 trace_mhp_acpi_pc_dimm_delete_failed(mem_st
->selector
);
183 qapi_event_send_mem_unplug_error(dev
->id
,
184 error_get_pretty(local_err
));
185 error_free(local_err
);
188 object_unparent(OBJECT(dev
));
189 trace_mhp_acpi_pc_dimm_deleted(mem_st
->selector
);
197 static const MemoryRegionOps acpi_memory_hotplug_ops
= {
198 .read
= acpi_memory_hotplug_read
,
199 .write
= acpi_memory_hotplug_write
,
200 .endianness
= DEVICE_LITTLE_ENDIAN
,
202 .min_access_size
= 1,
203 .max_access_size
= 4,
207 void acpi_memory_hotplug_init(MemoryRegion
*as
, Object
*owner
,
208 MemHotplugState
*state
, hwaddr io_base
)
210 MachineState
*machine
= MACHINE(qdev_get_machine());
212 state
->dev_count
= machine
->ram_slots
;
213 if (!state
->dev_count
) {
217 state
->devs
= g_malloc0(sizeof(*state
->devs
) * state
->dev_count
);
218 memory_region_init_io(&state
->io
, owner
, &acpi_memory_hotplug_ops
, state
,
219 "acpi-mem-hotplug", MEMORY_HOTPLUG_IO_LEN
);
220 memory_region_add_subregion(as
, io_base
, &state
->io
);
224 * acpi_memory_slot_status:
225 * @mem_st: memory hotplug state
227 * @errp: set in case of an error
229 * Obtain a single memory slot status.
231 * This function will be called by memory unplug request cb and unplug cb.
234 acpi_memory_slot_status(MemHotplugState
*mem_st
,
235 DeviceState
*dev
, Error
**errp
)
237 Error
*local_err
= NULL
;
238 int slot
= object_property_get_int(OBJECT(dev
), PC_DIMM_SLOT_PROP
,
242 error_propagate(errp
, local_err
);
246 if (slot
>= mem_st
->dev_count
) {
247 char *dev_path
= object_get_canonical_path(OBJECT(dev
));
248 error_setg(errp
, "acpi_memory_slot_status: "
249 "device [%s] returned invalid memory slot[%d]",
255 return &mem_st
->devs
[slot
];
258 void acpi_memory_plug_cb(HotplugHandler
*hotplug_dev
, MemHotplugState
*mem_st
,
259 DeviceState
*dev
, Error
**errp
)
262 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
264 if (!dc
->hotpluggable
) {
268 mdev
= acpi_memory_slot_status(mem_st
, dev
, errp
);
274 mdev
->is_enabled
= true;
275 if (dev
->hotplugged
) {
276 mdev
->is_inserting
= true;
277 acpi_send_event(DEVICE(hotplug_dev
), ACPI_MEMORY_HOTPLUG_STATUS
);
281 void acpi_memory_unplug_request_cb(HotplugHandler
*hotplug_dev
,
282 MemHotplugState
*mem_st
,
283 DeviceState
*dev
, Error
**errp
)
287 mdev
= acpi_memory_slot_status(mem_st
, dev
, errp
);
292 mdev
->is_removing
= true;
293 acpi_send_event(DEVICE(hotplug_dev
), ACPI_MEMORY_HOTPLUG_STATUS
);
296 void acpi_memory_unplug_cb(MemHotplugState
*mem_st
,
297 DeviceState
*dev
, Error
**errp
)
301 mdev
= acpi_memory_slot_status(mem_st
, dev
, errp
);
306 mdev
->is_enabled
= false;
310 static const VMStateDescription vmstate_memhp_sts
= {
311 .name
= "memory hotplug device state",
313 .minimum_version_id
= 1,
314 .minimum_version_id_old
= 1,
315 .fields
= (VMStateField
[]) {
316 VMSTATE_BOOL(is_enabled
, MemStatus
),
317 VMSTATE_BOOL(is_inserting
, MemStatus
),
318 VMSTATE_UINT32(ost_event
, MemStatus
),
319 VMSTATE_UINT32(ost_status
, MemStatus
),
320 VMSTATE_END_OF_LIST()
324 const VMStateDescription vmstate_memory_hotplug
= {
325 .name
= "memory hotplug state",
327 .minimum_version_id
= 1,
328 .minimum_version_id_old
= 1,
329 .fields
= (VMStateField
[]) {
330 VMSTATE_UINT32(selector
, MemHotplugState
),
331 VMSTATE_STRUCT_VARRAY_POINTER_UINT32(devs
, MemHotplugState
, dev_count
,
332 vmstate_memhp_sts
, MemStatus
),
333 VMSTATE_END_OF_LIST()
337 void build_memory_hotplug_aml(Aml
*table
, uint32_t nr_mem
,
338 const char *res_root
,
339 const char *event_handler_method
,
340 AmlRegionSpace rs
, hwaddr memhp_io_base
)
349 mhp_res_path
= g_strdup_printf("%s." MEMORY_HOTPLUG_DEVICE
, res_root
);
350 mem_ctrl_dev
= aml_device("%s", mhp_res_path
);
354 aml_append(mem_ctrl_dev
, aml_name_decl("_HID", aml_string("PNP0A06")));
355 aml_append(mem_ctrl_dev
,
356 aml_name_decl("_UID", aml_string("Memory hotplug resources")));
358 crs
= aml_resource_template();
359 if (rs
== AML_SYSTEM_IO
) {
361 aml_io(AML_DECODE16
, memhp_io_base
, memhp_io_base
, 0,
362 MEMORY_HOTPLUG_IO_LEN
)
365 aml_append(crs
, aml_memory32_fixed(memhp_io_base
,
366 MEMORY_HOTPLUG_IO_LEN
, AML_READ_WRITE
));
368 aml_append(mem_ctrl_dev
, aml_name_decl("_CRS", crs
));
370 aml_append(mem_ctrl_dev
, aml_operation_region(
371 MEMORY_HOTPLUG_IO_REGION
, rs
,
372 aml_int(memhp_io_base
), MEMORY_HOTPLUG_IO_LEN
)
376 aml_append(table
, mem_ctrl_dev
);
378 dev_container
= aml_device(MEMORY_DEVICES_CONTAINER
);
381 Aml
*one
= aml_int(1);
382 Aml
*zero
= aml_int(0);
383 Aml
*ret_val
= aml_local(0);
384 Aml
*slot_arg0
= aml_arg(0);
385 Aml
*slots_nr
= aml_name(MEMORY_SLOTS_NUMBER
);
386 Aml
*ctrl_lock
= aml_name(MEMORY_SLOT_LOCK
);
387 Aml
*slot_selector
= aml_name(MEMORY_SLOT_SLECTOR
);
388 char *mmio_path
= g_strdup_printf("%s." MEMORY_HOTPLUG_IO_REGION
,
391 aml_append(dev_container
, aml_name_decl("_HID", aml_string("PNP0A06")));
392 aml_append(dev_container
,
393 aml_name_decl("_UID", aml_string("DIMM devices")));
395 assert(nr_mem
<= ACPI_MAX_RAM_SLOTS
);
396 aml_append(dev_container
,
397 aml_name_decl(MEMORY_SLOTS_NUMBER
, aml_int(nr_mem
))
400 field
= aml_field(mmio_path
, AML_DWORD_ACC
,
401 AML_NOLOCK
, AML_PRESERVE
);
402 aml_append(field
, /* read only */
403 aml_named_field(MEMORY_SLOT_ADDR_LOW
, 32));
404 aml_append(field
, /* read only */
405 aml_named_field(MEMORY_SLOT_ADDR_HIGH
, 32));
406 aml_append(field
, /* read only */
407 aml_named_field(MEMORY_SLOT_SIZE_LOW
, 32));
408 aml_append(field
, /* read only */
409 aml_named_field(MEMORY_SLOT_SIZE_HIGH
, 32));
410 aml_append(field
, /* read only */
411 aml_named_field(MEMORY_SLOT_PROXIMITY
, 32));
412 aml_append(dev_container
, field
);
414 field
= aml_field(mmio_path
, AML_BYTE_ACC
,
415 AML_NOLOCK
, AML_WRITE_AS_ZEROS
);
416 aml_append(field
, aml_reserved_field(160 /* bits, Offset(20) */));
417 aml_append(field
, /* 1 if enabled, read only */
418 aml_named_field(MEMORY_SLOT_ENABLED
, 1));
420 /*(read) 1 if has a insert event. (write) 1 to clear event */
421 aml_named_field(MEMORY_SLOT_INSERT_EVENT
, 1));
423 /* (read) 1 if has a remove event. (write) 1 to clear event */
424 aml_named_field(MEMORY_SLOT_REMOVE_EVENT
, 1));
426 /* initiates device eject, write only */
427 aml_named_field(MEMORY_SLOT_EJECT
, 1));
428 aml_append(dev_container
, field
);
430 field
= aml_field(mmio_path
, AML_DWORD_ACC
,
431 AML_NOLOCK
, AML_PRESERVE
);
432 aml_append(field
, /* DIMM selector, write only */
433 aml_named_field(MEMORY_SLOT_SLECTOR
, 32));
434 aml_append(field
, /* _OST event code, write only */
435 aml_named_field(MEMORY_SLOT_OST_EVENT
, 32));
436 aml_append(field
, /* _OST status code, write only */
437 aml_named_field(MEMORY_SLOT_OST_STATUS
, 32));
438 aml_append(dev_container
, field
);
441 method
= aml_method("_STA", 0, AML_NOTSERIALIZED
);
442 ifctx
= aml_if(aml_equal(slots_nr
, zero
));
444 aml_append(ifctx
, aml_return(zero
));
446 aml_append(method
, ifctx
);
447 /* present, functioning, decoding, not shown in UI */
448 aml_append(method
, aml_return(aml_int(0xB)));
449 aml_append(dev_container
, method
);
451 aml_append(dev_container
, aml_mutex(MEMORY_SLOT_LOCK
, 0));
453 method
= aml_method(MEMORY_SLOT_SCAN_METHOD
, 0, AML_NOTSERIALIZED
);
457 Aml
*idx
= aml_local(0);
458 Aml
*eject_req
= aml_int(3);
459 Aml
*dev_chk
= aml_int(1);
461 ifctx
= aml_if(aml_equal(slots_nr
, zero
));
463 aml_append(ifctx
, aml_return(zero
));
465 aml_append(method
, ifctx
);
467 aml_append(method
, aml_store(zero
, idx
));
468 aml_append(method
, aml_acquire(ctrl_lock
, 0xFFFF));
470 * loops over all slots and Notifies DIMMs with
471 * Device Check or Eject Request notifications if
472 * slot has corresponding status bit set and clears
475 while_ctx
= aml_while(aml_lless(idx
, slots_nr
));
477 Aml
*ins_evt
= aml_name(MEMORY_SLOT_INSERT_EVENT
);
478 Aml
*rm_evt
= aml_name(MEMORY_SLOT_REMOVE_EVENT
);
480 aml_append(while_ctx
, aml_store(idx
, slot_selector
));
481 ifctx
= aml_if(aml_equal(ins_evt
, one
));
484 aml_call2(MEMORY_SLOT_NOTIFY_METHOD
,
486 aml_append(ifctx
, aml_store(one
, ins_evt
));
488 aml_append(while_ctx
, ifctx
);
490 else_ctx
= aml_else();
491 ifctx
= aml_if(aml_equal(rm_evt
, one
));
494 aml_call2(MEMORY_SLOT_NOTIFY_METHOD
,
496 aml_append(ifctx
, aml_store(one
, rm_evt
));
498 aml_append(else_ctx
, ifctx
);
499 aml_append(while_ctx
, else_ctx
);
501 aml_append(while_ctx
, aml_add(idx
, one
, idx
));
503 aml_append(method
, while_ctx
);
504 aml_append(method
, aml_release(ctrl_lock
));
505 aml_append(method
, aml_return(one
));
507 aml_append(dev_container
, method
);
509 method
= aml_method(MEMORY_SLOT_STATUS_METHOD
, 1, AML_NOTSERIALIZED
);
511 Aml
*slot_enabled
= aml_name(MEMORY_SLOT_ENABLED
);
513 aml_append(method
, aml_store(zero
, ret_val
));
514 aml_append(method
, aml_acquire(ctrl_lock
, 0xFFFF));
516 aml_store(aml_to_integer(slot_arg0
), slot_selector
));
518 ifctx
= aml_if(aml_equal(slot_enabled
, one
));
520 aml_append(ifctx
, aml_store(aml_int(0xF), ret_val
));
522 aml_append(method
, ifctx
);
524 aml_append(method
, aml_release(ctrl_lock
));
525 aml_append(method
, aml_return(ret_val
));
527 aml_append(dev_container
, method
);
529 method
= aml_method(MEMORY_SLOT_CRS_METHOD
, 1, AML_SERIALIZED
);
531 Aml
*mr64
= aml_name("MR64");
532 Aml
*mr32
= aml_name("MR32");
533 Aml
*crs_tmpl
= aml_resource_template();
534 Aml
*minl
= aml_name("MINL");
535 Aml
*minh
= aml_name("MINH");
536 Aml
*maxl
= aml_name("MAXL");
537 Aml
*maxh
= aml_name("MAXH");
538 Aml
*lenl
= aml_name("LENL");
539 Aml
*lenh
= aml_name("LENH");
541 aml_append(method
, aml_acquire(ctrl_lock
, 0xFFFF));
542 aml_append(method
, aml_store(aml_to_integer(slot_arg0
),
546 aml_qword_memory(AML_POS_DECODE
, AML_MIN_FIXED
, AML_MAX_FIXED
,
547 AML_CACHEABLE
, AML_READ_WRITE
,
548 0, 0x0, 0xFFFFFFFFFFFFFFFEULL
, 0,
549 0xFFFFFFFFFFFFFFFFULL
));
550 aml_append(method
, aml_name_decl("MR64", crs_tmpl
));
552 aml_create_dword_field(mr64
, aml_int(14), "MINL"));
554 aml_create_dword_field(mr64
, aml_int(18), "MINH"));
556 aml_create_dword_field(mr64
, aml_int(38), "LENL"));
558 aml_create_dword_field(mr64
, aml_int(42), "LENH"));
560 aml_create_dword_field(mr64
, aml_int(22), "MAXL"));
562 aml_create_dword_field(mr64
, aml_int(26), "MAXH"));
565 aml_store(aml_name(MEMORY_SLOT_ADDR_HIGH
), minh
));
567 aml_store(aml_name(MEMORY_SLOT_ADDR_LOW
), minl
));
569 aml_store(aml_name(MEMORY_SLOT_SIZE_HIGH
), lenh
));
571 aml_store(aml_name(MEMORY_SLOT_SIZE_LOW
), lenl
));
573 /* 64-bit math: MAX = MIN + LEN - 1 */
574 aml_append(method
, aml_add(minl
, lenl
, maxl
));
575 aml_append(method
, aml_add(minh
, lenh
, maxh
));
576 ifctx
= aml_if(aml_lless(maxl
, minl
));
578 aml_append(ifctx
, aml_add(maxh
, one
, maxh
));
580 aml_append(method
, ifctx
);
581 ifctx
= aml_if(aml_lless(maxl
, one
));
583 aml_append(ifctx
, aml_subtract(maxh
, one
, maxh
));
585 aml_append(method
, ifctx
);
586 aml_append(method
, aml_subtract(maxl
, one
, maxl
));
588 /* return 32-bit _CRS if addr/size is in low mem */
589 /* TODO: remove it since all hotplugged DIMMs are in high mem */
590 ifctx
= aml_if(aml_equal(maxh
, zero
));
592 crs_tmpl
= aml_resource_template();
594 aml_dword_memory(AML_POS_DECODE
, AML_MIN_FIXED
,
595 AML_MAX_FIXED
, AML_CACHEABLE
,
597 0, 0x0, 0xFFFFFFFE, 0,
599 aml_append(ifctx
, aml_name_decl("MR32", crs_tmpl
));
601 aml_create_dword_field(mr32
, aml_int(10), "MIN"));
603 aml_create_dword_field(mr32
, aml_int(14), "MAX"));
605 aml_create_dword_field(mr32
, aml_int(22), "LEN"));
606 aml_append(ifctx
, aml_store(minl
, aml_name("MIN")));
607 aml_append(ifctx
, aml_store(maxl
, aml_name("MAX")));
608 aml_append(ifctx
, aml_store(lenl
, aml_name("LEN")));
610 aml_append(ifctx
, aml_release(ctrl_lock
));
611 aml_append(ifctx
, aml_return(mr32
));
613 aml_append(method
, ifctx
);
615 aml_append(method
, aml_release(ctrl_lock
));
616 aml_append(method
, aml_return(mr64
));
618 aml_append(dev_container
, method
);
620 method
= aml_method(MEMORY_SLOT_PROXIMITY_METHOD
, 1,
623 Aml
*proximity
= aml_name(MEMORY_SLOT_PROXIMITY
);
625 aml_append(method
, aml_acquire(ctrl_lock
, 0xFFFF));
626 aml_append(method
, aml_store(aml_to_integer(slot_arg0
),
628 aml_append(method
, aml_store(proximity
, ret_val
));
629 aml_append(method
, aml_release(ctrl_lock
));
630 aml_append(method
, aml_return(ret_val
));
632 aml_append(dev_container
, method
);
634 method
= aml_method(MEMORY_SLOT_OST_METHOD
, 4, AML_NOTSERIALIZED
);
636 Aml
*ost_evt
= aml_name(MEMORY_SLOT_OST_EVENT
);
637 Aml
*ost_status
= aml_name(MEMORY_SLOT_OST_STATUS
);
639 aml_append(method
, aml_acquire(ctrl_lock
, 0xFFFF));
640 aml_append(method
, aml_store(aml_to_integer(slot_arg0
),
642 aml_append(method
, aml_store(aml_arg(1), ost_evt
));
643 aml_append(method
, aml_store(aml_arg(2), ost_status
));
644 aml_append(method
, aml_release(ctrl_lock
));
646 aml_append(dev_container
, method
);
648 method
= aml_method(MEMORY_SLOT_EJECT_METHOD
, 2, AML_NOTSERIALIZED
);
650 Aml
*eject
= aml_name(MEMORY_SLOT_EJECT
);
652 aml_append(method
, aml_acquire(ctrl_lock
, 0xFFFF));
653 aml_append(method
, aml_store(aml_to_integer(slot_arg0
),
655 aml_append(method
, aml_store(one
, eject
));
656 aml_append(method
, aml_release(ctrl_lock
));
658 aml_append(dev_container
, method
);
660 /* build memory devices */
661 for (i
= 0; i
< nr_mem
; i
++) {
665 dev
= aml_device("MP%02X", i
);
666 aml_append(dev
, aml_name_decl("_UID", aml_string("0x%02X", i
)));
667 aml_append(dev
, aml_name_decl("_HID", aml_eisaid("PNP0C80")));
669 method
= aml_method("_CRS", 0, AML_NOTSERIALIZED
);
670 s
= MEMORY_SLOT_CRS_METHOD
;
671 aml_append(method
, aml_return(aml_call1(s
, aml_name("_UID"))));
672 aml_append(dev
, method
);
674 method
= aml_method("_STA", 0, AML_NOTSERIALIZED
);
675 s
= MEMORY_SLOT_STATUS_METHOD
;
676 aml_append(method
, aml_return(aml_call1(s
, aml_name("_UID"))));
677 aml_append(dev
, method
);
679 method
= aml_method("_PXM", 0, AML_NOTSERIALIZED
);
680 s
= MEMORY_SLOT_PROXIMITY_METHOD
;
681 aml_append(method
, aml_return(aml_call1(s
, aml_name("_UID"))));
682 aml_append(dev
, method
);
684 method
= aml_method("_OST", 3, AML_NOTSERIALIZED
);
685 s
= MEMORY_SLOT_OST_METHOD
;
687 aml_call4(s
, aml_name("_UID"), aml_arg(0),
688 aml_arg(1), aml_arg(2)));
689 aml_append(dev
, method
);
691 method
= aml_method("_EJ0", 1, AML_NOTSERIALIZED
);
692 s
= MEMORY_SLOT_EJECT_METHOD
;
694 aml_call2(s
, aml_name("_UID"), aml_arg(0)));
695 aml_append(dev
, method
);
697 aml_append(dev_container
, dev
);
700 /* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) {
701 * If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ... }
703 method
= aml_method(MEMORY_SLOT_NOTIFY_METHOD
, 2, AML_NOTSERIALIZED
);
704 for (i
= 0; i
< nr_mem
; i
++) {
705 ifctx
= aml_if(aml_equal(aml_arg(0), aml_int(i
)));
707 aml_notify(aml_name("MP%.02X", i
), aml_arg(1))
709 aml_append(method
, ifctx
);
711 aml_append(dev_container
, method
);
713 aml_append(table
, dev_container
);
715 if (event_handler_method
) {
716 method
= aml_method(event_handler_method
, 0, AML_NOTSERIALIZED
);
717 aml_append(method
, aml_call0(MEMORY_DEVICES_CONTAINER
"."
718 MEMORY_SLOT_SCAN_METHOD
));
719 aml_append(table
, method
);
722 g_free(mhp_res_path
);