^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2012 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Author: Liu Jinsong <jinsong.liu@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author: Jiang Yunhong <yunhong.jiang@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <acpi/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <xen/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <xen/interface/platform.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/xen/hypercall.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define PREFIX "ACPI:xen_cpu_hotplug:"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define INSTALL_NOTIFY_HANDLER 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define UNINSTALL_NOTIFY_HANDLER 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static acpi_status xen_acpi_cpu_hotadd(struct acpi_processor *pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* --------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) Driver Interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) -------------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static int xen_acpi_processor_enable(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) acpi_status status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) unsigned long long value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) union acpi_object object = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct acpi_processor *pr = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (!strcmp(acpi_device_hid(device), ACPI_PROCESSOR_OBJECT_HID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* Declared with "Processor" statement; match ProcessorID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) status = acpi_evaluate_object(pr->handle, NULL, NULL, &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) pr_err(PREFIX "Evaluating processor object\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) pr->acpi_id = object.processor.proc_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* Declared with "Device" statement; match _UID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) status = acpi_evaluate_integer(pr->handle, METHOD_NAME__UID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) NULL, &value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) pr_err(PREFIX "Evaluating processor _UID\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) pr->acpi_id = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) pr->id = xen_pcpu_id(pr->acpi_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (invalid_logical_cpuid(pr->id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* This cpu is not presented at hypervisor, try to hotadd it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (ACPI_FAILURE(xen_acpi_cpu_hotadd(pr))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) pr_err(PREFIX "Hotadd CPU (acpi_id = %d) failed.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) pr->acpi_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static int xen_acpi_processor_add(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct acpi_processor *pr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (!device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) pr = kzalloc(sizeof(struct acpi_processor), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (!pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) pr->handle = device->handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) strcpy(acpi_device_name(device), ACPI_PROCESSOR_DEVICE_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) strcpy(acpi_device_class(device), ACPI_PROCESSOR_CLASS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) device->driver_data = pr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ret = xen_acpi_processor_enable(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) pr_err(PREFIX "Error when enabling Xen processor\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static int xen_acpi_processor_remove(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct acpi_processor *pr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (!device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) pr = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (!pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) kfree(pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /*--------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) Acpi processor hotplug support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) --------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static int is_processor_present(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) unsigned long long sta = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) status = acpi_evaluate_integer(handle, "_STA", NULL, &sta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_PRESENT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * _STA is mandatory for a processor that supports hot plug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (status == AE_NOT_FOUND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) pr_info(PREFIX "Processor does not support hot plug\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) pr_info(PREFIX "Processor Device is not present");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static int xen_apic_id(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct acpi_madt_local_apic *lapic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int apic_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) if (!buffer.length || !buffer.pointer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) obj = buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (obj->type != ACPI_TYPE_BUFFER ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) obj->buffer.length < sizeof(*lapic)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) kfree(buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) lapic = (struct acpi_madt_local_apic *)obj->buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (lapic->header.type != ACPI_MADT_TYPE_LOCAL_APIC ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) !(lapic->lapic_flags & ACPI_MADT_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) kfree(buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) apic_id = (uint32_t)lapic->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) kfree(buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) buffer.length = ACPI_ALLOCATE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) buffer.pointer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return apic_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static int xen_hotadd_cpu(struct acpi_processor *pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) int cpu_id, apic_id, pxm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct xen_platform_op op;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) apic_id = xen_apic_id(pr->handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (apic_id < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) pr_err(PREFIX "Failed to get apic_id for acpi_id %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) pr->acpi_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) pxm = xen_acpi_get_pxm(pr->handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (pxm < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) pr_err(PREFIX "Failed to get _PXM for acpi_id %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) pr->acpi_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return pxm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) op.cmd = XENPF_cpu_hotadd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) op.u.cpu_add.apic_id = apic_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) op.u.cpu_add.acpi_id = pr->acpi_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) op.u.cpu_add.pxm = pxm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) cpu_id = HYPERVISOR_platform_op(&op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (cpu_id < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) pr_err(PREFIX "Failed to hotadd CPU for acpi_id %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) pr->acpi_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) return cpu_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static acpi_status xen_acpi_cpu_hotadd(struct acpi_processor *pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (!is_processor_present(pr->handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return AE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) pr->id = xen_hotadd_cpu(pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (invalid_logical_cpuid(pr->id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return AE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * Sync with Xen hypervisor, providing new /sys/.../xen_cpuX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * interface after cpu hotadded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) xen_pcpu_hotplug_sync();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static int acpi_processor_device_remove(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) pr_debug(PREFIX "Xen does not support CPU hotremove\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static void acpi_processor_hotplug_notify(acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) u32 event, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct acpi_processor *pr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct acpi_device *device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; /* default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) acpi_scan_lock_acquire();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) case ACPI_NOTIFY_BUS_CHECK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) case ACPI_NOTIFY_DEVICE_CHECK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) ACPI_DEBUG_PRINT((ACPI_DB_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) "Processor driver received %s event\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) (event == ACPI_NOTIFY_BUS_CHECK) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) "ACPI_NOTIFY_BUS_CHECK" : "ACPI_NOTIFY_DEVICE_CHECK"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (!is_processor_present(handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) acpi_bus_get_device(handle, &device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (acpi_device_enumerated(device))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) result = acpi_bus_scan(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) pr_err(PREFIX "Unable to add the device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) device = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) acpi_bus_get_device(handle, &device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (!acpi_device_enumerated(device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) pr_err(PREFIX "Missing device object\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) ost_code = ACPI_OST_SC_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) case ACPI_NOTIFY_EJECT_REQUEST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) ACPI_DEBUG_PRINT((ACPI_DB_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) "received ACPI_NOTIFY_EJECT_REQUEST\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (acpi_bus_get_device(handle, &device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) pr_err(PREFIX "Device don't exist, dropping EJECT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) pr = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (!pr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) pr_err(PREFIX "Driver data is NULL, dropping EJECT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * TBD: implement acpi_processor_device_remove if Xen support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * CPU hotremove in the future.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) acpi_processor_device_remove(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ACPI_DEBUG_PRINT((ACPI_DB_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) "Unsupported event [0x%x]\n", event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /* non-hotplug event; possibly handled by other handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) (void) acpi_evaluate_ost(handle, event, ost_code, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) acpi_scan_lock_release();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static acpi_status is_processor_device(acpi_handle handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct acpi_device_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) char *hid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) status = acpi_get_object_info(handle, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (info->type == ACPI_TYPE_PROCESSOR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return AE_OK; /* found a processor object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (!(info->valid & ACPI_VALID_HID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) return AE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) hid = info->hardware_id.string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if ((hid == NULL) || strcmp(hid, ACPI_PROCESSOR_DEVICE_HID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return AE_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return AE_OK; /* found a processor device object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) static acpi_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) processor_walk_namespace_cb(acpi_handle handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) u32 lvl, void *context, void **rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) int *action = context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) status = is_processor_device(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return AE_OK; /* not a processor; continue to walk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) switch (*action) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) case INSTALL_NOTIFY_HANDLER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) acpi_install_notify_handler(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) ACPI_SYSTEM_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) acpi_processor_hotplug_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) case UNINSTALL_NOTIFY_HANDLER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) acpi_remove_notify_handler(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) ACPI_SYSTEM_NOTIFY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) acpi_processor_hotplug_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) /* found a processor; skip walking underneath */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return AE_CTRL_DEPTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) void acpi_processor_install_hotplug_notify(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) int action = INSTALL_NOTIFY_HANDLER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) acpi_walk_namespace(ACPI_TYPE_ANY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) ACPI_ROOT_OBJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) ACPI_UINT32_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) processor_walk_namespace_cb, NULL, &action, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) void acpi_processor_uninstall_hotplug_notify(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) int action = UNINSTALL_NOTIFY_HANDLER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) acpi_walk_namespace(ACPI_TYPE_ANY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) ACPI_ROOT_OBJECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) ACPI_UINT32_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) processor_walk_namespace_cb, NULL, &action, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static const struct acpi_device_id processor_device_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {ACPI_PROCESSOR_OBJECT_HID, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {ACPI_PROCESSOR_DEVICE_HID, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) {"", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) MODULE_DEVICE_TABLE(acpi, processor_device_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static struct acpi_driver xen_acpi_processor_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) .name = "processor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) .class = ACPI_PROCESSOR_CLASS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) .ids = processor_device_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) .ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) .add = xen_acpi_processor_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) .remove = xen_acpi_processor_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static int __init xen_acpi_processor_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (!xen_initial_domain())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /* unregister the stub which only used to reserve driver space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) xen_stub_processor_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) result = acpi_bus_register_driver(&xen_acpi_processor_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (result < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) xen_stub_processor_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) acpi_processor_install_hotplug_notify();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static void __exit xen_acpi_processor_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (!xen_initial_domain())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) acpi_processor_uninstall_hotplug_notify();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) acpi_bus_unregister_driver(&xen_acpi_processor_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) * stub reserve space again to prevent any chance of native
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * driver loading.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) xen_stub_processor_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) module_init(xen_acpi_processor_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) module_exit(xen_acpi_processor_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) ACPI_MODULE_NAME("xen-acpi-cpuhotplug");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) MODULE_AUTHOR("Liu Jinsong <jinsong.liu@intel.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) MODULE_DESCRIPTION("Xen Hotplug CPU Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) MODULE_LICENSE("GPL");