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"
5 #include "hw/qdev-core.h"
6 #include "migration/vmstate.h"
8 #include "qapi/error.h"
9 #include "qapi/qapi-events-acpi.h"
10 #include "qapi/qapi-events-machine.h"
11 #include "qapi/qapi-events-qdev.h"
13 #define MEMORY_SLOTS_NUMBER "MDNR"
14 #define MEMORY_HOTPLUG_IO_REGION "HPMR"
15 #define MEMORY_SLOT_ADDR_LOW "MRBL"
16 #define MEMORY_SLOT_ADDR_HIGH "MRBH"
17 #define MEMORY_SLOT_SIZE_LOW "MRLL"
18 #define MEMORY_SLOT_SIZE_HIGH "MRLH"
19 #define MEMORY_SLOT_PROXIMITY "MPX"
20 #define MEMORY_SLOT_ENABLED "MES"
21 #define MEMORY_SLOT_INSERT_EVENT "MINS"
22 #define MEMORY_SLOT_REMOVE_EVENT "MRMV"
23 #define MEMORY_SLOT_EJECT "MEJ"
24 #define MEMORY_SLOT_SLECTOR "MSEL"
25 #define MEMORY_SLOT_OST_EVENT "MOEV"
26 #define MEMORY_SLOT_OST_STATUS "MOSC"
27 #define MEMORY_SLOT_LOCK "MLCK"
28 #define MEMORY_SLOT_STATUS_METHOD "MRST"
29 #define MEMORY_SLOT_CRS_METHOD "MCRS"
30 #define MEMORY_SLOT_OST_METHOD "MOST"
31 #define MEMORY_SLOT_PROXIMITY_METHOD "MPXM"
32 #define MEMORY_SLOT_EJECT_METHOD "MEJ0"
33 #define MEMORY_SLOT_NOTIFY_METHOD "MTFY"
34 #define MEMORY_HOTPLUG_DEVICE "MHPD"
36 static ACPIOSTInfo
*acpi_memory_device_status(int slot
, MemStatus
*mdev
)
38 ACPIOSTInfo
*info
= g_new0(ACPIOSTInfo
, 1);
40 info
->slot_type
= ACPI_SLOT_TYPE_DIMM
;
41 info
->slot
= g_strdup_printf("%d", slot
);
42 info
->source
= mdev
->ost_event
;
43 info
->status
= mdev
->ost_status
;
45 DeviceState
*dev
= DEVICE(mdev
->dimm
);
47 info
->device
= g_strdup(dev
->id
);
48 info
->has_device
= true;
54 void acpi_memory_ospm_status(MemHotplugState
*mem_st
, ACPIOSTInfoList
***list
)
56 ACPIOSTInfoList
***tail
= list
;
59 for (i
= 0; i
< mem_st
->dev_count
; i
++) {
60 QAPI_LIST_APPEND(*tail
,
61 acpi_memory_device_status(i
, &mem_st
->devs
[i
]));
65 static uint64_t acpi_memory_hotplug_read(void *opaque
, hwaddr addr
,
69 MemHotplugState
*mem_st
= opaque
;
73 if (mem_st
->selector
>= mem_st
->dev_count
) {
74 trace_mhp_acpi_invalid_slot_selected(mem_st
->selector
);
78 mdev
= &mem_st
->devs
[mem_st
->selector
];
79 o
= OBJECT(mdev
->dimm
);
81 case 0x0: /* Lo part of phys address where DIMM is mapped */
82 val
= o
? object_property_get_uint(o
, PC_DIMM_ADDR_PROP
, NULL
) : 0;
83 trace_mhp_acpi_read_addr_lo(mem_st
->selector
, val
);
85 case 0x4: /* Hi part of phys address where DIMM is mapped */
87 o
? object_property_get_uint(o
, PC_DIMM_ADDR_PROP
, NULL
) >> 32 : 0;
88 trace_mhp_acpi_read_addr_hi(mem_st
->selector
, val
);
90 case 0x8: /* Lo part of DIMM size */
91 val
= o
? object_property_get_uint(o
, PC_DIMM_SIZE_PROP
, NULL
) : 0;
92 trace_mhp_acpi_read_size_lo(mem_st
->selector
, val
);
94 case 0xc: /* Hi part of DIMM size */
96 o
? object_property_get_uint(o
, PC_DIMM_SIZE_PROP
, NULL
) >> 32 : 0;
97 trace_mhp_acpi_read_size_hi(mem_st
->selector
, val
);
99 case 0x10: /* node proximity for _PXM method */
100 val
= o
? object_property_get_uint(o
, PC_DIMM_NODE_PROP
, NULL
) : 0;
101 trace_mhp_acpi_read_pxm(mem_st
->selector
, val
);
103 case 0x14: /* pack and return is_* fields */
104 val
|= mdev
->is_enabled
? 1 : 0;
105 val
|= mdev
->is_inserting
? 2 : 0;
106 val
|= mdev
->is_removing
? 4 : 0;
107 trace_mhp_acpi_read_flags(mem_st
->selector
, val
);
116 static void acpi_memory_hotplug_write(void *opaque
, hwaddr addr
, uint64_t data
,
119 MemHotplugState
*mem_st
= opaque
;
122 DeviceState
*dev
= NULL
;
123 HotplugHandler
*hotplug_ctrl
= NULL
;
124 Error
*local_err
= NULL
;
126 if (!mem_st
->dev_count
) {
131 if (mem_st
->selector
>= mem_st
->dev_count
) {
132 trace_mhp_acpi_invalid_slot_selected(mem_st
->selector
);
138 case 0x0: /* DIMM slot selector */
139 mem_st
->selector
= data
;
140 trace_mhp_acpi_write_slot(mem_st
->selector
);
142 case 0x4: /* _OST event */
143 mdev
= &mem_st
->devs
[mem_st
->selector
];
145 /* TODO: handle device insert OST event */
146 } else if (data
== 3) {
147 /* TODO: handle device remove OST event */
149 mdev
->ost_event
= data
;
150 trace_mhp_acpi_write_ost_ev(mem_st
->selector
, mdev
->ost_event
);
152 case 0x8: /* _OST status */
153 mdev
= &mem_st
->devs
[mem_st
->selector
];
154 mdev
->ost_status
= data
;
155 trace_mhp_acpi_write_ost_status(mem_st
->selector
, mdev
->ost_status
);
156 /* TODO: implement memory removal on guest signal */
158 info
= acpi_memory_device_status(mem_st
->selector
, mdev
);
159 qapi_event_send_acpi_device_ost(info
);
160 qapi_free_ACPIOSTInfo(info
);
162 case 0x14: /* set is_* fields */
163 mdev
= &mem_st
->devs
[mem_st
->selector
];
164 if (data
& 2) { /* clear insert event */
165 mdev
->is_inserting
= false;
166 trace_mhp_acpi_clear_insert_evt(mem_st
->selector
);
167 } else if (data
& 4) {
168 mdev
->is_removing
= false;
169 trace_mhp_acpi_clear_remove_evt(mem_st
->selector
);
170 } else if (data
& 8) {
171 if (!mdev
->is_enabled
) {
172 trace_mhp_acpi_ejecting_invalid_slot(mem_st
->selector
);
176 dev
= DEVICE(mdev
->dimm
);
177 hotplug_ctrl
= qdev_get_hotplug_handler(dev
);
178 /* call pc-dimm unplug cb */
179 hotplug_handler_unplug(hotplug_ctrl
, dev
, &local_err
);
181 trace_mhp_acpi_pc_dimm_delete_failed(mem_st
->selector
);
184 * Send both MEM_UNPLUG_ERROR and DEVICE_UNPLUG_GUEST_ERROR
185 * while the deprecation of MEM_UNPLUG_ERROR is
188 qapi_event_send_mem_unplug_error(dev
->id
? : "",
189 error_get_pretty(local_err
));
190 qapi_event_send_device_unplug_guest_error(!!dev
->id
, dev
->id
,
191 dev
->canonical_path
);
192 error_free(local_err
);
195 object_unparent(OBJECT(dev
));
196 trace_mhp_acpi_pc_dimm_deleted(mem_st
->selector
);
204 static const MemoryRegionOps acpi_memory_hotplug_ops
= {
205 .read
= acpi_memory_hotplug_read
,
206 .write
= acpi_memory_hotplug_write
,
207 .endianness
= DEVICE_LITTLE_ENDIAN
,
209 .min_access_size
= 1,
210 .max_access_size
= 4,
214 void acpi_memory_hotplug_init(MemoryRegion
*as
, Object
*owner
,
215 MemHotplugState
*state
, hwaddr io_base
)
217 MachineState
*machine
= MACHINE(qdev_get_machine());
219 state
->dev_count
= machine
->ram_slots
;
220 if (!state
->dev_count
) {
224 state
->devs
= g_malloc0(sizeof(*state
->devs
) * state
->dev_count
);
225 memory_region_init_io(&state
->io
, owner
, &acpi_memory_hotplug_ops
, state
,
226 "acpi-mem-hotplug", MEMORY_HOTPLUG_IO_LEN
);
227 memory_region_add_subregion(as
, io_base
, &state
->io
);
231 * acpi_memory_slot_status:
232 * @mem_st: memory hotplug state
234 * @errp: set in case of an error
236 * Obtain a single memory slot status.
238 * This function will be called by memory unplug request cb and unplug cb.
241 acpi_memory_slot_status(MemHotplugState
*mem_st
,
242 DeviceState
*dev
, Error
**errp
)
244 Error
*local_err
= NULL
;
245 int slot
= object_property_get_int(OBJECT(dev
), PC_DIMM_SLOT_PROP
,
249 error_propagate(errp
, local_err
);
253 if (slot
>= mem_st
->dev_count
) {
254 char *dev_path
= object_get_canonical_path(OBJECT(dev
));
255 error_setg(errp
, "acpi_memory_slot_status: "
256 "device [%s] returned invalid memory slot[%d]",
262 return &mem_st
->devs
[slot
];
265 void acpi_memory_plug_cb(HotplugHandler
*hotplug_dev
, MemHotplugState
*mem_st
,
266 DeviceState
*dev
, Error
**errp
)
269 DeviceClass
*dc
= DEVICE_GET_CLASS(dev
);
271 if (!dc
->hotpluggable
) {
275 mdev
= acpi_memory_slot_status(mem_st
, dev
, errp
);
281 mdev
->is_enabled
= true;
282 if (dev
->hotplugged
) {
283 mdev
->is_inserting
= true;
284 acpi_send_event(DEVICE(hotplug_dev
), ACPI_MEMORY_HOTPLUG_STATUS
);
288 void acpi_memory_unplug_request_cb(HotplugHandler
*hotplug_dev
,
289 MemHotplugState
*mem_st
,
290 DeviceState
*dev
, Error
**errp
)
294 mdev
= acpi_memory_slot_status(mem_st
, dev
, errp
);
299 mdev
->is_removing
= true;
300 acpi_send_event(DEVICE(hotplug_dev
), ACPI_MEMORY_HOTPLUG_STATUS
);
303 void acpi_memory_unplug_cb(MemHotplugState
*mem_st
,
304 DeviceState
*dev
, Error
**errp
)
308 mdev
= acpi_memory_slot_status(mem_st
, dev
, errp
);
313 mdev
->is_enabled
= false;
317 static const VMStateDescription vmstate_memhp_sts
= {
318 .name
= "memory hotplug device state",
320 .minimum_version_id
= 1,
321 .minimum_version_id_old
= 1,
322 .fields
= (VMStateField
[]) {
323 VMSTATE_BOOL(is_enabled
, MemStatus
),
324 VMSTATE_BOOL(is_inserting
, MemStatus
),
325 VMSTATE_UINT32(ost_event
, MemStatus
),
326 VMSTATE_UINT32(ost_status
, MemStatus
),
327 VMSTATE_END_OF_LIST()
331 const VMStateDescription vmstate_memory_hotplug
= {
332 .name
= "memory hotplug state",
334 .minimum_version_id
= 1,
335 .minimum_version_id_old
= 1,
336 .fields
= (VMStateField
[]) {
337 VMSTATE_UINT32(selector
, MemHotplugState
),
338 VMSTATE_STRUCT_VARRAY_POINTER_UINT32(devs
, MemHotplugState
, dev_count
,
339 vmstate_memhp_sts
, MemStatus
),
340 VMSTATE_END_OF_LIST()
344 void build_memory_hotplug_aml(Aml
*table
, uint32_t nr_mem
,
345 const char *res_root
,
346 const char *event_handler_method
,
347 AmlRegionSpace rs
, hwaddr memhp_io_base
)
356 mhp_res_path
= g_strdup_printf("%s." MEMORY_HOTPLUG_DEVICE
, res_root
);
357 mem_ctrl_dev
= aml_device("%s", mhp_res_path
);
361 aml_append(mem_ctrl_dev
, aml_name_decl("_HID", aml_string("PNP0A06")));
362 aml_append(mem_ctrl_dev
,
363 aml_name_decl("_UID", aml_string("Memory hotplug resources")));
365 crs
= aml_resource_template();
366 if (rs
== AML_SYSTEM_IO
) {
368 aml_io(AML_DECODE16
, memhp_io_base
, memhp_io_base
, 0,
369 MEMORY_HOTPLUG_IO_LEN
)
372 aml_append(crs
, aml_memory32_fixed(memhp_io_base
,
373 MEMORY_HOTPLUG_IO_LEN
, AML_READ_WRITE
));
375 aml_append(mem_ctrl_dev
, aml_name_decl("_CRS", crs
));
377 aml_append(mem_ctrl_dev
, aml_operation_region(
378 MEMORY_HOTPLUG_IO_REGION
, rs
,
379 aml_int(memhp_io_base
), MEMORY_HOTPLUG_IO_LEN
)
383 aml_append(table
, mem_ctrl_dev
);
385 dev_container
= aml_device(MEMORY_DEVICES_CONTAINER
);
388 Aml
*one
= aml_int(1);
389 Aml
*zero
= aml_int(0);
390 Aml
*ret_val
= aml_local(0);
391 Aml
*slot_arg0
= aml_arg(0);
392 Aml
*slots_nr
= aml_name(MEMORY_SLOTS_NUMBER
);
393 Aml
*ctrl_lock
= aml_name(MEMORY_SLOT_LOCK
);
394 Aml
*slot_selector
= aml_name(MEMORY_SLOT_SLECTOR
);
395 char *mmio_path
= g_strdup_printf("%s." MEMORY_HOTPLUG_IO_REGION
,
398 aml_append(dev_container
, aml_name_decl("_HID", aml_string("PNP0A06")));
399 aml_append(dev_container
,
400 aml_name_decl("_UID", aml_string("DIMM devices")));
402 assert(nr_mem
<= ACPI_MAX_RAM_SLOTS
);
403 aml_append(dev_container
,
404 aml_name_decl(MEMORY_SLOTS_NUMBER
, aml_int(nr_mem
))
407 field
= aml_field(mmio_path
, AML_DWORD_ACC
,
408 AML_NOLOCK
, AML_PRESERVE
);
409 aml_append(field
, /* read only */
410 aml_named_field(MEMORY_SLOT_ADDR_LOW
, 32));
411 aml_append(field
, /* read only */
412 aml_named_field(MEMORY_SLOT_ADDR_HIGH
, 32));
413 aml_append(field
, /* read only */
414 aml_named_field(MEMORY_SLOT_SIZE_LOW
, 32));
415 aml_append(field
, /* read only */
416 aml_named_field(MEMORY_SLOT_SIZE_HIGH
, 32));
417 aml_append(field
, /* read only */
418 aml_named_field(MEMORY_SLOT_PROXIMITY
, 32));
419 aml_append(dev_container
, field
);
421 field
= aml_field(mmio_path
, AML_BYTE_ACC
,
422 AML_NOLOCK
, AML_WRITE_AS_ZEROS
);
423 aml_append(field
, aml_reserved_field(160 /* bits, Offset(20) */));
424 aml_append(field
, /* 1 if enabled, read only */
425 aml_named_field(MEMORY_SLOT_ENABLED
, 1));
427 /*(read) 1 if has a insert event. (write) 1 to clear event */
428 aml_named_field(MEMORY_SLOT_INSERT_EVENT
, 1));
430 /* (read) 1 if has a remove event. (write) 1 to clear event */
431 aml_named_field(MEMORY_SLOT_REMOVE_EVENT
, 1));
433 /* initiates device eject, write only */
434 aml_named_field(MEMORY_SLOT_EJECT
, 1));
435 aml_append(dev_container
, field
);
437 field
= aml_field(mmio_path
, AML_DWORD_ACC
,
438 AML_NOLOCK
, AML_PRESERVE
);
439 aml_append(field
, /* DIMM selector, write only */
440 aml_named_field(MEMORY_SLOT_SLECTOR
, 32));
441 aml_append(field
, /* _OST event code, write only */
442 aml_named_field(MEMORY_SLOT_OST_EVENT
, 32));
443 aml_append(field
, /* _OST status code, write only */
444 aml_named_field(MEMORY_SLOT_OST_STATUS
, 32));
445 aml_append(dev_container
, field
);
448 method
= aml_method("_STA", 0, AML_NOTSERIALIZED
);
449 ifctx
= aml_if(aml_equal(slots_nr
, zero
));
451 aml_append(ifctx
, aml_return(zero
));
453 aml_append(method
, ifctx
);
454 /* present, functioning, decoding, not shown in UI */
455 aml_append(method
, aml_return(aml_int(0xB)));
456 aml_append(dev_container
, method
);
458 aml_append(dev_container
, aml_mutex(MEMORY_SLOT_LOCK
, 0));
460 method
= aml_method(MEMORY_SLOT_SCAN_METHOD
, 0, AML_NOTSERIALIZED
);
464 Aml
*idx
= aml_local(0);
465 Aml
*eject_req
= aml_int(3);
466 Aml
*dev_chk
= aml_int(1);
468 ifctx
= aml_if(aml_equal(slots_nr
, zero
));
470 aml_append(ifctx
, aml_return(zero
));
472 aml_append(method
, ifctx
);
474 aml_append(method
, aml_store(zero
, idx
));
475 aml_append(method
, aml_acquire(ctrl_lock
, 0xFFFF));
477 * loops over all slots and Notifies DIMMs with
478 * Device Check or Eject Request notifications if
479 * slot has corresponding status bit set and clears
482 while_ctx
= aml_while(aml_lless(idx
, slots_nr
));
484 Aml
*ins_evt
= aml_name(MEMORY_SLOT_INSERT_EVENT
);
485 Aml
*rm_evt
= aml_name(MEMORY_SLOT_REMOVE_EVENT
);
487 aml_append(while_ctx
, aml_store(idx
, slot_selector
));
488 ifctx
= aml_if(aml_equal(ins_evt
, one
));
491 aml_call2(MEMORY_SLOT_NOTIFY_METHOD
,
493 aml_append(ifctx
, aml_store(one
, ins_evt
));
495 aml_append(while_ctx
, ifctx
);
497 else_ctx
= aml_else();
498 ifctx
= aml_if(aml_equal(rm_evt
, one
));
501 aml_call2(MEMORY_SLOT_NOTIFY_METHOD
,
503 aml_append(ifctx
, aml_store(one
, rm_evt
));
505 aml_append(else_ctx
, ifctx
);
506 aml_append(while_ctx
, else_ctx
);
508 aml_append(while_ctx
, aml_add(idx
, one
, idx
));
510 aml_append(method
, while_ctx
);
511 aml_append(method
, aml_release(ctrl_lock
));
512 aml_append(method
, aml_return(one
));
514 aml_append(dev_container
, method
);
516 method
= aml_method(MEMORY_SLOT_STATUS_METHOD
, 1, AML_NOTSERIALIZED
);
518 Aml
*slot_enabled
= aml_name(MEMORY_SLOT_ENABLED
);
520 aml_append(method
, aml_store(zero
, ret_val
));
521 aml_append(method
, aml_acquire(ctrl_lock
, 0xFFFF));
523 aml_store(aml_to_integer(slot_arg0
), slot_selector
));
525 ifctx
= aml_if(aml_equal(slot_enabled
, one
));
527 aml_append(ifctx
, aml_store(aml_int(0xF), ret_val
));
529 aml_append(method
, ifctx
);
531 aml_append(method
, aml_release(ctrl_lock
));
532 aml_append(method
, aml_return(ret_val
));
534 aml_append(dev_container
, method
);
536 method
= aml_method(MEMORY_SLOT_CRS_METHOD
, 1, AML_SERIALIZED
);
538 Aml
*mr64
= aml_name("MR64");
539 Aml
*mr32
= aml_name("MR32");
540 Aml
*crs_tmpl
= aml_resource_template();
541 Aml
*minl
= aml_name("MINL");
542 Aml
*minh
= aml_name("MINH");
543 Aml
*maxl
= aml_name("MAXL");
544 Aml
*maxh
= aml_name("MAXH");
545 Aml
*lenl
= aml_name("LENL");
546 Aml
*lenh
= aml_name("LENH");
548 aml_append(method
, aml_acquire(ctrl_lock
, 0xFFFF));
549 aml_append(method
, aml_store(aml_to_integer(slot_arg0
),
553 aml_qword_memory(AML_POS_DECODE
, AML_MIN_FIXED
, AML_MAX_FIXED
,
554 AML_CACHEABLE
, AML_READ_WRITE
,
555 0, 0x0, 0xFFFFFFFFFFFFFFFEULL
, 0,
556 0xFFFFFFFFFFFFFFFFULL
));
557 aml_append(method
, aml_name_decl("MR64", crs_tmpl
));
559 aml_create_dword_field(mr64
, aml_int(14), "MINL"));
561 aml_create_dword_field(mr64
, aml_int(18), "MINH"));
563 aml_create_dword_field(mr64
, aml_int(38), "LENL"));
565 aml_create_dword_field(mr64
, aml_int(42), "LENH"));
567 aml_create_dword_field(mr64
, aml_int(22), "MAXL"));
569 aml_create_dword_field(mr64
, aml_int(26), "MAXH"));
572 aml_store(aml_name(MEMORY_SLOT_ADDR_HIGH
), minh
));
574 aml_store(aml_name(MEMORY_SLOT_ADDR_LOW
), minl
));
576 aml_store(aml_name(MEMORY_SLOT_SIZE_HIGH
), lenh
));
578 aml_store(aml_name(MEMORY_SLOT_SIZE_LOW
), lenl
));
580 /* 64-bit math: MAX = MIN + LEN - 1 */
581 aml_append(method
, aml_add(minl
, lenl
, maxl
));
582 aml_append(method
, aml_add(minh
, lenh
, maxh
));
583 ifctx
= aml_if(aml_lless(maxl
, minl
));
585 aml_append(ifctx
, aml_add(maxh
, one
, maxh
));
587 aml_append(method
, ifctx
);
588 ifctx
= aml_if(aml_lless(maxl
, one
));
590 aml_append(ifctx
, aml_subtract(maxh
, one
, maxh
));
592 aml_append(method
, ifctx
);
593 aml_append(method
, aml_subtract(maxl
, one
, maxl
));
595 /* return 32-bit _CRS if addr/size is in low mem */
596 /* TODO: remove it since all hotplugged DIMMs are in high mem */
597 ifctx
= aml_if(aml_equal(maxh
, zero
));
599 crs_tmpl
= aml_resource_template();
601 aml_dword_memory(AML_POS_DECODE
, AML_MIN_FIXED
,
602 AML_MAX_FIXED
, AML_CACHEABLE
,
604 0, 0x0, 0xFFFFFFFE, 0,
606 aml_append(ifctx
, aml_name_decl("MR32", crs_tmpl
));
608 aml_create_dword_field(mr32
, aml_int(10), "MIN"));
610 aml_create_dword_field(mr32
, aml_int(14), "MAX"));
612 aml_create_dword_field(mr32
, aml_int(22), "LEN"));
613 aml_append(ifctx
, aml_store(minl
, aml_name("MIN")));
614 aml_append(ifctx
, aml_store(maxl
, aml_name("MAX")));
615 aml_append(ifctx
, aml_store(lenl
, aml_name("LEN")));
617 aml_append(ifctx
, aml_release(ctrl_lock
));
618 aml_append(ifctx
, aml_return(mr32
));
620 aml_append(method
, ifctx
);
622 aml_append(method
, aml_release(ctrl_lock
));
623 aml_append(method
, aml_return(mr64
));
625 aml_append(dev_container
, method
);
627 method
= aml_method(MEMORY_SLOT_PROXIMITY_METHOD
, 1,
630 Aml
*proximity
= aml_name(MEMORY_SLOT_PROXIMITY
);
632 aml_append(method
, aml_acquire(ctrl_lock
, 0xFFFF));
633 aml_append(method
, aml_store(aml_to_integer(slot_arg0
),
635 aml_append(method
, aml_store(proximity
, ret_val
));
636 aml_append(method
, aml_release(ctrl_lock
));
637 aml_append(method
, aml_return(ret_val
));
639 aml_append(dev_container
, method
);
641 method
= aml_method(MEMORY_SLOT_OST_METHOD
, 4, AML_NOTSERIALIZED
);
643 Aml
*ost_evt
= aml_name(MEMORY_SLOT_OST_EVENT
);
644 Aml
*ost_status
= aml_name(MEMORY_SLOT_OST_STATUS
);
646 aml_append(method
, aml_acquire(ctrl_lock
, 0xFFFF));
647 aml_append(method
, aml_store(aml_to_integer(slot_arg0
),
649 aml_append(method
, aml_store(aml_arg(1), ost_evt
));
650 aml_append(method
, aml_store(aml_arg(2), ost_status
));
651 aml_append(method
, aml_release(ctrl_lock
));
653 aml_append(dev_container
, method
);
655 method
= aml_method(MEMORY_SLOT_EJECT_METHOD
, 2, AML_NOTSERIALIZED
);
657 Aml
*eject
= aml_name(MEMORY_SLOT_EJECT
);
659 aml_append(method
, aml_acquire(ctrl_lock
, 0xFFFF));
660 aml_append(method
, aml_store(aml_to_integer(slot_arg0
),
662 aml_append(method
, aml_store(one
, eject
));
663 aml_append(method
, aml_release(ctrl_lock
));
665 aml_append(dev_container
, method
);
667 /* build memory devices */
668 for (i
= 0; i
< nr_mem
; i
++) {
672 dev
= aml_device("MP%02X", i
);
673 aml_append(dev
, aml_name_decl("_UID", aml_string("0x%02X", i
)));
674 aml_append(dev
, aml_name_decl("_HID", aml_eisaid("PNP0C80")));
676 method
= aml_method("_CRS", 0, AML_NOTSERIALIZED
);
677 s
= MEMORY_SLOT_CRS_METHOD
;
678 aml_append(method
, aml_return(aml_call1(s
, aml_name("_UID"))));
679 aml_append(dev
, method
);
681 method
= aml_method("_STA", 0, AML_NOTSERIALIZED
);
682 s
= MEMORY_SLOT_STATUS_METHOD
;
683 aml_append(method
, aml_return(aml_call1(s
, aml_name("_UID"))));
684 aml_append(dev
, method
);
686 method
= aml_method("_PXM", 0, AML_NOTSERIALIZED
);
687 s
= MEMORY_SLOT_PROXIMITY_METHOD
;
688 aml_append(method
, aml_return(aml_call1(s
, aml_name("_UID"))));
689 aml_append(dev
, method
);
691 method
= aml_method("_OST", 3, AML_NOTSERIALIZED
);
692 s
= MEMORY_SLOT_OST_METHOD
;
694 aml_call4(s
, aml_name("_UID"), aml_arg(0),
695 aml_arg(1), aml_arg(2)));
696 aml_append(dev
, method
);
698 method
= aml_method("_EJ0", 1, AML_NOTSERIALIZED
);
699 s
= MEMORY_SLOT_EJECT_METHOD
;
701 aml_call2(s
, aml_name("_UID"), aml_arg(0)));
702 aml_append(dev
, method
);
704 aml_append(dev_container
, dev
);
707 /* build Method(MEMORY_SLOT_NOTIFY_METHOD, 2) {
708 * If (LEqual(Arg0, 0x00)) {Notify(MP00, Arg1)} ... }
710 method
= aml_method(MEMORY_SLOT_NOTIFY_METHOD
, 2, AML_NOTSERIALIZED
);
711 for (i
= 0; i
< nr_mem
; i
++) {
712 ifctx
= aml_if(aml_equal(aml_arg(0), aml_int(i
)));
714 aml_notify(aml_name("MP%.02X", i
), aml_arg(1))
716 aml_append(method
, ifctx
);
718 aml_append(dev_container
, method
);
720 aml_append(table
, dev_container
);
722 if (event_handler_method
) {
723 method
= aml_method(event_handler_method
, 0, AML_NOTSERIALIZED
);
724 aml_append(method
, aml_call0(MEMORY_DEVICES_CONTAINER
"."
725 MEMORY_SLOT_SCAN_METHOD
));
726 aml_append(table
, method
);
729 g_free(mhp_res_path
);