summaryrefslogtreecommitdiff
path: root/drivers/acpi
diff options
context:
space:
mode:
authorMark Brown <broonie@kernel.org>2026-10-01 14:23:33 +0100
committerMark Brown <broonie@kernel.org>2026-10-01 14:23:33 +0100
commite273534c5e5f259fb43cda0228ce56b45ac0c93f (patch)
tree64509f18eed07ad7bcc0766a9d01dadf747a5b52 /drivers/acpi
parentcaab1372065c106f4baf18d11863e498a88a8940 (diff)
parent114920a3e82922869f8c27916e852b4ba0d560c4 (diff)
downloadlinux-next-e273534c5e5f259fb43cda0228ce56b45ac0c93f.tar.gz
linux-next-e273534c5e5f259fb43cda0228ce56b45ac0c93f.zip
Merge branch 'linux-next' of https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git
Diffstat (limited to 'drivers/acpi')
-rw-r--r--drivers/acpi/acpi_extlog.c64
-rw-r--r--drivers/acpi/acpi_mrrm.c14
-rw-r--r--drivers/acpi/acpi_pcc.c55
-rw-r--r--drivers/acpi/acpi_video.c43
-rw-r--r--drivers/acpi/acpica/dsfield.c3
-rw-r--r--drivers/acpi/acpica/exfield.c11
-rw-r--r--drivers/acpi/apei/ghes.c92
-rw-r--r--drivers/acpi/apei/ghes_helpers.c18
-rw-r--r--drivers/acpi/arm64/amba.c3
-rw-r--r--drivers/acpi/battery.c131
-rw-r--r--drivers/acpi/bus.c8
-rw-r--r--drivers/acpi/button.c12
-rw-r--r--drivers/acpi/cppc_acpi.c2209
-rw-r--r--drivers/acpi/device_pm.c77
-rw-r--r--drivers/acpi/fan.h2
-rw-r--r--drivers/acpi/fan_core.c147
-rw-r--r--drivers/acpi/fan_hwmon.c2
-rw-r--r--drivers/acpi/glue.c145
-rw-r--r--drivers/acpi/internal.h1
-rw-r--r--drivers/acpi/numa/hmat.c2
-rw-r--r--drivers/acpi/numa/srat.c2
-rw-r--r--drivers/acpi/osl.c2
-rw-r--r--drivers/acpi/pfr_update.c2
-rw-r--r--drivers/acpi/power.c13
-rw-r--r--drivers/acpi/processor_driver.c6
-rw-r--r--drivers/acpi/processor_thermal.c80
-rw-r--r--drivers/acpi/riscv/cppc.c26
-rw-r--r--drivers/acpi/sbs.c8
-rw-r--r--drivers/acpi/scan.c54
-rw-r--r--drivers/acpi/sysfs.c5
-rw-r--r--drivers/acpi/tables.c3
-rw-r--r--drivers/acpi/thermal.c19
-rw-r--r--drivers/acpi/utils.c13
-rw-r--r--drivers/acpi/video_detect.c8
-rw-r--r--drivers/acpi/x86/s2idle.c29
35 files changed, 2536 insertions, 773 deletions
diff --git a/drivers/acpi/acpi_extlog.c b/drivers/acpi/acpi_extlog.c
index 7ad3b36013cc..9e61354a807b 100644
--- a/drivers/acpi/acpi_extlog.c
+++ b/drivers/acpi/acpi_extlog.c
@@ -134,22 +134,42 @@ static int print_extlog_rcd(const char *pfx,
}
static void extlog_print_pcie(struct cper_sec_pcie *pcie_err,
- int severity)
+ int severity, u32 len)
{
-#ifdef ACPI_APEI_PCIEAER
- struct aer_capability_regs *aer;
+#ifdef CONFIG_ACPI_APEI_PCIEAER
+ struct aer_capability_regs aer_regs = {};
struct pci_dev *pdev;
unsigned int devfn;
unsigned int bus;
int aer_severity;
int domain;
+ if (len < sizeof(*pcie_err)) {
+ pr_warn_ratelimited(FW_WARN
+ "PCIe error section too small (%u)\n", len);
+ return;
+ }
+
if (!(pcie_err->validation_bits & CPER_PCIE_VALID_DEVICE_ID &&
pcie_err->validation_bits & CPER_PCIE_VALID_AER_INFO))
return;
aer_severity = cper_severity_to_aer(severity);
- aer = (struct aer_capability_regs *)pcie_err->aer_info;
+
+ /*
+ * struct pcie_tlp_log is larger than the hardware layout, so aer_info
+ * only maps onto the struct up to the four Header Log DWORDs. Copy that
+ * much, then place the TLP Prefix Log from where the hardware keeps it.
+ * Everything else stays zero: nothing reads root_command, root_status or
+ * the error source IDs, and header_len and flit are software-only.
+ */
+ memcpy(&aer_regs, pcie_err->aer_info,
+ offsetof(struct aer_capability_regs, header_log) +
+ PCIE_STD_NUM_TLP_HEADERLOG * sizeof(u32));
+ memcpy(aer_regs.header_log.prefix,
+ pcie_err->aer_info + PCI_ERR_PREFIX_LOG,
+ sizeof(aer_regs.header_log.prefix));
+
domain = pcie_err->device_id.segment;
bus = pcie_err->device_id.bus;
devfn = PCI_DEVFN(pcie_err->device_id.device,
@@ -158,28 +178,11 @@ static void extlog_print_pcie(struct cper_sec_pcie *pcie_err,
if (!pdev)
return;
- pci_print_aer(pdev, aer_severity, aer);
+ pci_print_aer(pdev, aer_severity, &aer_regs);
pci_dev_put(pdev);
#endif
}
-static void
-extlog_cxl_cper_handle_prot_err(struct cxl_cper_sec_prot_err *prot_err,
- int severity)
-{
-#ifdef ACPI_APEI_PCIEAER
- struct cxl_cper_prot_err_work_data wd;
-
- if (cxl_cper_sec_prot_err_valid(prot_err))
- return;
-
- if (cxl_cper_setup_prot_err_work_data(&wd, prot_err, severity))
- return;
-
- cxl_cper_handle_prot_err(&wd);
-#endif
-}
-
static int extlog_print(struct notifier_block *nb, unsigned long val,
void *data)
{
@@ -208,6 +211,15 @@ static int extlog_print(struct notifier_block *nb, unsigned long val,
tmp = (struct acpi_hest_generic_status *)elog_buf;
+ /*
+ * Bound the length before cper_estatus_check() walks the sections: it
+ * iterates over data_length, which is not yet known to fit elog_buf.
+ * cper_estatus_check_header() then rejects a length that wrapped, which
+ * the bound cannot see.
+ */
+ if (cper_estatus_len(tmp) > ELOG_ENTRY_LEN || cper_estatus_check(tmp))
+ return NOTIFY_DONE;
+
if (!ras_userspace_consumers()) {
print_extlog_rcd(NULL, tmp, cpu);
goto out;
@@ -235,12 +247,14 @@ static int extlog_print(struct notifier_block *nb, unsigned long val,
struct cxl_cper_sec_prot_err *prot_err =
acpi_hest_get_payload(gdata);
- extlog_cxl_cper_handle_prot_err(prot_err,
- gdata->error_severity);
+ cxl_cper_post_prot_err(prot_err,
+ gdata->error_severity,
+ gdata->error_data_length);
} else if (guid_equal(sec_type, &CPER_SEC_PCIE)) {
struct cper_sec_pcie *pcie_err = acpi_hest_get_payload(gdata);
- extlog_print_pcie(pcie_err, gdata->error_severity);
+ extlog_print_pcie(pcie_err, gdata->error_severity,
+ gdata->error_data_length);
} else {
void *err = acpi_hest_get_payload(gdata);
diff --git a/drivers/acpi/acpi_mrrm.c b/drivers/acpi/acpi_mrrm.c
index e99cbda83452..83934e2aa0d4 100644
--- a/drivers/acpi/acpi_mrrm.c
+++ b/drivers/acpi/acpi_mrrm.c
@@ -36,17 +36,11 @@ static u32 mrrm_mem_entry_num;
static int get_node_num(struct mrrm_mem_range_entry *e)
{
- unsigned int nid;
+ struct zone *zone;
- for_each_online_node(nid) {
- for (int z = 0; z < MAX_NR_ZONES; z++) {
- struct zone *zone = NODE_DATA(nid)->node_zones + z;
-
- if (!populated_zone(zone))
- continue;
- if (zone_intersects(zone, PHYS_PFN(e->base), PHYS_PFN(e->length)))
- return zone_to_nid(zone);
- }
+ for_each_populated_zone(zone) {
+ if (zone_intersects(zone, PHYS_PFN(e->base), PHYS_PFN(e->length)))
+ return zone_to_nid(zone);
}
return -ENOENT;
diff --git a/drivers/acpi/acpi_pcc.c b/drivers/acpi/acpi_pcc.c
index 438c67189511..345f233d77cd 100644
--- a/drivers/acpi/acpi_pcc.c
+++ b/drivers/acpi/acpi_pcc.c
@@ -28,6 +28,7 @@
* to PCC commands
*/
#define PCC_CMD_WAIT_RETRIES_NUM 500ULL
+#define PCC_SIGNATURE_SIZE sizeof(u32)
struct pcc_data {
struct pcc_mbox_chan *pcc_chan;
@@ -49,10 +50,24 @@ static acpi_status
acpi_pcc_address_space_setup(acpi_handle region_handle, u32 function,
void *handler_context, void **region_context)
{
- struct pcc_data *data;
struct acpi_pcc_info *ctx = handler_context;
struct pcc_mbox_chan *pcc_chan;
+ struct pcc_data *data;
acpi_status ret;
+ u64 usecs_lat;
+
+ if (function == ACPI_REGION_DEACTIVATE) {
+ data = *region_context;
+ if (data) {
+ pcc_mbox_free_channel(data->pcc_chan);
+ kfree(data);
+ *region_context = NULL;
+ }
+ return AE_OK;
+ }
+
+ if (function != ACPI_REGION_ACTIVATE)
+ return AE_BAD_PARAMETER;
data = kzalloc_obj(*data);
if (!data)
@@ -74,6 +89,14 @@ acpi_pcc_address_space_setup(acpi_handle region_handle, u32 function,
}
pcc_chan = data->pcc_chan;
+ if (pcc_chan->shmem_size < PCC_SIGNATURE_SIZE ||
+ ctx->length > pcc_chan->shmem_size - PCC_SIGNATURE_SIZE) {
+ pr_err("PCC channel-%d shared memory is too small.\n",
+ ctx->subspace_id);
+ ret = AE_AML_REGION_LIMIT;
+ goto err_free_channel;
+ }
+
if (!pcc_chan->mchan->mbox->txdone_irq) {
pr_err("This channel-%d does not support interrupt.\n",
ctx->subspace_id);
@@ -81,6 +104,16 @@ acpi_pcc_address_space_setup(acpi_handle region_handle, u32 function,
goto err_free_channel;
}
+ /*
+ * pcc_chan->latency is just a Nominal value. In reality the remote
+ * processor could be much slower to reply. So add an arbitrary
+ * amount of wait on top of Nominal.
+ */
+ usecs_lat = PCC_CMD_WAIT_RETRIES_NUM * pcc_chan->latency;
+ data->cl.tx_tout = DIV_ROUND_UP_ULL(usecs_lat, 1000);
+ if (!data->cl.tx_tout)
+ data->cl.tx_tout = 1;
+
*region_context = data;
return AE_OK;
@@ -97,27 +130,23 @@ acpi_pcc_address_space_handler(u32 function, acpi_physical_address addr,
u32 bits, acpi_integer *value,
void *handler_context, void *region_context)
{
- int ret;
struct pcc_data *data = region_context;
- u64 usecs_lat;
+ void __iomem *pcc_opregion;
+ int ret;
+
+ pcc_opregion = data->pcc_chan->shmem + PCC_SIGNATURE_SIZE;
reinit_completion(&data->done);
- /* Write to Shared Memory */
- memcpy_toio(data->pcc_chan->shmem, (void *)value, data->ctx.length);
+ /* Write to the PCC OperationRegion after the shared memory signature. */
+ memcpy_toio(pcc_opregion, (void *)value, data->ctx.length);
ret = mbox_send_message(data->pcc_chan->mchan, NULL);
if (ret < 0)
return AE_ERROR;
- /*
- * pcc_chan->latency is just a Nominal value. In reality the remote
- * processor could be much slower to reply. So add an arbitrary
- * amount of wait on top of Nominal.
- */
- usecs_lat = PCC_CMD_WAIT_RETRIES_NUM * data->pcc_chan->latency;
ret = wait_for_completion_timeout(&data->done,
- usecs_to_jiffies(usecs_lat));
+ msecs_to_jiffies(data->cl.tx_tout));
if (ret == 0) {
pr_err("PCC command executed timeout!\n");
return AE_TIME;
@@ -125,7 +154,7 @@ acpi_pcc_address_space_handler(u32 function, acpi_physical_address addr,
mbox_chan_txdone(data->pcc_chan->mchan, ret);
- memcpy_fromio(value, data->pcc_chan->shmem, data->ctx.length);
+ memcpy_fromio(value, pcc_opregion, data->ctx.length);
return AE_OK;
}
diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index 4d6fd9f6e9ad..2a2822516665 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -1700,9 +1700,9 @@ static int acpi_video_resume(struct notifier_block *nb,
static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
{
+ struct device *phys_dev, *parent = NULL;
struct backlight_properties props;
struct pci_dev *pdev;
- struct device *parent = NULL;
int result;
static int count;
char *name;
@@ -1729,11 +1729,10 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
device,
&acpi_backlight_ops,
&props);
- put_device(parent);
kfree(name);
if (IS_ERR(device->backlight)) {
device->backlight = NULL;
- return;
+ goto put_parent;
}
/*
@@ -1743,8 +1742,12 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
device->backlight->props.brightness =
acpi_video_get_brightness(device->backlight);
- device->cooling_dev = thermal_cooling_device_register("LCD", device,
- &video_cooling_ops);
+ phys_dev = acpi_bus_get_primary_device(device->dev);
+ if (!phys_dev)
+ phys_dev = get_device(parent);
+
+ device->cooling_dev = thermal_cooling_device_create(phys_dev, "LCD", device,
+ &video_cooling_ops);
if (IS_ERR(device->cooling_dev)) {
/*
* Set cooling_dev to NULL so we don't crash trying to free it.
@@ -1753,21 +1756,17 @@ static void acpi_video_dev_register_backlight(struct acpi_video_device *device)
* -- dtor
*/
device->cooling_dev = NULL;
- return;
+ goto put_phys_dev;
}
- dev_info(&device->dev->dev, "registered as cooling_device%d\n",
- device->cooling_dev->id);
- result = sysfs_create_link(&device->dev->dev.kobj,
- &device->cooling_dev->device.kobj,
- "thermal_cooling");
- if (result)
- pr_info("sysfs link creation failed\n");
+ dev_info(&device->cooling_dev->device, "Using ACPI device %s\n",
+ acpi_dev_name(device->dev));
- result = sysfs_create_link(&device->cooling_dev->device.kobj,
- &device->dev->dev.kobj, "device");
- if (result)
- pr_info("Reverse sysfs link creation failed\n");
+put_phys_dev:
+ put_device(phys_dev);
+
+put_parent:
+ put_device(parent);
}
static void acpi_video_run_bcl_for_osi(struct acpi_video_bus *video)
@@ -1825,6 +1824,10 @@ static int acpi_video_bus_register_backlight(struct acpi_video_bus *video)
static void acpi_video_dev_unregister_backlight(struct acpi_video_device *device)
{
+ if (device->cooling_dev) {
+ thermal_cooling_device_unregister(device->cooling_dev);
+ device->cooling_dev = NULL;
+ }
if (device->backlight) {
backlight_device_unregister(device->backlight);
device->backlight = NULL;
@@ -1834,12 +1837,6 @@ static void acpi_video_dev_unregister_backlight(struct acpi_video_device *device
kfree(device->brightness);
device->brightness = NULL;
}
- if (device->cooling_dev) {
- sysfs_remove_link(&device->dev->dev.kobj, "thermal_cooling");
- sysfs_remove_link(&device->cooling_dev->device.kobj, "device");
- thermal_cooling_device_unregister(device->cooling_dev);
- device->cooling_dev = NULL;
- }
}
static int acpi_video_bus_unregister_backlight(struct acpi_video_bus *video)
diff --git a/drivers/acpi/acpica/dsfield.c b/drivers/acpi/acpica/dsfield.c
index d7d56cc600d3..f7e503bf57c8 100644
--- a/drivers/acpi/acpica/dsfield.c
+++ b/drivers/acpi/acpica/dsfield.c
@@ -522,7 +522,8 @@ acpi_ds_create_field(union acpi_parse_object *op,
}
if (info.region_node->object->region.space_id ==
- ACPI_ADR_SPACE_PLATFORM_COMM) {
+ ACPI_ADR_SPACE_PLATFORM_COMM &&
+ !region_node->object->field.internal_pcc_buffer) {
region_node->object->field.internal_pcc_buffer =
ACPI_ALLOCATE_ZEROED(info.region_node->object->region.
length);
diff --git a/drivers/acpi/acpica/exfield.c b/drivers/acpi/acpica/exfield.c
index 9a55524ed8f4..50317fe0cbd5 100644
--- a/drivers/acpi/acpica/exfield.c
+++ b/drivers/acpi/acpica/exfield.c
@@ -45,12 +45,13 @@ static const u8 acpi_protocol_lengths[] = {
/*
* The following macros determine a given offset is a COMD field.
- * According to the specification, generic subspaces (types 0-2) contains a
- * 2-byte COMD field at offset 4 and master subspaces (type 3) contains a 4-byte
- * COMD field starting at offset 12.
+ * According to the specification, the PCC OperationRegion begins after
+ * the PCC signature. The raw shared memory COMD offsets of 4 for generic
+ * subspaces (types 0-2) and 12 for master subspaces (type 3) therefore
+ * appear at OperationRegion offsets 0 and 8.
*/
-#define GENERIC_SUBSPACE_COMMAND(a) (4 == a || a == 5)
-#define MASTER_SUBSPACE_COMMAND(a) (12 <= a && a <= 15)
+#define GENERIC_SUBSPACE_COMMAND(a) (0 == a || a == 1)
+#define MASTER_SUBSPACE_COMMAND(a) (8 <= a && a <= 11)
/*******************************************************************************
*
diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
index fe10ab0e02f6..08c985e729d6 100644
--- a/drivers/acpi/apei/ghes.c
+++ b/drivers/acpi/apei/ghes.c
@@ -642,11 +642,14 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata)
#ifdef CONFIG_ACPI_APEI_PCIEAER
struct cper_sec_pcie *pcie_err = acpi_hest_get_payload(gdata);
+ if (gdata->error_data_length < sizeof(*pcie_err))
+ return;
+
if (pcie_err->validation_bits & CPER_PCIE_VALID_DEVICE_ID &&
pcie_err->validation_bits & CPER_PCIE_VALID_AER_INFO) {
+ struct aer_capability_regs *aer_info;
unsigned int devfn;
int aer_severity;
- u8 *aer_info;
devfn = PCI_DEVFN(pcie_err->device_id.device,
pcie_err->device_id.function);
@@ -664,13 +667,25 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata)
sizeof(struct aer_capability_regs));
if (!aer_info)
return;
- memcpy(aer_info, pcie_err->aer_info, sizeof(struct aer_capability_regs));
+
+ /*
+ * Map aer_info onto the struct as extlog_print_pcie() does:
+ * copy up to the four Header Log DWORDs, then place the TLP
+ * Prefix Log from where the hardware keeps it. The rest stays
+ * zero, so firmware cannot drive the pcie_print_tlp_log() loop
+ * over dw[] out of bounds.
+ */
+ memset(aer_info, 0, sizeof(struct aer_capability_regs));
+ memcpy(aer_info, pcie_err->aer_info,
+ offsetof(struct aer_capability_regs, header_log) +
+ PCIE_STD_NUM_TLP_HEADERLOG * sizeof(u32));
+ memcpy(aer_info->header_log.prefix,
+ pcie_err->aer_info + PCI_ERR_PREFIX_LOG,
+ sizeof(aer_info->header_log.prefix));
aer_recover_queue(pcie_err->device_id.segment,
pcie_err->device_id.bus,
- devfn, aer_severity,
- (struct aer_capability_regs *)
- aer_info);
+ devfn, aer_severity, aer_info);
}
#endif
}
@@ -752,13 +767,13 @@ static DEFINE_KFIFO(cxl_cper_prot_err_fifo, struct cxl_cper_prot_err_work_data,
static DEFINE_RAW_SPINLOCK(cxl_cper_prot_err_work_lock);
struct work_struct *cxl_cper_prot_err_work;
-static void cxl_cper_post_prot_err(struct cxl_cper_sec_prot_err *prot_err,
- int severity)
+void cxl_cper_post_prot_err(struct cxl_cper_sec_prot_err *prot_err,
+ int severity, u32 len)
{
#ifdef CONFIG_ACPI_APEI_PCIEAER
struct cxl_cper_prot_err_work_data wd;
- if (cxl_cper_sec_prot_err_valid(prot_err))
+ if (cxl_cper_sec_prot_err_valid(prot_err, len))
return;
guard(raw_spinlock_irqsave)(&cxl_cper_prot_err_work_lock);
@@ -777,6 +792,7 @@ static void cxl_cper_post_prot_err(struct cxl_cper_sec_prot_err *prot_err,
schedule_work(cxl_cper_prot_err_work);
#endif
}
+EXPORT_SYMBOL_FOR_MODULES(cxl_cper_post_prot_err, "acpi_extlog");
void cxl_cper_register_prot_err_work(struct work_struct *work)
{
@@ -823,10 +839,15 @@ static DEFINE_RAW_SPINLOCK(cxl_cper_work_lock);
struct work_struct *cxl_cper_work;
static void cxl_cper_post_event(enum cxl_event_type event_type,
- struct cxl_cper_event_rec *rec)
+ struct cxl_cper_event_rec *rec, u32 len)
{
struct cxl_cper_work_data wd;
+ if (len < sizeof(*rec)) {
+ pr_err(FW_WARN "CXL CPER section too small (%u)\n", len);
+ return;
+ }
+
if (rec->hdr.length <= sizeof(rec->hdr) ||
rec->hdr.length > sizeof(*rec)) {
pr_err(FW_WARN "CXL CPER Invalid section length (%u)\n",
@@ -923,6 +944,28 @@ static void ghes_log_hwerr(int sev, guid_t *sec_type)
hwerr_log_error_type(HWERR_RECOV_OTHERS);
}
+/*
+ * The fields from "extended" on are absent from the 73-byte UEFI 2.1/2.2
+ * layout that older firmware still emits. Return the length needed for the
+ * fields the validation bits claim, so over-claiming is rejected without
+ * rejecting an honest short record.
+ */
+static u32 ghes_mem_err_min_len(u64 validation_bits)
+{
+ u32 len = sizeof(struct cper_sec_mem_err_old);
+
+ if (validation_bits & (CPER_MEM_VALID_ROW_EXT | CPER_MEM_VALID_CHIP_ID))
+ len = offsetof(struct cper_sec_mem_err, rank);
+ if (validation_bits & CPER_MEM_VALID_RANK_NUMBER)
+ len = offsetof(struct cper_sec_mem_err, mem_array_handle);
+ if (validation_bits & CPER_MEM_VALID_CARD_HANDLE)
+ len = offsetof(struct cper_sec_mem_err, mem_dev_handle);
+ if (validation_bits & CPER_MEM_VALID_MODULE_HANDLE)
+ len = sizeof(struct cper_sec_mem_err);
+
+ return len;
+}
+
static void ghes_do_proc(struct ghes *ghes,
const struct acpi_hest_generic_status *estatus)
{
@@ -948,6 +991,25 @@ static void ghes_do_proc(struct ghes *ghes,
if (guid_equal(sec_type, &CPER_SEC_PLATFORM_MEM)) {
struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata);
+ /*
+ * Check once for all three consumers below. The 73-byte
+ * UEFI 2.1/2.2 layout is the floor, matching
+ * cper_estatus_print_section() and making
+ * validation_bits safe to read.
+ */
+ if (gdata->error_data_length <
+ sizeof(struct cper_sec_mem_err_old))
+ continue;
+
+ /* Then require what the claimed fields actually need. */
+ if (gdata->error_data_length <
+ ghes_mem_err_min_len(mem_err->validation_bits)) {
+ pr_warn_ratelimited(FW_WARN GHES_PFX
+ "memory error section too small (%u) for the fields it claims\n",
+ gdata->error_data_length);
+ continue;
+ }
+
atomic_notifier_call_chain(&ghes_report_chain, sev, mem_err);
arch_apei_report_mem_error(sev, mem_err);
@@ -959,19 +1021,23 @@ static void ghes_do_proc(struct ghes *ghes,
} else if (guid_equal(sec_type, &CPER_SEC_CXL_PROT_ERR)) {
struct cxl_cper_sec_prot_err *prot_err = acpi_hest_get_payload(gdata);
- cxl_cper_post_prot_err(prot_err, gdata->error_severity);
+ cxl_cper_post_prot_err(prot_err, gdata->error_severity,
+ gdata->error_data_length);
} else if (guid_equal(sec_type, &CPER_SEC_CXL_GEN_MEDIA_GUID)) {
struct cxl_cper_event_rec *rec = acpi_hest_get_payload(gdata);
- cxl_cper_post_event(CXL_CPER_EVENT_GEN_MEDIA, rec);
+ cxl_cper_post_event(CXL_CPER_EVENT_GEN_MEDIA, rec,
+ gdata->error_data_length);
} else if (guid_equal(sec_type, &CPER_SEC_CXL_DRAM_GUID)) {
struct cxl_cper_event_rec *rec = acpi_hest_get_payload(gdata);
- cxl_cper_post_event(CXL_CPER_EVENT_DRAM, rec);
+ cxl_cper_post_event(CXL_CPER_EVENT_DRAM, rec,
+ gdata->error_data_length);
} else if (guid_equal(sec_type, &CPER_SEC_CXL_MEM_MODULE_GUID)) {
struct cxl_cper_event_rec *rec = acpi_hest_get_payload(gdata);
- cxl_cper_post_event(CXL_CPER_EVENT_MEM_MODULE, rec);
+ cxl_cper_post_event(CXL_CPER_EVENT_MEM_MODULE, rec,
+ gdata->error_data_length);
} else {
void *err = acpi_hest_get_payload(gdata);
diff --git a/drivers/acpi/apei/ghes_helpers.c b/drivers/acpi/apei/ghes_helpers.c
index bc7111b740af..df41b993f413 100644
--- a/drivers/acpi/apei/ghes_helpers.c
+++ b/drivers/acpi/apei/ghes_helpers.c
@@ -5,8 +5,15 @@
#include <linux/aer.h>
#include <cxl/event.h>
-int cxl_cper_sec_prot_err_valid(struct cxl_cper_sec_prot_err *prot_err)
+int cxl_cper_sec_prot_err_valid(struct cxl_cper_sec_prot_err *prot_err, u32 len)
{
+ if (len < sizeof(*prot_err)) {
+ pr_err_ratelimited(FW_WARN
+ "CXL CPER prot err section too small (%u)\n",
+ len);
+ return -EINVAL;
+ }
+
if (!(prot_err->valid_bits & PROT_ERR_VALID_AGENT_ADDRESS)) {
pr_err_ratelimited("CXL CPER invalid agent type\n");
return -EINVAL;
@@ -23,6 +30,15 @@ int cxl_cper_sec_prot_err_valid(struct cxl_cper_sec_prot_err *prot_err)
return -EINVAL;
}
+ /* The RAS Capability block sits after a firmware-sized DVSEC. */
+ if (sizeof(*prot_err) + prot_err->dvsec_len +
+ sizeof(struct cxl_ras_capability_regs) > len) {
+ pr_err_ratelimited(FW_WARN
+ "CXL CPER prot err DVSEC (%u) overruns section (%u)\n",
+ prot_err->dvsec_len, len);
+ return -EINVAL;
+ }
+
if ((prot_err->agent_type == RCD || prot_err->agent_type == DEVICE ||
prot_err->agent_type == LD || prot_err->agent_type == FMLD) &&
!(prot_err->valid_bits & PROT_ERR_VALID_SERIAL_NUMBER))
diff --git a/drivers/acpi/arm64/amba.c b/drivers/acpi/arm64/amba.c
index 1350083bce5f..7ee431d9464a 100644
--- a/drivers/acpi/arm64/amba.c
+++ b/drivers/acpi/arm64/amba.c
@@ -87,11 +87,12 @@ static int amba_handler_attach(struct acpi_device *adev,
* the amba device we are about to create.
*/
if (parent)
- dev->dev.parent = acpi_get_first_physical_node(parent);
+ dev->dev.parent = acpi_bus_get_primary_device(parent);
device_set_node(&dev->dev, acpi_fwnode_handle(adev));
ret = amba_device_add(dev, &iomem_resource);
+ put_device(dev->dev.parent);
if (ret) {
dev_err(&adev->dev, "%s(): amba_device_add() failed (%d)\n",
__func__, ret);
diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c
index 670853ec3a4d..8599949f8786 100644
--- a/drivers/acpi/battery.c
+++ b/drivers/acpi/battery.c
@@ -341,7 +341,9 @@ static int acpi_battery_get_property(struct power_supply *psy,
return ret;
}
-static const enum power_supply_property charge_battery_props[] = {
+/* For devices supporting the _BIX ACPI control method */
+
+static const enum power_supply_property charge_battery_extended_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_TECHNOLOGY,
@@ -359,7 +361,7 @@ static const enum power_supply_property charge_battery_props[] = {
POWER_SUPPLY_PROP_SERIAL_NUMBER,
};
-static const enum power_supply_property charge_battery_full_cap_broken_props[] = {
+static const enum power_supply_property charge_battery_full_cap_broken_extended_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_TECHNOLOGY,
@@ -373,7 +375,7 @@ static const enum power_supply_property charge_battery_full_cap_broken_props[] =
POWER_SUPPLY_PROP_SERIAL_NUMBER,
};
-static const enum power_supply_property energy_battery_props[] = {
+static const enum power_supply_property energy_battery_extended_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_TECHNOLOGY,
@@ -391,7 +393,7 @@ static const enum power_supply_property energy_battery_props[] = {
POWER_SUPPLY_PROP_SERIAL_NUMBER,
};
-static const enum power_supply_property energy_battery_full_cap_broken_props[] = {
+static const enum power_supply_property energy_battery_full_cap_broken_extended_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_TECHNOLOGY,
@@ -405,6 +407,68 @@ static const enum power_supply_property energy_battery_full_cap_broken_props[] =
POWER_SUPPLY_PROP_SERIAL_NUMBER,
};
+/* For devices supporting only the _BIF ACPI control method */
+
+static const enum power_supply_property charge_battery_props[] = {
+ POWER_SUPPLY_PROP_STATUS,
+ POWER_SUPPLY_PROP_PRESENT,
+ POWER_SUPPLY_PROP_TECHNOLOGY,
+ POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
+ POWER_SUPPLY_PROP_VOLTAGE_NOW,
+ POWER_SUPPLY_PROP_CURRENT_NOW,
+ POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
+ POWER_SUPPLY_PROP_CHARGE_FULL,
+ POWER_SUPPLY_PROP_CHARGE_NOW,
+ POWER_SUPPLY_PROP_CAPACITY,
+ POWER_SUPPLY_PROP_CAPACITY_LEVEL,
+ POWER_SUPPLY_PROP_MODEL_NAME,
+ POWER_SUPPLY_PROP_MANUFACTURER,
+ POWER_SUPPLY_PROP_SERIAL_NUMBER,
+};
+
+static const enum power_supply_property charge_battery_full_cap_broken_props[] = {
+ POWER_SUPPLY_PROP_STATUS,
+ POWER_SUPPLY_PROP_PRESENT,
+ POWER_SUPPLY_PROP_TECHNOLOGY,
+ POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
+ POWER_SUPPLY_PROP_VOLTAGE_NOW,
+ POWER_SUPPLY_PROP_CURRENT_NOW,
+ POWER_SUPPLY_PROP_CHARGE_NOW,
+ POWER_SUPPLY_PROP_MODEL_NAME,
+ POWER_SUPPLY_PROP_MANUFACTURER,
+ POWER_SUPPLY_PROP_SERIAL_NUMBER,
+};
+
+static const enum power_supply_property energy_battery_props[] = {
+ POWER_SUPPLY_PROP_STATUS,
+ POWER_SUPPLY_PROP_PRESENT,
+ POWER_SUPPLY_PROP_TECHNOLOGY,
+ POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
+ POWER_SUPPLY_PROP_VOLTAGE_NOW,
+ POWER_SUPPLY_PROP_POWER_NOW,
+ POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
+ POWER_SUPPLY_PROP_ENERGY_FULL,
+ POWER_SUPPLY_PROP_ENERGY_NOW,
+ POWER_SUPPLY_PROP_CAPACITY,
+ POWER_SUPPLY_PROP_CAPACITY_LEVEL,
+ POWER_SUPPLY_PROP_MODEL_NAME,
+ POWER_SUPPLY_PROP_MANUFACTURER,
+ POWER_SUPPLY_PROP_SERIAL_NUMBER,
+};
+
+static const enum power_supply_property energy_battery_full_cap_broken_props[] = {
+ POWER_SUPPLY_PROP_STATUS,
+ POWER_SUPPLY_PROP_PRESENT,
+ POWER_SUPPLY_PROP_TECHNOLOGY,
+ POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
+ POWER_SUPPLY_PROP_VOLTAGE_NOW,
+ POWER_SUPPLY_PROP_POWER_NOW,
+ POWER_SUPPLY_PROP_ENERGY_NOW,
+ POWER_SUPPLY_PROP_MODEL_NAME,
+ POWER_SUPPLY_PROP_MANUFACTURER,
+ POWER_SUPPLY_PROP_SERIAL_NUMBER,
+};
+
/* Battery Management */
struct acpi_offsets {
size_t offset; /* offset inside struct acpi_sbs_battery */
@@ -904,6 +968,7 @@ static void __exit battery_hook_exit(void)
static int sysfs_add_battery(struct acpi_battery *battery)
{
+ bool extended_info_available = test_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags);
struct power_supply_config psy_cfg = {
.drv_data = battery,
.attr_grp = acpi_battery_groups,
@@ -922,25 +987,55 @@ static int sysfs_add_battery(struct acpi_battery *battery)
if (power_unit == ACPI_BATTERY_POWER_UNIT_MA) {
if (full_cap_broken) {
- battery->bat_desc.properties =
- charge_battery_full_cap_broken_props;
- battery->bat_desc.num_properties =
- ARRAY_SIZE(charge_battery_full_cap_broken_props);
+ if (extended_info_available) {
+ battery->bat_desc.properties =
+ charge_battery_full_cap_broken_extended_props;
+ battery->bat_desc.num_properties =
+ ARRAY_SIZE(charge_battery_full_cap_broken_extended_props);
+ } else {
+ battery->bat_desc.properties =
+ charge_battery_full_cap_broken_props;
+ battery->bat_desc.num_properties =
+ ARRAY_SIZE(charge_battery_full_cap_broken_props);
+ }
} else {
- battery->bat_desc.properties = charge_battery_props;
- battery->bat_desc.num_properties =
- ARRAY_SIZE(charge_battery_props);
+ if (extended_info_available) {
+ battery->bat_desc.properties =
+ charge_battery_extended_props;
+ battery->bat_desc.num_properties =
+ ARRAY_SIZE(charge_battery_extended_props);
+ } else {
+ battery->bat_desc.properties =
+ charge_battery_props;
+ battery->bat_desc.num_properties =
+ ARRAY_SIZE(charge_battery_props);
+ }
}
} else {
if (full_cap_broken) {
- battery->bat_desc.properties =
- energy_battery_full_cap_broken_props;
- battery->bat_desc.num_properties =
- ARRAY_SIZE(energy_battery_full_cap_broken_props);
+ if (extended_info_available) {
+ battery->bat_desc.properties =
+ energy_battery_full_cap_broken_extended_props;
+ battery->bat_desc.num_properties =
+ ARRAY_SIZE(energy_battery_full_cap_broken_extended_props);
+ } else {
+ battery->bat_desc.properties =
+ energy_battery_full_cap_broken_props;
+ battery->bat_desc.num_properties =
+ ARRAY_SIZE(energy_battery_full_cap_broken_props);
+ }
} else {
- battery->bat_desc.properties = energy_battery_props;
- battery->bat_desc.num_properties =
- ARRAY_SIZE(energy_battery_props);
+ if (extended_info_available) {
+ battery->bat_desc.properties =
+ energy_battery_extended_props;
+ battery->bat_desc.num_properties =
+ ARRAY_SIZE(energy_battery_extended_props);
+ } else {
+ battery->bat_desc.properties =
+ energy_battery_props;
+ battery->bat_desc.num_properties =
+ ARRAY_SIZE(energy_battery_props);
+ }
}
}
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 808c6746be14..48f0b4809f94 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -1120,11 +1120,6 @@ EXPORT_SYMBOL_GPL(acpi_driver_match_device);
ACPI Bus operations
-------------------------------------------------------------------------- */
-static int acpi_bus_match(struct device *dev, const struct device_driver *drv)
-{
- return 0;
-}
-
static int acpi_device_uevent(const struct device *dev, struct kobj_uevent_env *env)
{
return __acpi_device_uevent_modalias(to_acpi_device(dev), env);
@@ -1132,7 +1127,6 @@ static int acpi_device_uevent(const struct device *dev, struct kobj_uevent_env *
const struct bus_type acpi_bus_type = {
.name = "acpi",
- .match = acpi_bus_match,
.uevent = acpi_device_uevent,
};
@@ -1451,7 +1445,7 @@ static int __init acpi_bus_init(void)
*/
acpi_root_dir = proc_mkdir(ACPI_BUS_FILE_ROOT, NULL);
- result = bus_register(&acpi_bus_type);
+ result = companion_bus_register(&acpi_bus_type);
if (!result)
return 0;
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index cdbb1023a8ee..34c7173b5a6c 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -146,6 +146,18 @@ static const struct dmi_system_id dmi_lid_quirks[] = {
},
{
/*
+ * Razer Blade Stealth 13 early 2020, when the lid is opened
+ * while suspended the open notification is lost and _LID keeps
+ * returning closed after resume, causing spurious re-suspends.
+ */
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "Razer"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "Blade Stealth 13 (Early 2020) - RZ09-0310"),
+ },
+ .driver_data = (void *)(long)ACPI_BUTTON_LID_INIT_OPEN,
+ },
+ {
+ /*
* Samsung galaxybook2 ,initial _LID device notification returns
* lid closed.
*/
diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index fef54fcd00b7..80e2e6b32ce3 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -34,8 +34,12 @@
#define pr_fmt(fmt) "ACPI CPPC: " fmt
#include <linux/delay.h>
+#include <linux/interval_tree_generic.h>
#include <linux/iopoll.h>
#include <linux/ktime.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/rbtree.h>
#include <linux/rwsem.h>
#include <linux/wait.h>
#include <linux/topology.h>
@@ -70,6 +74,8 @@ struct cppc_pcc_data {
* Take write_lock for all purposes which gives exclusive access
*/
struct rw_semaphore pcc_lock;
+ /* Serialize byte-oriented accesses to aliased PCC payload fields. */
+ raw_spinlock_t payload_lock;
/* Wait queue for CPUs whose requests were batched */
wait_queue_head_t pcc_write_wait_q;
@@ -81,6 +87,7 @@ struct cppc_pcc_data {
/* Array to represent the PCC channel per subspace ID */
static struct cppc_pcc_data *pcc_data[MAX_PCC_SUBSPACES];
+static DEFINE_MUTEX(pcc_data_lock);
/* The cpu_pcc_subspace_idx contains per CPU subspace ID */
static DEFINE_PER_CPU(int, cpu_pcc_subspace_idx);
@@ -93,9 +100,77 @@ static DEFINE_PER_CPU(int, cpu_pcc_subspace_idx);
*/
static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr);
+/* Protect immutable capability queries against descriptor removal. */
+static DEFINE_MUTEX(cpc_desc_lock);
+
+static void cpc_set_desc(unsigned int cpu, struct cpc_desc *desc)
+{
+ guard(mutex)(&cpc_desc_lock);
+ per_cpu(cpc_desc_ptr, cpu) = desc;
+}
+
+struct cpc_sysmem_node {
+ struct rb_node rb;
+ u64 subtree_last;
+ u64 start;
+ u64 last;
+ struct cpc_desc *desc;
+ unsigned int reg_idx;
+ struct list_head aliases;
+ struct list_head alias_node;
+ struct cpc_sysmem_node *alias_of;
+ bool registered;
+};
+
+struct cpc_non_mmio_node {
+ struct rb_node rb;
+ u64 subtree_last;
+ u64 start;
+ u64 last;
+ struct cpc_desc *desc;
+ unsigned int reg_idx;
+ u8 space_id;
+ u8 pcc_ss_id;
+ bool registered;
+};
+
+#define CPC_SYSMEM_START(node) ((node)->start)
+#define CPC_SYSMEM_LAST(node) ((node)->last)
+
+INTERVAL_TREE_DEFINE(struct cpc_sysmem_node, rb, u64, subtree_last,
+ CPC_SYSMEM_START, CPC_SYSMEM_LAST, static inline,
+ cpc_sysmem_itree)
+
+static struct rb_root_cached cpc_sysmem_tree = RB_ROOT_CACHED;
+static DEFINE_MUTEX(cpc_sysmem_lock);
+
+#define CPC_NON_MMIO_START(node) ((node)->start)
+#define CPC_NON_MMIO_LAST(node) ((node)->last)
+
+INTERVAL_TREE_DEFINE(struct cpc_non_mmio_node, rb, u64, subtree_last,
+ CPC_NON_MMIO_START, CPC_NON_MMIO_LAST, static inline,
+ cpc_non_mmio_itree)
+
+static struct rb_root_cached cpc_pcc_trees[MAX_PCC_SUBSPACES];
+static struct rb_root_cached cpc_sysio_tree = RB_ROOT_CACHED;
+static DEFINE_MUTEX(cpc_non_mmio_lock);
+
+static struct cpc_sysmem_node *cpc_sysmem_first(u64 start, u64 last)
+{
+ return cpc_sysmem_itree_iter_first(&cpc_sysmem_tree, start, last);
+}
+
+static struct cpc_sysmem_node *cpc_sysmem_next(struct cpc_sysmem_node *node,
+ u64 start, u64 last)
+{
+ return cpc_sysmem_itree_iter_next(node, start, last);
+}
+
+#define CPC_PCC_HEADER_SIZE 0x8
+
/* pcc mapped address + header size + offset within PCC subspace */
#define GET_PCC_VADDR(offs, pcc_ss_id) (pcc_data[pcc_ss_id]->pcc_channel->shmem + \
- 0x8 + (offs))
+ CPC_PCC_HEADER_SIZE + (offs))
/* Check if a CPC register is in PCC */
#define CPC_IN_PCC(cpc) ((cpc)->type == ACPI_TYPE_BUFFER && \
@@ -129,6 +204,28 @@ static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr);
!!(cpc)->cpc_entry.int_value : \
!IS_NULL_REG(&(cpc)->cpc_entry.reg))
+static bool cpc_is_writable(const struct cpc_register_resource *cpc)
+{
+ return cpc->type == ACPI_TYPE_BUFFER &&
+ !IS_NULL_REG(&cpc->cpc_entry.reg) &&
+ !cpc->cpc_entry.write_unsupported;
+}
+
+static bool cpc_is_readable(const struct cpc_register_resource *cpc)
+{
+ return cpc->type != ACPI_TYPE_BUFFER ||
+ !cpc->cpc_entry.read_unsupported;
+}
+
+static bool cpc_entry_present(const struct cpc_register_resource *cpc)
+{
+ if (cpc->type == ACPI_TYPE_INTEGER)
+ return true;
+
+ return cpc->type == ACPI_TYPE_BUFFER &&
+ !IS_NULL_REG(&cpc->cpc_entry.reg);
+}
+
/*
* Each bit indicates the optionality of the register in per-cpu
* cpc_regs[] with the corresponding index. 0 means mandatory and 1
@@ -142,6 +239,36 @@ static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr);
*/
#define IS_OPTIONAL_CPC_REG(reg_idx) (REG_OPTIONAL & (1U << (reg_idx)))
+static bool cpc_integer_entry_valid(unsigned int reg_idx, u64 value,
+ bool *legacy_null)
+{
+ *legacy_null = false;
+
+ switch (reg_idx) {
+ case HIGHEST_PERF:
+ case NOMINAL_PERF:
+ case LOW_NON_LINEAR_PERF:
+ case LOWEST_PERF:
+ case REFERENCE_PERF:
+ case LOWEST_FREQ:
+ case NOMINAL_FREQ:
+ return value <= U32_MAX;
+ case CTR_WRAP_TIME:
+ /* AML Integers and the kernel interface are both 64-bit. */
+ return true;
+ case AUTO_SEL_ENABLE:
+ return value <= 1;
+ case DESIRED_PERF:
+ /* Validated against Autonomous Selection after parsing. */
+ *legacy_null = value == 0;
+ return *legacy_null;
+ default:
+ /* Tolerate legacy Integer 0 placeholders for absent options. */
+ *legacy_null = value == 0 && IS_OPTIONAL_CPC_REG(reg_idx);
+ return *legacy_null;
+ }
+}
+
/*
* Arbitrary Retries in case the remote processor is slow to respond
* to PCC commands. Keeping it high enough to cover emulators where
@@ -149,7 +276,8 @@ static DEFINE_PER_CPU(struct cpc_desc *, cpc_desc_ptr);
*/
#define NUM_RETRIES 500ULL
-#define OVER_16BTS_MASK ~0xFFFFULL
+#define CPC_GENERIC_REGISTER_DESCRIPTOR 0x82
+#define CPC_GENERIC_REGISTER_LENGTH (sizeof(struct cpc_reg) - 3)
#define define_one_cppc_ro(_name) \
static struct kobj_attribute _name = \
@@ -200,15 +328,82 @@ show_cppc_data(cppc_get_perf_ctrs, cppc_perf_fb_ctrs, wraparound_time);
((((val) & GENMASK(((reg)->bit_width) - 1, 0)) << (reg)->bit_offset) | \
((prev_val) & ~(GENMASK(((reg)->bit_width) - 1, 0) << (reg)->bit_offset))) \
-static u64 cpc_sysmem_access_size(const struct cpc_register_resource *reg)
+static unsigned int cpc_reg_access_width(const struct cpc_reg *reg)
{
- const struct cpc_reg *gas = &reg->cpc_entry.reg;
- unsigned int width;
-
- if (gas->access_width > 4)
+ if (reg->access_width > 4)
return 0;
- width = GET_BIT_WIDTH(gas);
+ if (reg->access_width)
+ return 8U << (reg->access_width - 1);
+
+ return reg->bit_width;
+}
+
+enum cpc_platform_quirk {
+ CPC_QUIRK_PERF_LIMITED_OWNS_UNIT = BIT(0),
+};
+
+static const struct acpi_platform_list cpc_platform_quirk_list[] = {
+ {
+ .oem_id = "NVIDIA",
+ .oem_table_id = "T41",
+ .table = ACPI_SIG_DSDT,
+ .pred = all_versions,
+ .reason = "Performance Limited owns its access unit",
+ .data = CPC_QUIRK_PERF_LIMITED_OWNS_UNIT,
+ },
+ { }
+};
+
+static DEFINE_MUTEX(cpc_platform_quirk_lock);
+static bool cpc_platform_quirks_initialized;
+static u32 cpc_platform_quirks;
+
+static int cpc_get_platform_quirks(u32 *quirks)
+{
+ int idx, ret = 0;
+
+ mutex_lock(&cpc_platform_quirk_lock);
+ if (!cpc_platform_quirks_initialized) {
+ idx = acpi_match_platform_list(cpc_platform_quirk_list);
+ if (idx < 0 && idx != -ENODEV) {
+ ret = idx;
+ goto out;
+ }
+ if (idx >= 0)
+ cpc_platform_quirks = cpc_platform_quirk_list[idx].data;
+ cpc_platform_quirks_initialized = true;
+ }
+ *quirks = cpc_platform_quirks;
+out:
+ mutex_unlock(&cpc_platform_quirk_lock);
+
+ return ret;
+}
+
+static void cpc_apply_platform_quirks(struct cpc_reg *reg,
+ unsigned int reg_idx, u32 quirks)
+{
+ unsigned int access_width;
+
+ if (!(quirks & CPC_QUIRK_PERF_LIMITED_OWNS_UNIT) ||
+ reg_idx != PERF_LIMITED ||
+ reg->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY ||
+ reg->bit_width != 2 || reg->bit_offset)
+ return;
+
+ access_width = cpc_reg_access_width(reg);
+ if (access_width != 32)
+ return;
+
+ reg->bit_width = access_width;
+ pr_info_once("firmware quirk: Performance Limited owns its access unit, using Bit Width %u\n",
+ access_width);
+}
+
+static u64 cpc_sysmem_access_size(const struct cpc_register_resource *reg)
+{
+ unsigned int width = cpc_reg_access_width(&reg->cpc_entry.reg);
if (width != 8 && width != 16 && width != 32 && width != 64)
return 0;
@@ -216,13 +411,35 @@ static u64 cpc_sysmem_access_size(const struct cpc_register_resource *reg)
return width / 8;
}
+static u64 cpc_sysmem_field_size(const struct cpc_reg *gas)
+{
+ return DIV_ROUND_UP((u64)gas->bit_offset + gas->bit_width, 8);
+}
+
+static u64 cpc_sysmem_claim_size(const struct cpc_register_resource *reg)
+{
+ const struct cpc_reg *gas = &reg->cpc_entry.reg;
+ u64 access_size = cpc_sysmem_access_size(reg);
+
+ if (!gas->bit_width)
+ return access_size;
+
+ return max(access_size, cpc_sysmem_field_size(gas));
+}
+
+static bool cpc_reg_access_aligned(const struct cpc_reg *reg, u64 access_size)
+{
+ /* x86 MMIO and port-I/O accessors support unaligned addresses. */
+ return IS_ENABLED(CONFIG_X86) || IS_ALIGNED(reg->address, access_size);
+}
+
static bool cpc_sysmem_access_units_overlap(const struct cpc_register_resource *a,
const struct cpc_register_resource *b)
{
const struct cpc_reg *a_gas = &a->cpc_entry.reg;
const struct cpc_reg *b_gas = &b->cpc_entry.reg;
- u64 a_size = cpc_sysmem_access_size(a);
- u64 b_size = cpc_sysmem_access_size(b);
+ u64 a_size = cpc_sysmem_claim_size(a);
+ u64 b_size = cpc_sysmem_claim_size(b);
/* Keep the conservative locking path for malformed access widths. */
if (!a_size || !b_size)
@@ -234,36 +451,883 @@ static bool cpc_sysmem_access_units_overlap(const struct cpc_register_resource *
return a_gas->address - b_gas->address < b_size;
}
-static void cpc_mark_rmw_lock_users(struct cpc_desc *cpc_desc)
+static bool cpc_reg_is_writable(unsigned int reg_idx)
{
- int i, j;
+ /* Only controls written by this driver can be competing writers. */
+ switch (reg_idx) {
+ case DESIRED_PERF:
+ case MIN_PERF:
+ case MAX_PERF:
+ case PERF_LIMITED:
+ case ENABLE:
+ case AUTO_SEL_ENABLE:
+ case AUTO_ACT_WINDOW:
+ case ENERGY_PERF:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static bool cpc_reg_is_write_only(const struct cpc_desc *cpc_desc,
+ unsigned int reg_idx)
+{
+ return cpc_desc->version >= CPPC_V4_REV &&
+ (reg_idx == DESIRED_PERF || reg_idx == OSPM_NOMINAL_PERF);
+}
+static void cpc_disable_reg(struct cpc_desc *cpc_desc, unsigned int reg_idx)
+{
+ struct cpc_register_resource *reg = &cpc_desc->cpc_regs[reg_idx];
+
+ reg->type = ACPI_TYPE_INTEGER;
+ reg->cpc_entry.int_value = 0;
+}
+
+static bool cpc_optional_writer_can_be_disabled(unsigned int reg_idx)
+{
+ if (!IS_OPTIONAL_CPC_REG(reg_idx) || !cpc_reg_is_writable(reg_idx) ||
+ reg_idx == MIN_PERF || reg_idx == MAX_PERF || reg_idx == ENABLE ||
+ reg_idx == AUTO_SEL_ENABLE)
+ return false;
+
+ return true;
+}
+
+static bool cpc_sysmem_reg_needs_rmw(const struct cpc_register_resource *reg)
+{
+ const struct cpc_reg *gas = &reg->cpc_entry.reg;
+ u64 access_size = cpc_sysmem_access_size(reg);
+
+ return gas->bit_offset || gas->bit_width != access_size * 8;
+}
+
+static int cpc_validate_sysmem_reg(struct cpc_desc *cpc_desc,
+ const struct cpc_reg *gas,
+ unsigned int reg_idx)
+{
+ unsigned int access_width = cpc_reg_access_width(gas);
+ u64 access_size;
+
+ if (access_width != 8 && access_width != 16 &&
+ access_width != 32 && access_width != 64)
+ goto invalid;
+
+ if (!gas->bit_width || gas->bit_width > access_width ||
+ gas->bit_offset >= access_width ||
+ gas->bit_width > access_width - gas->bit_offset)
+ goto invalid;
+
+ access_size = access_width / 8;
+ if (!gas->address || gas->address > U64_MAX - (access_size - 1))
+ goto invalid;
+ if (!cpc_reg_access_aligned(gas, access_size))
+ goto invalid;
+
+ if (reg_idx == PERF_LIMITED) {
+ if (access_width == 64 && !IS_ENABLED(CONFIG_64BIT)) {
+ pr_warn_once("CPU%d: Performance Limited register cannot be accessed atomically; keeping its range reserved\n",
+ cpc_desc->cpu_id);
+ cpc_desc->cpc_regs[reg_idx].cpc_entry.read_unsupported = true;
+ cpc_desc->cpc_regs[reg_idx].cpc_entry.write_unsupported = true;
+ return 0;
+ }
+
+ if (gas->bit_offset || gas->bit_width != access_width) {
+ pr_warn_once("CPU%d: Performance Limited register cannot be cleared safely; keeping it readable\n",
+ cpc_desc->cpu_id);
+ cpc_desc->cpc_regs[reg_idx].cpc_entry.write_unsupported = true;
+ }
+ }
+
+ return 0;
+
+invalid:
+ access_size = 0;
+ if (access_width == 8 || access_width == 16 ||
+ access_width == 32 || access_width == 64)
+ access_size = access_width / 8;
+ if (gas->bit_width)
+ access_size = max(access_size, cpc_sysmem_field_size(gas));
+ if ((cpc_reg_is_write_only(cpc_desc, reg_idx) ||
+ reg_idx == PERF_LIMITED) && gas->address && access_size &&
+ gas->address <= U64_MAX - (access_size - 1)) {
+ struct cpc_register_resource *reg = &cpc_desc->cpc_regs[reg_idx];
+
+ if (reg_idx == PERF_LIMITED)
+ pr_warn_once("CPU%d: _CPC v%d register %u is inaccessible; keeping its range reserved\n",
+ cpc_desc->cpu_id, cpc_desc->version, reg_idx);
+ else
+ pr_warn("CPU%d: _CPC v%d register %u is inaccessible; keeping its range reserved\n",
+ cpc_desc->cpu_id, cpc_desc->version, reg_idx);
+ reg->cpc_entry.read_unsupported = true;
+ reg->cpc_entry.write_unsupported = true;
+ return 0;
+ }
+
+ pr_debug("CPU:%d invalid SystemMemory GAS for _CPC register %u\n",
+ cpc_desc->cpu_id, reg_idx);
+ return -EINVAL;
+}
+
+static bool cpc_immutable_autonomous(const struct cpc_desc *cpc_desc)
+{
+ const struct cpc_register_resource *reg;
+
+ reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE];
+ return osc_sb_cppc2_support_acked && reg->type == ACPI_TYPE_INTEGER &&
+ reg->cpc_entry.int_value == 1;
+}
+
+static bool cpc_retain_pcc_status(struct cpc_desc *cpc_desc,
+ unsigned int reg_idx);
+
+static int cpc_resolve_unsupported(struct cpc_desc *cpc_desc,
+ u32 unsupported)
+{
+ unsigned int i;
+ u32 bounds = BIT(MIN_PERF) | BIT(MAX_PERF);
+ bool min_unusable, max_unusable;
+
+ if (unsupported & bounds) {
+ min_unusable = (unsupported & BIT(MIN_PERF)) ||
+ !cpc_is_writable(&cpc_desc->cpc_regs[MIN_PERF]);
+ max_unusable = (unsupported & BIT(MAX_PERF)) ||
+ !cpc_is_writable(&cpc_desc->cpc_regs[MAX_PERF]);
+ if (min_unusable && max_unusable) {
+ pr_warn("CPU%d: ignoring inaccessible Minimum and Maximum Performance registers\n",
+ cpc_desc->cpu_id);
+ cpc_disable_reg(cpc_desc, MIN_PERF);
+ cpc_disable_reg(cpc_desc, MAX_PERF);
+ unsupported &= ~bounds;
+ }
+ }
+
+ for (i = 0; i < cpc_desc->num_entries - 2; i++) {
+ if (!(unsupported & BIT(i)))
+ continue;
+
+ /* CPPC control does not depend on Performance Limited status. */
+ if (i == PERF_LIMITED) {
+ if (CPC_IN_PCC(&cpc_desc->cpc_regs[i]) &&
+ cpc_retain_pcc_status(cpc_desc, i))
+ continue;
+
+ pr_warn_once("CPU%d: ignoring inaccessible Performance Limited register\n",
+ cpc_desc->cpu_id);
+ cpc_disable_reg(cpc_desc, i);
+ continue;
+ }
+
+ if (i == DESIRED_PERF && cpc_immutable_autonomous(cpc_desc)) {
+ pr_warn("CPU%d: ignoring inaccessible Desired Performance register in autonomous mode\n",
+ cpc_desc->cpu_id);
+ cpc_disable_reg(cpc_desc, i);
+ continue;
+ }
+
+ /*
+ * A present Enable or Autonomous Selection control must remain
+ * usable. Disabling the latter could leave autonomous selection
+ * enabled while OSPM believes that it has disabled it.
+ */
+ if (i == ENABLE ||
+ (i == AUTO_SEL_ENABLE && cpc_entry_present(&cpc_desc->cpc_regs[i])) ||
+ i == MIN_PERF || i == MAX_PERF ||
+ !IS_OPTIONAL_CPC_REG(i)) {
+ pr_err("CPU%d: cannot access _CPC register %u\n",
+ cpc_desc->cpu_id, i);
+ return -EINVAL;
+ }
+
+ pr_warn("CPU%d: ignoring inaccessible optional _CPC register %u\n",
+ cpc_desc->cpu_id, i);
+ cpc_disable_reg(cpc_desc, i);
+ }
+
+ return 0;
+}
+
+static int cpc_validate_required_controls(struct cpc_desc *cpc_desc)
+{
+ unsigned int i;
+
+ /*
+ * Performance Limited is required by the specification, but tolerate a
+ * NULL descriptor used by firmware which cannot report limiting events.
+ * CPPC control does not depend on this status.
+ */
for (i = 0; i < cpc_desc->num_entries - 2; i++) {
- struct cpc_register_resource *a = &cpc_desc->cpc_regs[i];
+ if (i != DESIRED_PERF && i != PERF_LIMITED &&
+ !IS_OPTIONAL_CPC_REG(i) &&
+ !cpc_entry_present(&cpc_desc->cpc_regs[i])) {
+ pr_debug("CPU:%d lacks mandatory _CPC register %u\n",
+ cpc_desc->cpu_id, i);
+ return -EINVAL;
+ }
+ }
+
+ /* Desired may be absent only for immutable autonomous operation. */
+ if (!cpc_is_writable(&cpc_desc->cpc_regs[DESIRED_PERF]) &&
+ !cpc_immutable_autonomous(cpc_desc)) {
+ pr_debug("CPU:%d lacks a writable Desired Performance register\n",
+ cpc_desc->cpu_id);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int cpc_validate_bound_controls(struct cpc_desc *cpc_desc)
+{
+ bool have_min, have_max;
+
+ have_min = cpc_is_writable(&cpc_desc->cpc_regs[MIN_PERF]);
+ have_max = cpc_is_writable(&cpc_desc->cpc_regs[MAX_PERF]);
+ if (have_min != have_max) {
+ pr_err("CPU%d: _CPC must provide both Minimum and Maximum Performance or neither\n",
+ cpc_desc->cpu_id);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static bool
+cpc_retain_pcc_status(struct cpc_desc *cpc_desc, unsigned int reg_idx)
+{
+ struct cpc_register_resource *reg = &cpc_desc->cpc_regs[reg_idx];
+ const struct cpc_reg *gas = &reg->cpc_entry.reg;
+ u64 size;
+
+ if (reg_idx != PERF_LIMITED || !gas->bit_width)
+ return false;
+
+ size = DIV_ROUND_UP((u64)gas->bit_offset + gas->bit_width, 8);
+ if (!size || gas->address > U64_MAX - (size - 1))
+ return false;
+
+ reg->cpc_entry.read_unsupported = true;
+ reg->cpc_entry.write_unsupported = true;
+ pr_warn_once("CPU%d: Performance Limited register cannot be accessed; keeping its PCC range reserved\n",
+ cpc_desc->cpu_id);
+ return true;
+}
+
+static bool
+cpc_retain_sysio_status(struct cpc_desc *cpc_desc, unsigned int reg_idx)
+{
+ struct cpc_register_resource *reg = &cpc_desc->cpc_regs[reg_idx];
+ const struct cpc_reg *gas = &reg->cpc_entry.reg;
+
+ if (reg_idx != PERF_LIMITED || !gas->bit_width)
+ return false;
+
+ /* Retain any in-range portion for overlap validation only. */
+ if (gas->address > U16_MAX)
+ return false;
+
+ pr_warn_once("CPU%d: Performance Limited register cannot be accessed; keeping its SystemIO range reserved\n",
+ cpc_desc->cpu_id);
+ reg->cpc_entry.read_unsupported = true;
+ reg->cpc_entry.write_unsupported = true;
+ return true;
+}
+
+static u64 cpc_non_mmio_access_size(const struct cpc_register_resource *reg)
+{
+ const struct cpc_reg *gas = &reg->cpc_entry.reg;
+
+ if (gas->space_id == ACPI_ADR_SPACE_PLATFORM_COMM)
+ return DIV_ROUND_UP((u64)gas->bit_offset + gas->bit_width, 8);
+
+ return max((u64)cpc_reg_access_width(gas) / 8,
+ DIV_ROUND_UP((u64)gas->bit_offset + gas->bit_width, 8));
+}
+
+static void cpc_validate_pcc_bounds(struct cpc_desc *cpc_desc,
+ int pcc_ss_id, struct cppc_pcc_data *data,
+ u32 *unsupported)
+{
+ u64 shmem_size = data->pcc_channel->shmem_size;
+ unsigned int i;
+
+ for (i = 0; i < cpc_desc->num_entries - 2; i++) {
+ struct cpc_register_resource *reg = &cpc_desc->cpc_regs[i];
struct cpc_reg *gas;
u64 access_size;
- if (!CPC_SUPPORTED(a) || !CPC_IN_SYSTEM_MEMORY(a))
+ if ((*unsupported & BIT(i)) || !CPC_SUPPORTED(reg) ||
+ !CPC_IN_PCC(reg))
continue;
- gas = &a->cpc_entry.reg;
- access_size = cpc_sysmem_access_size(a);
- if (gas->bit_offset || !access_size ||
- gas->bit_width != access_size * 8)
- a->cpc_entry.use_rmw_lock = true;
+ gas = &reg->cpc_entry.reg;
+ if (gas->access_width != pcc_ss_id)
+ continue;
+ access_size = cpc_non_mmio_access_size(reg);
+ if (shmem_size >= CPC_PCC_HEADER_SIZE &&
+ gas->address <= shmem_size - CPC_PCC_HEADER_SIZE &&
+ access_size <= shmem_size - CPC_PCC_HEADER_SIZE - gas->address)
+ continue;
- for (j = i + 1; j < cpc_desc->num_entries - 2; j++) {
- struct cpc_register_resource *b = &cpc_desc->cpc_regs[j];
+ pr_debug("CPU%d: _CPC register %u exceeds the PCC shared region\n",
+ cpc_desc->cpu_id, i);
+ *unsupported |= BIT(i);
+ }
+}
- if (!CPC_SUPPORTED(b) || !CPC_IN_SYSTEM_MEMORY(b))
- continue;
- if (!cpc_sysmem_access_units_overlap(a, b))
- continue;
+static bool cpc_pcc_access_needed(const struct cpc_desc *cpc_desc)
+{
+ unsigned int i;
+
+ for (i = 0; i < cpc_desc->num_entries - 2; i++) {
+ const struct cpc_register_resource *reg = &cpc_desc->cpc_regs[i];
+
+ if (CPC_SUPPORTED(reg) && CPC_IN_PCC(reg) &&
+ (cpc_is_readable(reg) || cpc_is_writable(reg)))
+ return true;
+ }
+
+ return false;
+}
+
+static bool cpc_non_mmio_overlap_conflicts(u8 space_id, bool a_writable,
+ bool b_writable, bool a_write_only,
+ bool b_write_only)
+{
+ /* Only a write-only control can use a separate read-side port alias. */
+ if (space_id == ACPI_ADR_SPACE_SYSTEM_IO && a_writable != b_writable)
+ return a_writable ? !a_write_only : !b_write_only;
+
+ return a_writable || b_writable;
+}
+
+static bool
+cpc_sysio_perf_limited_conflicts(unsigned int a_idx, bool a_writable,
+ unsigned int b_idx, bool b_writable)
+{
+ return (a_idx == PERF_LIMITED && b_writable) ||
+ (b_idx == PERF_LIMITED && a_writable);
+}
+
+static struct rb_root_cached *cpc_non_mmio_tree(u8 space_id, u8 pcc_ss_id)
+{
+ if (space_id == ACPI_ADR_SPACE_PLATFORM_COMM)
+ return &cpc_pcc_trees[pcc_ss_id];
+ if (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
+ return &cpc_sysio_tree;
+ return NULL;
+}
+
+static bool cpc_same_non_mmio_register(const struct cpc_non_mmio_node *a,
+ const struct cpc_non_mmio_node *b)
+{
+ const struct cpc_reg *a_gas =
+ &a->desc->cpc_regs[a->reg_idx].cpc_entry.reg;
+ const struct cpc_reg *b_gas =
+ &b->desc->cpc_regs[b->reg_idx].cpc_entry.reg;
+
+ return a->space_id == b->space_id && a->pcc_ss_id == b->pcc_ss_id &&
+ a->reg_idx == b->reg_idx && a->start == b->start &&
+ a->last == b->last && a_gas->bit_offset == b_gas->bit_offset &&
+ a_gas->bit_width == b_gas->bit_width &&
+ (a->space_id == ACPI_ADR_SPACE_PLATFORM_COMM ||
+ cpc_reg_access_width(a_gas) == cpc_reg_access_width(b_gas));
+}
+
+static int cpc_validate_non_mmio_pair(const struct cpc_non_mmio_node *a,
+ const struct cpc_non_mmio_node *b)
+{
+ const struct cpc_register_resource *a_reg;
+ const struct cpc_register_resource *b_reg;
+ bool a_writable, b_writable;
+ const char *name;
+
+ a_reg = &a->desc->cpc_regs[a->reg_idx];
+ b_reg = &b->desc->cpc_regs[b->reg_idx];
+ a_writable = cpc_reg_is_writable(a->reg_idx) && cpc_is_writable(a_reg);
+ b_writable = cpc_reg_is_writable(b->reg_idx) && cpc_is_writable(b_reg);
+
+ if (!cpc_non_mmio_overlap_conflicts(a->space_id, a_writable,
+ b_writable,
+ cpc_reg_is_write_only(a->desc, a->reg_idx),
+ cpc_reg_is_write_only(b->desc, b->reg_idx)) &&
+ !(a->space_id == ACPI_ADR_SPACE_SYSTEM_IO &&
+ cpc_sysio_perf_limited_conflicts(a->reg_idx, a_writable,
+ b->reg_idx, b_writable)))
+ return 0;
+
+ if (cpc_same_non_mmio_register(a, b))
+ return 0;
+
+ name = a->space_id == ACPI_ADR_SPACE_PLATFORM_COMM ?
+ "PCC" : "SystemIO";
+ pr_err("CPU%d: %s _CPC register %u conflicts with CPU%d register %u\n",
+ a->desc->cpu_id, name, a->reg_idx, b->desc->cpu_id,
+ b->reg_idx);
+ return -EINVAL;
+}
+
+static void cpc_unregister_non_mmio_desc_locked(struct cpc_desc *cpc_desc)
+{
+ unsigned int i;
+
+ if (!cpc_desc->non_mmio_nodes)
+ return;
+
+ for (i = 0; i < cpc_desc->num_entries - 2; i++) {
+ struct cpc_non_mmio_node *node = &cpc_desc->non_mmio_nodes[i];
+ struct rb_root_cached *tree;
+
+ if (!node->registered)
+ continue;
+
+ tree = cpc_non_mmio_tree(node->space_id, node->pcc_ss_id);
+ cpc_non_mmio_itree_remove(node, tree);
+ }
+
+ kfree(cpc_desc->non_mmio_nodes);
+ cpc_desc->non_mmio_nodes = NULL;
+}
+
+static int cpc_register_non_mmio_desc(struct cpc_desc *cpc_desc)
+{
+ unsigned int nr_regs = cpc_desc->num_entries - 2;
+ unsigned int i;
+ int ret = 0;
+ bool found = false;
+
+ for (i = 0; i < nr_regs; i++) {
+ struct cpc_register_resource *reg = &cpc_desc->cpc_regs[i];
+ u8 space_id;
+
+ if (!CPC_SUPPORTED(reg) || reg->type != ACPI_TYPE_BUFFER)
+ continue;
+ space_id = reg->cpc_entry.reg.space_id;
+ if (space_id == ACPI_ADR_SPACE_PLATFORM_COMM ||
+ space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ return 0;
+
+ cpc_desc->non_mmio_nodes = kcalloc(nr_regs,
+ sizeof(*cpc_desc->non_mmio_nodes),
+ GFP_KERNEL);
+ if (!cpc_desc->non_mmio_nodes)
+ return -ENOMEM;
+
+ mutex_lock(&cpc_non_mmio_lock);
+
+ for (i = 0; i < nr_regs; i++) {
+ struct cpc_register_resource *reg = &cpc_desc->cpc_regs[i];
+ struct cpc_non_mmio_node *match, *node;
+ struct rb_root_cached *tree;
+ u8 space_id;
+ u64 size;
+
+ if (!CPC_SUPPORTED(reg) || reg->type != ACPI_TYPE_BUFFER)
+ continue;
+
+ space_id = reg->cpc_entry.reg.space_id;
+ if (space_id != ACPI_ADR_SPACE_PLATFORM_COMM &&
+ space_id != ACPI_ADR_SPACE_SYSTEM_IO)
+ continue;
+
+ node = &cpc_desc->non_mmio_nodes[i];
+ size = cpc_non_mmio_access_size(reg);
+ node->start = reg->cpc_entry.reg.address;
+ node->last = node->start + size - 1;
+ node->desc = cpc_desc;
+ node->reg_idx = i;
+ node->space_id = space_id;
+ node->pcc_ss_id = space_id == ACPI_ADR_SPACE_PLATFORM_COMM ?
+ reg->cpc_entry.reg.access_width : 0;
+ tree = cpc_non_mmio_tree(space_id, node->pcc_ss_id);
+
+ match = cpc_non_mmio_itree_iter_first(tree, node->start,
+ node->last);
+ while (match) {
+ ret = cpc_validate_non_mmio_pair(node, match);
+ if (ret)
+ goto out_unregister;
+
+ match = cpc_non_mmio_itree_iter_next(match, node->start,
+ node->last);
+ }
+ cpc_non_mmio_itree_insert(node, tree);
+ node->registered = true;
+ }
+
+ mutex_unlock(&cpc_non_mmio_lock);
+ return 0;
+
+out_unregister:
+ cpc_unregister_non_mmio_desc_locked(cpc_desc);
+ mutex_unlock(&cpc_non_mmio_lock);
+ return ret;
+}
+
+static void cpc_unregister_non_mmio_desc(struct cpc_desc *cpc_desc)
+{
+ if (!cpc_desc->non_mmio_nodes)
+ return;
+
+ mutex_lock(&cpc_non_mmio_lock);
+ cpc_unregister_non_mmio_desc_locked(cpc_desc);
+ mutex_unlock(&cpc_non_mmio_lock);
+}
+
+static void cpc_mark_rmw_lock_users(struct cpc_desc *cpc_desc)
+{
+ int i;
+
+ for (i = 0; i < cpc_desc->num_entries - 2; i++) {
+ struct cpc_register_resource *reg = &cpc_desc->cpc_regs[i];
+
+ if (CPC_SUPPORTED(reg) && CPC_IN_SYSTEM_MEMORY(reg) &&
+ cpc_is_writable(reg))
+ reg->cpc_entry.use_rmw_lock =
+ cpc_sysmem_reg_needs_rmw(reg);
+ }
+}
+
+struct cpc_bit_position {
+ u64 byte;
+ u8 bit;
+};
+
+static bool cpc_bit_position_before(const struct cpc_bit_position *a,
+ const struct cpc_bit_position *b)
+{
+ return a->byte < b->byte || (a->byte == b->byte && a->bit < b->bit);
+}
+
+static bool cpc_sysmem_fields_overlap(const struct cpc_register_resource *a,
+ const struct cpc_register_resource *b)
+{
+ const struct cpc_reg *a_gas = &a->cpc_entry.reg;
+ const struct cpc_reg *b_gas = &b->cpc_entry.reg;
+ unsigned int a_last_bit = a_gas->bit_offset + a_gas->bit_width - 1;
+ unsigned int b_last_bit = b_gas->bit_offset + b_gas->bit_width - 1;
+ struct cpc_bit_position a_start = {
+ .byte = a_gas->address + a_gas->bit_offset / 8,
+ .bit = a_gas->bit_offset % 8,
+ };
+ struct cpc_bit_position a_end = {
+ .byte = a_gas->address + a_last_bit / 8,
+ .bit = a_last_bit % 8,
+ };
+ struct cpc_bit_position b_start = {
+ .byte = b_gas->address + b_gas->bit_offset / 8,
+ .bit = b_gas->bit_offset % 8,
+ };
+ struct cpc_bit_position b_end = {
+ .byte = b_gas->address + b_last_bit / 8,
+ .bit = b_last_bit % 8,
+ };
+
+ return !cpc_bit_position_before(&a_end, &b_start) &&
+ !cpc_bit_position_before(&b_end, &a_start);
+}
+
+static bool cpc_sysmem_access_overlaps_field(const struct cpc_register_resource *access,
+ const struct cpc_register_resource *field)
+{
+ const struct cpc_reg *access_gas = &access->cpc_entry.reg;
+ const struct cpc_reg *field_gas = &field->cpc_entry.reg;
+ u64 access_last;
+ u64 field_start;
+ u64 field_last;
+
+ if (!field_gas->bit_width)
+ return cpc_sysmem_access_units_overlap(access, field);
+
+ access_last = access_gas->address +
+ cpc_sysmem_access_size(access) - 1;
+ field_start = field_gas->address + field_gas->bit_offset / 8;
+ field_last = field_gas->address +
+ (field_gas->bit_offset + field_gas->bit_width - 1) / 8;
+
+ return access_gas->address <= field_last && field_start <= access_last;
+}
+
+static bool cpc_same_sysmem_register(unsigned int a_idx,
+ const struct cpc_register_resource *a,
+ unsigned int b_idx,
+ const struct cpc_register_resource *b)
+{
+ const struct cpc_reg *a_gas = &a->cpc_entry.reg;
+ const struct cpc_reg *b_gas = &b->cpc_entry.reg;
+
+ return a_idx == b_idx &&
+ a_gas->address == b_gas->address &&
+ a_gas->bit_width == b_gas->bit_width &&
+ a_gas->bit_offset == b_gas->bit_offset &&
+ cpc_reg_access_width(a_gas) == cpc_reg_access_width(b_gas);
+}
+
+static int cpc_validate_sysmem_pair(const struct cpc_desc *a_desc,
+ unsigned int a_idx,
+ const struct cpc_desc *b_desc,
+ unsigned int b_idx)
+{
+ const struct cpc_register_resource *a = &a_desc->cpc_regs[a_idx];
+ const struct cpc_register_resource *b = &b_desc->cpc_regs[b_idx];
+ bool a_write_only, b_write_only;
+ bool a_writable, b_writable;
+ bool fields_overlap;
+
+ /* The overlap helper includes each descriptor's conservative claim. */
+ if (!CPC_SUPPORTED(a) || !CPC_IN_SYSTEM_MEMORY(a) ||
+ !CPC_SUPPORTED(b) || !CPC_IN_SYSTEM_MEMORY(b) ||
+ !cpc_sysmem_access_units_overlap(a, b))
+ return 0;
+
+ a_write_only = cpc_reg_is_write_only(a_desc, a_idx);
+ b_write_only = cpc_reg_is_write_only(b_desc, b_idx);
+ fields_overlap = !a->cpc_entry.reg.bit_width ||
+ !b->cpc_entry.reg.bit_width ||
+ cpc_sysmem_fields_overlap(a, b);
+ /* A readable field must not expose another field's undefined bits. */
+ if (a_write_only != b_write_only &&
+ cpc_is_readable(a_write_only ? b : a) &&
+ fields_overlap)
+ goto conflict;
+
+ a_writable = cpc_reg_is_writable(a_idx) && cpc_is_writable(a);
+ b_writable = cpc_reg_is_writable(b_idx) && cpc_is_writable(b);
+ if (!a_writable && !b_writable)
+ return 0;
+
+ if (cpc_same_sysmem_register(a_idx, a, b_idx, b)) {
+ u64 access_size = cpc_sysmem_access_size(a);
+
+ /*
+ * Exact partial aliases update the same field and retain
+ * last-writer-wins semantics when the complete access is one native
+ * transaction. A 64-bit MMIO write may be split on 32-bit kernels,
+ * and an unaligned x86 access is not guaranteed to be one device
+ * transaction.
+ */
+ if (!a_writable ||
+ (IS_ALIGNED(a->cpc_entry.reg.address, access_size) &&
+ (access_size < sizeof(u64) ||
+ IS_ENABLED(CONFIG_64BIT))))
+ return 0;
+ goto conflict;
+ }
+
+ /*
+ * The platform may set Performance Limited asynchronously. A write to
+ * another field in the same access unit could write back stale status
+ * bits, which an OSPM lock cannot prevent.
+ */
+ if ((a_idx == PERF_LIMITED && b_writable) ||
+ (b_idx == PERF_LIMITED && a_writable))
+ goto conflict;
+
+ /* A full-width writer must not overwrite another logical field. */
+ if (fields_overlap &&
+ ((a_writable && b_writable) ||
+ (a_writable && !cpc_sysmem_reg_needs_rmw(a)) ||
+ (b_writable && !cpc_sysmem_reg_needs_rmw(b))))
+ goto conflict;
+
+ /* Different descriptors do not share their partial-write locks. */
+ if (a_desc != b_desc && a_writable && b_writable)
+ goto conflict;
+
+ /*
+ * RMW of either writer preserves the other field. If that field is
+ * write-only, its readback is undefined and cannot safely be replayed.
+ */
+ if ((a_write_only && b_writable &&
+ cpc_sysmem_reg_needs_rmw(b) &&
+ cpc_sysmem_access_overlaps_field(b, a)) ||
+ (b_write_only && a_writable &&
+ cpc_sysmem_reg_needs_rmw(a) &&
+ cpc_sysmem_access_overlaps_field(a, b)))
+ goto conflict;
- a->cpc_entry.use_rmw_lock = true;
- b->cpc_entry.use_rmw_lock = true;
+ return 0;
+
+conflict:
+ pr_err("CPU%d: SystemMemory _CPC register %u conflicts with CPU%d register %u\n",
+ a_desc->cpu_id, a_idx, b_desc->cpu_id, b_idx);
+ return -EINVAL;
+}
+
+static bool cpc_disable_new_sysmem_writer(struct cpc_desc *cpc_desc,
+ unsigned int reg_idx,
+ const struct cpc_sysmem_node *node)
+{
+ struct cpc_register_resource *reg = &cpc_desc->cpc_regs[reg_idx];
+ struct cpc_sysmem_node *match;
+ unsigned int status_cpu = 0;
+ bool found = false;
+
+ if (!cpc_optional_writer_can_be_disabled(reg_idx) ||
+ !cpc_is_writable(reg))
+ return false;
+
+ match = cpc_sysmem_first(node->start, node->last);
+ while (match) {
+ const struct cpc_register_resource *status;
+
+ if (match->reg_idx == PERF_LIMITED) {
+ status = &match->desc->cpc_regs[PERF_LIMITED];
+ if (!status->cpc_entry.reg.bit_width ||
+ cpc_sysmem_fields_overlap(reg, status))
+ return false;
+ status_cpu = match->desc->cpu_id;
+ found = true;
+ }
+
+ match = cpc_sysmem_next(match, node->start, node->last);
+ }
+ if (!found)
+ return false;
+
+ pr_warn_once("CPU%d: ignoring optional _CPC register %u sharing CPU%d Performance Limited access unit\n",
+ cpc_desc->cpu_id, reg_idx, status_cpu);
+ cpc_disable_reg(cpc_desc, reg_idx);
+ return true;
+}
+
+static void cpc_unregister_sysmem_desc_locked(struct cpc_desc *cpc_desc)
+{
+ unsigned int i;
+
+ if (!cpc_desc->sysmem_nodes)
+ return;
+
+ for (i = 0; i < cpc_desc->num_entries - 2; i++) {
+ struct cpc_sysmem_node *node = &cpc_desc->sysmem_nodes[i];
+ struct cpc_sysmem_node *alias, *child;
+
+ if (node->alias_of) {
+ list_del(&node->alias_node);
+ continue;
}
+ if (!node->registered)
+ continue;
+
+ cpc_sysmem_itree_remove(node, &cpc_sysmem_tree);
+ node->registered = false;
+ if (list_empty(&node->aliases))
+ continue;
+
+ /* Keep one representative for aliases owned by live descriptors. */
+ alias = list_first_entry(&node->aliases,
+ struct cpc_sysmem_node, alias_node);
+ list_del_init(&alias->alias_node);
+ alias->alias_of = NULL;
+ alias->registered = true;
+ list_splice_init(&node->aliases, &alias->aliases);
+ list_for_each_entry(child, &alias->aliases, alias_node)
+ child->alias_of = alias;
+ cpc_sysmem_itree_insert(alias, &cpc_sysmem_tree);
}
+
+ kfree(cpc_desc->sysmem_nodes);
+ cpc_desc->sysmem_nodes = NULL;
+}
+
+static int cpc_register_sysmem_desc(struct cpc_desc *cpc_desc)
+{
+ unsigned int nr_regs = cpc_desc->num_entries - 2;
+ unsigned int i;
+ int ret = 0;
+ bool found = false;
+
+ for (i = 0; i < nr_regs; i++) {
+ struct cpc_register_resource *reg = &cpc_desc->cpc_regs[i];
+
+ if (CPC_SUPPORTED(reg) && CPC_IN_SYSTEM_MEMORY(reg)) {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ return 0;
+
+ cpc_desc->sysmem_nodes = kcalloc(nr_regs,
+ sizeof(*cpc_desc->sysmem_nodes),
+ GFP_KERNEL);
+ if (!cpc_desc->sysmem_nodes)
+ return -ENOMEM;
+
+ mutex_lock(&cpc_sysmem_lock);
+
+ for (i = 0; i < nr_regs; i++) {
+ struct cpc_register_resource *reg = &cpc_desc->cpc_regs[i];
+ struct cpc_sysmem_node *alias = NULL, *match, *node;
+ u64 size;
+
+ if (!CPC_SUPPORTED(reg) || !CPC_IN_SYSTEM_MEMORY(reg))
+ continue;
+
+ node = &cpc_desc->sysmem_nodes[i];
+ size = cpc_sysmem_claim_size(reg);
+ node->start = reg->cpc_entry.reg.address;
+ node->last = node->start + size - 1;
+ node->desc = cpc_desc;
+ node->reg_idx = i;
+ INIT_LIST_HEAD(&node->aliases);
+ INIT_LIST_HEAD(&node->alias_node);
+
+ /* Performance Limited precedes every optional writer we may disable. */
+ if (cpc_disable_new_sysmem_writer(cpc_desc, i, node))
+ continue;
+
+ match = cpc_sysmem_first(node->start, node->last);
+ while (match) {
+ struct cpc_register_resource *match_reg;
+
+ match_reg = &match->desc->cpc_regs[match->reg_idx];
+ ret = cpc_validate_sysmem_pair(cpc_desc, i, match->desc,
+ match->reg_idx);
+ if (ret)
+ goto out_unregister;
+ if (cpc_desc == match->desc) {
+ reg->cpc_entry.use_rmw_lock = true;
+ match_reg->cpc_entry.use_rmw_lock = true;
+ }
+ if (cpc_same_sysmem_register(i, reg, match->reg_idx, match_reg))
+ alias = match;
+
+ match = cpc_sysmem_next(match, node->start, node->last);
+ }
+ if (alias) {
+ node->alias_of = alias;
+ list_add_tail(&node->alias_node, &alias->aliases);
+ continue;
+ }
+
+ cpc_sysmem_itree_insert(node, &cpc_sysmem_tree);
+ node->registered = true;
+ }
+
+ mutex_unlock(&cpc_sysmem_lock);
+ return 0;
+
+out_unregister:
+ cpc_unregister_sysmem_desc_locked(cpc_desc);
+ mutex_unlock(&cpc_sysmem_lock);
+ return ret;
+}
+
+static void cpc_unregister_sysmem_desc(struct cpc_desc *cpc_desc)
+{
+ if (!cpc_desc->sysmem_nodes)
+ return;
+
+ mutex_lock(&cpc_sysmem_lock);
+ cpc_unregister_sysmem_desc_locked(cpc_desc);
+ mutex_unlock(&cpc_sysmem_lock);
}
static ssize_t show_feedback_ctrs(struct kobject *kobj,
@@ -297,7 +1361,30 @@ static struct attribute *cppc_attrs[] = {
};
ATTRIBUTE_GROUPS(cppc);
+static void cppc_free_desc(struct cpc_desc *cpc_ptr)
+{
+ unsigned int i;
+
+ cpc_unregister_non_mmio_desc(cpc_ptr);
+ cpc_unregister_sysmem_desc(cpc_ptr);
+
+ for (i = 2; i < cpc_ptr->num_entries; i++) {
+ void __iomem *addr = cpc_ptr->cpc_regs[i - 2].sys_mem_vaddr;
+
+ if (addr)
+ iounmap(addr);
+ }
+
+ kfree(cpc_ptr);
+}
+
+static void cppc_kobj_release(struct kobject *kobj)
+{
+ cppc_free_desc(to_cpc_desc(kobj));
+}
+
static const struct kobj_type cppc_ktype = {
+ .release = cppc_kobj_release,
.sysfs_ops = &kobj_sysfs_ops,
.default_groups = cppc_groups,
};
@@ -321,6 +1408,8 @@ static int check_pcc_chan(int pcc_ss_id, bool chk_err_bit)
pcc_ss_data->deadline_us);
if (likely(!ret)) {
+ /* Order completion status before reading the returned payload. */
+ rmb();
pcc_ss_data->platform_owns_pcc = false;
if (chk_err_bit && (status & PCC_ERROR_MASK))
ret = -EIO;
@@ -333,13 +1422,47 @@ static int check_pcc_chan(int pcc_ss_id, bool chk_err_bit)
return ret;
}
+static void cppc_complete_pcc_write(int pcc_ss_id,
+ struct cppc_pcc_data *pcc_ss_data, int ret)
+{
+ int i;
+
+ if (unlikely(ret)) {
+ for_each_possible_cpu(i) {
+ struct cpc_desc *desc = per_cpu(cpc_desc_ptr, i);
+
+ if (!desc ||
+ per_cpu(cpu_pcc_subspace_idx, i) != pcc_ss_id)
+ continue;
+
+ if (desc->write_cmd_id == pcc_ss_data->pcc_write_cnt)
+ desc->write_cmd_status = ret;
+ }
+ }
+
+ pcc_ss_data->pcc_write_cnt++;
+ wake_up_all(&pcc_ss_data->pcc_write_wait_q);
+}
+
+/* The caller must hold pcc_lock for write. */
+static void cppc_abort_pending_pcc_write(int pcc_ss_id,
+ struct cppc_pcc_data *pcc_ss_data,
+ int ret)
+{
+ if (!pcc_ss_data->pending_pcc_write_cmd)
+ return;
+
+ pcc_ss_data->pending_pcc_write_cmd = false;
+ cppc_complete_pcc_write(pcc_ss_id, pcc_ss_data, ret);
+}
+
/*
* This function transfers the ownership of the PCC to the platform
* So it must be called while holding write_lock(pcc_lock)
*/
static int send_pcc_cmd(int pcc_ss_id, u16 cmd)
{
- int ret = -EIO, i;
+ int ret = -EIO;
struct cppc_pcc_data *pcc_ss_data = pcc_data[pcc_ss_id];
struct acpi_pcct_shared_memory __iomem *generic_comm_base =
pcc_ss_data->pcc_channel->shmem;
@@ -431,21 +1554,8 @@ static int send_pcc_cmd(int pcc_ss_id, u16 cmd)
mbox_client_txdone(pcc_ss_data->pcc_channel->mchan, ret);
end:
- if (cmd == CMD_WRITE) {
- if (unlikely(ret)) {
- for_each_possible_cpu(i) {
- struct cpc_desc *desc = per_cpu(cpc_desc_ptr, i);
-
- if (!desc)
- continue;
-
- if (desc->write_cmd_id == pcc_ss_data->pcc_write_cnt)
- desc->write_cmd_status = ret;
- }
- }
- pcc_ss_data->pcc_write_cnt++;
- wake_up_all(&pcc_ss_data->pcc_write_wait_q);
- }
+ if (cmd == CMD_WRITE)
+ cppc_complete_pcc_write(pcc_ss_id, pcc_ss_data, ret);
return ret;
}
@@ -555,7 +1665,7 @@ bool cppc_allow_fast_switch(const struct cpumask *cpus)
min_reg = &cpc_ptr->cpc_regs[MIN_PERF];
max_reg = &cpc_ptr->cpc_regs[MAX_PERF];
- if (!CPC_SUPPORTED(desired_reg) ||
+ if (!cpc_is_writable(desired_reg) ||
(!CPC_IN_SYSTEM_MEMORY(desired_reg) &&
!CPC_IN_SYSTEM_IO(desired_reg)) ||
(CPC_SUPPORTED(min_reg) &&
@@ -643,35 +1753,49 @@ EXPORT_SYMBOL_GPL(acpi_get_psd_map);
static int register_pcc_channel(int pcc_ss_idx)
{
+ struct cppc_pcc_data *data;
struct pcc_mbox_chan *pcc_chan;
u64 usecs_lat;
+ int ret = 0;
- if (pcc_ss_idx >= 0) {
- pcc_chan = pcc_mbox_request_channel(&cppc_mbox_cl, pcc_ss_idx);
-
- if (IS_ERR(pcc_chan)) {
- pr_err("Failed to find PCC channel for subspace %d\n",
- pcc_ss_idx);
- return -ENODEV;
- }
+ if (pcc_ss_idx < 0 || pcc_ss_idx >= MAX_PCC_SUBSPACES)
+ return -EINVAL;
- pcc_data[pcc_ss_idx]->pcc_channel = pcc_chan;
- /*
- * cppc_ss->latency is just a Nominal value. In reality
- * the remote processor could be much slower to reply.
- * So add an arbitrary amount of wait on top of Nominal.
- */
- usecs_lat = NUM_RETRIES * pcc_chan->latency;
- pcc_data[pcc_ss_idx]->deadline_us = usecs_lat;
- pcc_data[pcc_ss_idx]->pcc_mrtt = pcc_chan->min_turnaround_time;
- pcc_data[pcc_ss_idx]->pcc_mpar = pcc_chan->max_access_rate;
- pcc_data[pcc_ss_idx]->pcc_nominal = pcc_chan->latency;
+ mutex_lock(&pcc_data_lock);
+ data = pcc_data[pcc_ss_idx];
+ if (!data) {
+ ret = -ENODEV;
+ goto out_unlock;
+ }
+ if (data->pcc_channel_acquired)
+ goto out_unlock;
- /* Set flag so that we don't come here for each CPU. */
- pcc_data[pcc_ss_idx]->pcc_channel_acquired = true;
+ pcc_chan = pcc_mbox_request_channel(&cppc_mbox_cl, pcc_ss_idx);
+ if (IS_ERR(pcc_chan)) {
+ ret = -ENODEV;
+ goto out_unlock;
}
- return 0;
+ data->pcc_channel = pcc_chan;
+ /*
+ * cppc_ss->latency is just a Nominal value. In reality
+ * the remote processor could be much slower to reply.
+ * So add an arbitrary amount of wait on top of Nominal.
+ */
+ usecs_lat = NUM_RETRIES * pcc_chan->latency;
+ data->deadline_us = usecs_lat;
+ data->pcc_mrtt = pcc_chan->min_turnaround_time;
+ data->pcc_mpar = pcc_chan->max_access_rate;
+ data->pcc_nominal = pcc_chan->latency;
+ init_rwsem(&data->pcc_lock);
+ init_waitqueue_head(&data->pcc_write_wait_q);
+
+ /* Reuse this channel when another CPU references the same subspace. */
+ data->pcc_channel_acquired = true;
+
+out_unlock:
+ mutex_unlock(&pcc_data_lock);
+ return ret;
}
/**
@@ -713,19 +1837,50 @@ bool __weak cpc_supported_by_cpu(void)
*/
static int pcc_data_alloc(int pcc_ss_id)
{
+ struct cppc_pcc_data *data;
+ int ret = 0;
+
if (pcc_ss_id < 0 || pcc_ss_id >= MAX_PCC_SUBSPACES)
return -EINVAL;
- if (pcc_data[pcc_ss_id]) {
- pcc_data[pcc_ss_id]->refcount++;
- } else {
- pcc_data[pcc_ss_id] = kzalloc_obj(struct cppc_pcc_data);
- if (!pcc_data[pcc_ss_id])
- return -ENOMEM;
- pcc_data[pcc_ss_id]->refcount++;
+ mutex_lock(&pcc_data_lock);
+ data = pcc_data[pcc_ss_id];
+ if (!data) {
+ data = kzalloc_obj(struct cppc_pcc_data);
+ if (!data) {
+ ret = -ENOMEM;
+ goto out_unlock;
+ }
+ raw_spin_lock_init(&data->payload_lock);
+ pcc_data[pcc_ss_id] = data;
}
+ data->refcount++;
- return 0;
+out_unlock:
+ mutex_unlock(&pcc_data_lock);
+ return ret;
+}
+
+static void pcc_data_put(int pcc_ss_id)
+{
+ struct cppc_pcc_data *data;
+
+ if (pcc_ss_id < 0 || pcc_ss_id >= MAX_PCC_SUBSPACES)
+ return;
+
+ mutex_lock(&pcc_data_lock);
+ data = pcc_data[pcc_ss_id];
+ if (!data || --data->refcount)
+ goto out_unlock;
+
+ pcc_data[pcc_ss_id] = NULL;
+ if (data->pcc_channel_acquired)
+ pcc_mbox_free_channel(data->pcc_channel);
+
+ kfree(data);
+
+out_unlock:
+ mutex_unlock(&pcc_data_lock);
}
/*
@@ -772,9 +1927,24 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
struct device *cpu_dev;
acpi_handle handle = pr->handle;
unsigned int num_ent, i, cpc_rev;
+ u32 unsupported_regs = 0;
+ u32 platform_quirks;
int pcc_subspace_id = -1;
+ bool pcc_data_ref = false;
+ bool cpc_present = false;
acpi_status status;
- int ret = -ENODATA;
+ int ret = -EINVAL;
+ int err;
+
+ if (per_cpu(cpc_desc_ptr, pr->id))
+ return 0;
+ ret = cpc_get_platform_quirks(&platform_quirks);
+ if (ret) {
+ pr_err("CPU%d: failed to match CPPC platform quirks: %d\n",
+ pr->id, ret);
+ return ret;
+ }
+ per_cpu(cpu_pcc_subspace_idx, pr->id) = -1;
if (!osc_sb_cppc2_support_acked) {
pr_debug("CPPC v2 _OSC not acked\n");
@@ -791,24 +1961,35 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
ret = -ENODEV;
goto out_buf_free;
}
+ cpc_present = true;
+ ret = -EINVAL;
out_obj = (union acpi_object *) output.pointer;
+ if (out_obj->package.count < 2) {
+ pr_debug("Unexpected _CPC package count (%u) for CPU:%d\n",
+ out_obj->package.count, pr->id);
+ goto out_buf_free;
+ }
cpc_ptr = kzalloc_obj(struct cpc_desc);
if (!cpc_ptr) {
ret = -ENOMEM;
goto out_buf_free;
}
+ cpc_ptr->cpu_id = pr->id;
/* First entry is NumEntries. */
cpc_obj = &out_obj->package.elements[0];
if (cpc_obj->type == ACPI_TYPE_INTEGER) {
- num_ent = cpc_obj->integer.value;
- if (num_ent <= 1) {
- pr_debug("Unexpected _CPC NumEntries value (%d) for CPU:%d\n",
- num_ent, pr->id);
+ if (cpc_obj->integer.value < 2 ||
+ cpc_obj->integer.value > out_obj->package.count) {
+ pr_debug("Invalid _CPC NumEntries (%llu) for package count (%u) on CPU:%d\n",
+ cpc_obj->integer.value, out_obj->package.count,
+ pr->id);
goto out_free;
}
+
+ num_ent = cpc_obj->integer.value;
} else {
pr_debug("Unexpected _CPC NumEntries entry type (%d) for CPU:%d\n",
cpc_obj->type, pr->id);
@@ -818,6 +1999,12 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
/* Second entry should be revision. */
cpc_obj = &out_obj->package.elements[1];
if (cpc_obj->type == ACPI_TYPE_INTEGER) {
+ if (cpc_obj->integer.value > U8_MAX) {
+ pr_debug("Invalid _CPC Revision (%llu) for CPU:%d\n",
+ cpc_obj->integer.value, pr->id);
+ ret = -EINVAL;
+ goto out_free;
+ }
cpc_rev = cpc_obj->integer.value;
} else {
pr_debug("Unexpected _CPC Revision entry type (%d) for CPU:%d\n",
@@ -857,11 +2044,45 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
cpc_obj = &out_obj->package.elements[i];
if (cpc_obj->type == ACPI_TYPE_INTEGER) {
- cpc_ptr->cpc_regs[i-2].type = ACPI_TYPE_INTEGER;
- cpc_ptr->cpc_regs[i-2].cpc_entry.int_value = cpc_obj->integer.value;
+ bool legacy_null;
+
+ if (!cpc_integer_entry_valid(i - 2,
+ cpc_obj->integer.value,
+ &legacy_null)) {
+ pr_debug("Invalid Integer _CPC register %u for CPU:%d\n",
+ i - 2, pr->id);
+ ret = -EINVAL;
+ goto out_free;
+ }
+ if (legacy_null)
+ pr_warn_once(FW_BUG "_CPC register %u uses Integer 0 for an absent Buffer\n",
+ i - 2);
+ cpc_ptr->cpc_regs[i - 2].type = ACPI_TYPE_INTEGER;
+ cpc_ptr->cpc_regs[i - 2].cpc_entry.int_value = cpc_obj->integer.value;
} else if (cpc_obj->type == ACPI_TYPE_BUFFER) {
+ if (cpc_obj->buffer.length < sizeof(*gas_t)) {
+ pr_debug("Invalid register descriptor for CPU:%d\n",
+ pr->id);
+ ret = -EINVAL;
+ goto out_free;
+ }
+
gas_t = (struct cpc_reg *)
cpc_obj->buffer.pointer;
+ if (gas_t->descriptor != CPC_GENERIC_REGISTER_DESCRIPTOR ||
+ gas_t->length != CPC_GENERIC_REGISTER_LENGTH) {
+ pr_debug("Invalid register resource for CPU:%d\n",
+ pr->id);
+ ret = -EINVAL;
+ goto out_free;
+ }
+
+ cpc_ptr->cpc_regs[i - 2].type = ACPI_TYPE_BUFFER;
+ memcpy(&cpc_ptr->cpc_regs[i - 2].cpc_entry.reg, gas_t,
+ sizeof(*gas_t));
+ gas_t = &cpc_ptr->cpc_regs[i - 2].cpc_entry.reg;
+ cpc_apply_platform_quirks(gas_t, i - 2,
+ platform_quirks);
/*
* The PCC Subspace index is encoded inside
@@ -870,65 +2091,142 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
* so extract it only once.
*/
if (gas_t->space_id == ACPI_ADR_SPACE_PLATFORM_COMM) {
+ /* These registers have no specified 32-bit upper bound. */
+ bool wide_write = i - 2 == PERF_LIMITED ||
+ i - 2 == ENABLE ||
+ i - 2 == AUTO_SEL_ENABLE;
+ bool write_width_supported = gas_t->bit_width == 8 ||
+ gas_t->bit_width == 16 ||
+ gas_t->bit_width == 32 ||
+ gas_t->bit_width == 64;
+ bool unsupported;
+
+ unsupported = !gas_t->bit_width ||
+ gas_t->bit_width > 64 ||
+ gas_t->bit_offset ||
+ gas_t->bit_width % 8 ||
+ (cpc_reg_is_writable(i - 2) &&
+ (!write_width_supported ||
+ (!wide_write && gas_t->bit_width > 32)));
+ if (unsupported) {
+ if (!cpc_retain_pcc_status(cpc_ptr, i - 2))
+ unsupported_regs |= BIT(i - 2);
+ continue;
+ }
+
if (pcc_subspace_id < 0) {
pcc_subspace_id = gas_t->access_width;
- if (pcc_data_alloc(pcc_subspace_id))
- goto out_free;
} else if (pcc_subspace_id != gas_t->access_width) {
pr_debug("Mismatched PCC ids in _CPC for CPU:%d\n",
pr->id);
+ ret = -EINVAL;
goto out_free;
}
+
+ if (!pcc_data_ref) {
+ err = pcc_data_alloc(pcc_subspace_id);
+ if (err) {
+ ret = err;
+ goto out_free;
+ }
+ pcc_data_ref = true;
+ }
} else if (gas_t->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
- if (gas_t->address) {
+ if (!IS_NULL_REG(gas_t)) {
void __iomem *addr;
size_t access_width;
+ err = cpc_validate_sysmem_reg(cpc_ptr, gas_t,
+ i - 2);
+ if (err) {
+ unsupported_regs |= BIT(i - 2);
+ continue;
+ }
+ if (!cpc_is_readable(&cpc_ptr->cpc_regs[i - 2]) &&
+ !cpc_is_writable(&cpc_ptr->cpc_regs[i - 2]))
+ continue;
+
if (!osc_cpc_flexible_adr_space_confirmed) {
pr_debug("Flexible address space capability not supported\n");
+ ret = -EOPNOTSUPP;
if (!cpc_supported_by_cpu())
goto out_free;
+ ret = -EINVAL;
}
- access_width = GET_BIT_WIDTH(gas_t) / 8;
+ access_width = cpc_reg_access_width(gas_t);
+ access_width /= 8;
addr = ioremap(gas_t->address, access_width);
- if (!addr)
+ if (!addr) {
+ ret = -ENOMEM;
goto out_free;
- cpc_ptr->cpc_regs[i-2].sys_mem_vaddr = addr;
+ }
+ cpc_ptr->cpc_regs[i - 2].sys_mem_vaddr = addr;
}
} else if (gas_t->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
- if (gas_t->access_width < 1 || gas_t->access_width > 3) {
- /*
- * 1 = 8-bit, 2 = 16-bit, and 3 = 32-bit.
- * SystemIO doesn't implement 64-bit
- * registers.
- */
- pr_debug("Invalid access width %d for SystemIO register in _CPC\n",
- gas_t->access_width);
- goto out_free;
+ u64 access_size;
+ const char *reason = "uses unsupported SystemIO geometry";
+ unsigned int access_width;
+ bool partial = false;
+ bool unsupported;
+
+ access_width = cpc_reg_access_width(gas_t);
+ unsupported = !IS_ENABLED(CONFIG_HAS_IOPORT);
+ if (unsupported)
+ reason = "requires unavailable SystemIO support";
+ else
+ unsupported = access_width != 8 &&
+ access_width != 16 &&
+ access_width != 32;
+ if (!unsupported) {
+ access_size = access_width / 8;
+ unsupported = !gas_t->bit_width ||
+ gas_t->bit_width > access_width ||
+ gas_t->bit_offset >= access_width ||
+ gas_t->bit_width > access_width -
+ gas_t->bit_offset;
+ partial = gas_t->bit_offset ||
+ gas_t->bit_width != access_width;
}
- if (gas_t->address & OVER_16BTS_MASK) {
- /* SystemIO registers use 16-bit integer addresses */
- pr_debug("Invalid IO port %llu for SystemIO register in _CPC\n",
- gas_t->address);
- goto out_free;
+ if (!unsupported) {
+ unsupported = (cpc_reg_is_writable(i - 2) &&
+ i - 2 != PERF_LIMITED &&
+ cpc_is_writable(&cpc_ptr->cpc_regs[i - 2]) &&
+ partial) ||
+ !cpc_reg_access_aligned(gas_t,
+ access_size) ||
+ gas_t->address >
+ U16_MAX - (access_size - 1);
+ }
+ if (unsupported) {
+ if (cpc_retain_sysio_status(cpc_ptr, i - 2))
+ continue;
+ pr_debug("CPU%d: _CPC register %u %s\n",
+ pr->id, i - 2, reason);
+ unsupported_regs |= BIT(i - 2);
+ continue;
+ }
+ if (i - 2 == PERF_LIMITED && partial) {
+ pr_warn_once("CPU%d: Performance Limited register cannot be cleared safely; keeping it readable\n",
+ cpc_ptr->cpu_id);
+ cpc_ptr->cpc_regs[i - 2].cpc_entry.write_unsupported = true;
}
if (!osc_cpc_flexible_adr_space_confirmed) {
pr_debug("Flexible address space capability not supported\n");
+ ret = -EOPNOTSUPP;
if (!cpc_supported_by_cpu())
goto out_free;
+ ret = -EINVAL;
}
} else {
if (gas_t->space_id != ACPI_ADR_SPACE_FIXED_HARDWARE || !cpc_ffh_supported()) {
/* Support only PCC, SystemMemory, SystemIO, and FFH type regs. */
pr_debug("Unsupported register type (%d) in _CPC\n",
gas_t->space_id);
+ ret = -EOPNOTSUPP;
goto out_free;
}
}
-
- cpc_ptr->cpc_regs[i-2].type = ACPI_TYPE_BUFFER;
- memcpy(&cpc_ptr->cpc_regs[i-2].cpc_entry.reg, gas_t, sizeof(*gas_t));
} else if (cpc_obj->type == ACPI_TYPE_PACKAGE && (i - 2) == RESOURCE_PRIORITY) {
/*
* ACPI 6.6, s8.4.6.1.2.7 defines Resource Priority as a
@@ -945,17 +2243,18 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
goto out_free;
}
}
- per_cpu(cpu_pcc_subspace_idx, pr->id) = pcc_subspace_id;
- /*
- * In CPPC v1, DESIRED_PERF is mandatory. In CPPC v2, it is optional
- * only when AUTO_SEL_ENABLE is supported.
- */
- if (!CPC_SUPPORTED(&cpc_ptr->cpc_regs[DESIRED_PERF]) &&
- (!osc_sb_cppc2_support_acked ||
- !CPC_SUPPORTED(&cpc_ptr->cpc_regs[AUTO_SEL_ENABLE])))
- pr_warn("Desired perf. register is mandatory if CPPC v2 is not supported "
- "or autonomous selection is disabled\n");
+ per_cpu(cpu_pcc_subspace_idx, pr->id) = pcc_data_ref ?
+ pcc_subspace_id : -1;
+
+ ret = cpc_resolve_unsupported(cpc_ptr, unsupported_regs);
+ if (ret)
+ goto out_free;
+ unsupported_regs = 0;
+
+ ret = cpc_validate_required_controls(cpc_ptr);
+ if (ret)
+ goto out_free;
/*
* Initialize the remaining cpc_regs as unsupported.
@@ -968,8 +2267,6 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
}
- /* Store CPU Logical ID */
- cpc_ptr->cpu_id = pr->id;
cpc_mark_rmw_lock_users(cpc_ptr);
raw_spin_lock_init(&cpc_ptr->rmw_lock);
@@ -978,16 +2275,43 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
if (ret)
goto out_free;
+ ret = cpc_register_sysmem_desc(cpc_ptr);
+ if (ret)
+ goto out_free;
+
/* Register PCC channel once for all PCC subspace ID. */
- if (pcc_subspace_id >= 0 && !pcc_data[pcc_subspace_id]->pcc_channel_acquired) {
+ if (pcc_data_ref) {
ret = register_pcc_channel(pcc_subspace_id);
+ if (ret) {
+ pr_err("Failed to find PCC channel for subspace %d\n",
+ pcc_subspace_id);
+ goto out_free;
+ }
+
+ cpc_validate_pcc_bounds(cpc_ptr, pcc_subspace_id,
+ pcc_data[pcc_subspace_id],
+ &unsupported_regs);
+
+ ret = cpc_resolve_unsupported(cpc_ptr, unsupported_regs);
if (ret)
goto out_free;
- init_rwsem(&pcc_data[pcc_subspace_id]->pcc_lock);
- init_waitqueue_head(&pcc_data[pcc_subspace_id]->pcc_write_wait_q);
+ /* A range-only status entry needs the channel only for bounds. */
+ if (!cpc_pcc_access_needed(cpc_ptr)) {
+ pcc_data_put(pcc_subspace_id);
+ pcc_data_ref = false;
+ per_cpu(cpu_pcc_subspace_idx, pr->id) = -1;
+ }
}
+ ret = cpc_validate_bound_controls(cpc_ptr);
+ if (ret)
+ goto out_free;
+
+ ret = cpc_register_non_mmio_desc(cpc_ptr);
+ if (ret)
+ goto out_free;
+
/* Everything looks okay */
pr_debug("Parsed CPC struct for CPU: %d\n", pr->id);
@@ -999,30 +2323,32 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr)
}
/* Plug PSD data into this CPU's CPC descriptor. */
- per_cpu(cpc_desc_ptr, pr->id) = cpc_ptr;
+ cpc_set_desc(pr->id, cpc_ptr);
ret = kobject_init_and_add(&cpc_ptr->kobj, &cppc_ktype, &cpu_dev->kobj,
"acpi_cppc");
if (ret) {
- per_cpu(cpc_desc_ptr, pr->id) = NULL;
+ cpc_set_desc(pr->id, NULL);
+ cpc_unregister_non_mmio_desc(cpc_ptr);
+ cpc_unregister_sysmem_desc(cpc_ptr);
kobject_put(&cpc_ptr->kobj);
- goto out_free;
+ goto out_pcc_put;
}
kfree(output.pointer);
return 0;
out_free:
- /* Free all the mapped sys mem areas for this CPU */
- for (i = 2; i < cpc_ptr->num_entries; i++) {
- void __iomem *addr = cpc_ptr->cpc_regs[i-2].sys_mem_vaddr;
+ cppc_free_desc(cpc_ptr);
- if (addr)
- iounmap(addr);
- }
- kfree(cpc_ptr);
+out_pcc_put:
+ if (pcc_data_ref)
+ pcc_data_put(pcc_subspace_id);
+ per_cpu(cpu_pcc_subspace_idx, pr->id) = -1;
out_buf_free:
+ if (cpc_present)
+ pr_err("CPU%d: failed to initialize _CPC: %d\n", pr->id, ret);
kfree(output.pointer);
return ret;
}
@@ -1037,34 +2363,24 @@ EXPORT_SYMBOL_GPL(acpi_cppc_processor_probe);
void acpi_cppc_processor_exit(struct acpi_processor *pr)
{
struct cpc_desc *cpc_ptr;
- unsigned int i;
- void __iomem *addr;
- int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, pr->id);
-
- if (pcc_ss_id >= 0 && pcc_data[pcc_ss_id]) {
- if (pcc_data[pcc_ss_id]->pcc_channel_acquired) {
- pcc_data[pcc_ss_id]->refcount--;
- if (!pcc_data[pcc_ss_id]->refcount) {
- pcc_mbox_free_channel(pcc_data[pcc_ss_id]->pcc_channel);
- kfree(pcc_data[pcc_ss_id]);
- pcc_data[pcc_ss_id] = NULL;
- }
- }
- }
+ int pcc_ss_id;
cpc_ptr = per_cpu(cpc_desc_ptr, pr->id);
- if (!cpc_ptr)
+ if (!cpc_ptr) {
+ per_cpu(cpu_pcc_subspace_idx, pr->id) = -1;
return;
-
- /* Free all the mapped sys mem areas for this CPU */
- for (i = 2; i < cpc_ptr->num_entries; i++) {
- addr = cpc_ptr->cpc_regs[i-2].sys_mem_vaddr;
- if (addr)
- iounmap(addr);
}
+ pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, pr->id);
+ cpc_set_desc(pr->id, NULL);
+ kobject_del(&cpc_ptr->kobj);
+ cpc_unregister_non_mmio_desc(cpc_ptr);
+ cpc_unregister_sysmem_desc(cpc_ptr);
+
+ pcc_data_put(pcc_ss_id);
+ per_cpu(cpu_pcc_subspace_idx, pr->id) = -1;
+
kobject_put(&cpc_ptr->kobj);
- kfree(cpc_ptr);
}
EXPORT_SYMBOL_GPL(acpi_cppc_processor_exit);
@@ -1123,23 +2439,34 @@ int __weak cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val)
static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val)
{
void __iomem *vaddr = NULL;
+ unsigned long flags;
+ u8 buf[sizeof(*val)];
+ unsigned int i;
int size;
int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu);
struct cpc_reg *reg = &reg_res->cpc_entry.reg;
+ if (!cpc_is_readable(reg_res))
+ return -EOPNOTSUPP;
+
if (reg_res->type == ACPI_TYPE_INTEGER) {
*val = reg_res->cpc_entry.int_value;
return 0;
}
*val = 0;
+ if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE)
+ return cpc_read_ffh(cpu, reg, val);
+
size = GET_BIT_WIDTH(reg);
- if (IS_ENABLED(CONFIG_HAS_IOPORT) &&
- reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
+ if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
u32 val_u32;
acpi_status status;
+ if (!IS_ENABLED(CONFIG_HAS_IOPORT))
+ return -EOPNOTSUPP;
+
status = acpi_os_read_port((acpi_io_address)reg->address,
&val_u32, size);
if (ACPI_FAILURE(status)) {
@@ -1148,20 +2475,33 @@ static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val)
return -EFAULT;
}
- *val = val_u32;
+ *val = MASK_VAL_READ(reg, val_u32);
return 0;
- } else if (reg->space_id == ACPI_ADR_SPACE_PLATFORM_COMM && pcc_ss_id >= 0) {
+ } else if (reg->space_id == ACPI_ADR_SPACE_PLATFORM_COMM) {
+ if (pcc_ss_id < 0 || !pcc_data[pcc_ss_id])
+ return -ENODEV;
+
/*
* For registers in PCC space, the register size is determined
* by the bit width field; the access size is used to indicate
* the PCC subspace id.
*/
vaddr = GET_PCC_VADDR(reg->address, pcc_ss_id);
- }
- else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
+ size = reg->bit_width / 8;
+ if (!size || size > sizeof(buf) || reg->bit_width % 8)
+ return -EFAULT;
+
+ raw_spin_lock_irqsave(&pcc_data[pcc_ss_id]->payload_lock, flags);
+ memcpy_fromio(buf, vaddr, size);
+ raw_spin_unlock_irqrestore(&pcc_data[pcc_ss_id]->payload_lock,
+ flags);
+
+ *val = 0;
+ for (i = 0; i < size; i++)
+ *val |= (u64)buf[i] << (i * 8);
+ return 0;
+ } else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
vaddr = reg_res->sys_mem_vaddr;
- else if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE)
- return cpc_read_ffh(cpu, reg, val);
else
return acpi_os_read_memory((acpi_physical_address)reg->address,
val, size);
@@ -1180,18 +2520,12 @@ static int cpc_read(int cpu, struct cpc_register_resource *reg_res, u64 *val)
*val = readq_relaxed(vaddr);
break;
default:
- if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
- pr_debug("Error: Cannot read %u bit width from system memory: 0x%llx\n",
- size, reg->address);
- } else if (reg->space_id == ACPI_ADR_SPACE_PLATFORM_COMM) {
- pr_debug("Error: Cannot read %u bit width from PCC for ss: %d\n",
- size, pcc_ss_id);
- }
+ pr_debug("Error: Cannot read %u bit width from system memory: 0x%llx\n",
+ size, reg->address);
return -EFAULT;
}
- if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
- *val = MASK_VAL_READ(reg, *val);
+ *val = MASK_VAL_READ(reg, *val);
return 0;
}
@@ -1203,17 +2537,28 @@ static int cpc_write(int cpu, struct cpc_register_resource *reg_res, u64 val)
u64 prev_val;
void __iomem *vaddr = NULL;
int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu);
- struct cpc_reg *reg = &reg_res->cpc_entry.reg;
+ struct cpc_reg *reg;
struct cpc_desc *cpc_desc;
unsigned long flags;
+ u8 buf[sizeof(val)];
+ unsigned int i;
bool locked = false;
+ if (!cpc_is_writable(reg_res))
+ return -EOPNOTSUPP;
+
+ reg = &reg_res->cpc_entry.reg;
+ if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE)
+ return cpc_write_ffh(cpu, reg, val);
+
size = GET_BIT_WIDTH(reg);
- if (IS_ENABLED(CONFIG_HAS_IOPORT) &&
- reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
+ if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
acpi_status status;
+ if (!IS_ENABLED(CONFIG_HAS_IOPORT))
+ return -EOPNOTSUPP;
+
status = acpi_os_write_port((acpi_io_address)reg->address,
(u32)val, size);
if (ACPI_FAILURE(status)) {
@@ -1223,60 +2568,72 @@ static int cpc_write(int cpu, struct cpc_register_resource *reg_res, u64 val)
}
return 0;
- } else if (reg->space_id == ACPI_ADR_SPACE_PLATFORM_COMM && pcc_ss_id >= 0) {
+ } else if (reg->space_id == ACPI_ADR_SPACE_PLATFORM_COMM) {
+ if (pcc_ss_id < 0 || !pcc_data[pcc_ss_id])
+ return -ENODEV;
+
/*
* For registers in PCC space, the register size is determined
* by the bit width field; the access size is used to indicate
* the PCC subspace id.
*/
vaddr = GET_PCC_VADDR(reg->address, pcc_ss_id);
- }
- else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
+ size = reg->bit_width / 8;
+ if (!size || size > sizeof(buf) || reg->bit_width % 8)
+ return -EFAULT;
+
+ for (i = 0; i < size; i++)
+ buf[i] = val >> (i * 8);
+
+ raw_spin_lock_irqsave(&pcc_data[pcc_ss_id]->payload_lock, flags);
+ memcpy_toio(vaddr, buf, size);
+ /* Publish every payload byte before another CPU can ring the doorbell. */
+ wmb();
+ raw_spin_unlock_irqrestore(&pcc_data[pcc_ss_id]->payload_lock,
+ flags);
+ return 0;
+ } else if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
vaddr = reg_res->sys_mem_vaddr;
- else if (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE)
- return cpc_write_ffh(cpu, reg, val);
else
return acpi_os_write_memory((acpi_physical_address)reg->address,
val, size);
- if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
- /*
- * The _CPC layout is immutable after probe. The precomputed flag
- * retains serialization for partial fields or overlapping access
- * units; standalone full-width registers avoid the lock.
- */
- locked = reg_res->cpc_entry.use_rmw_lock;
- if (locked) {
- cpc_desc = per_cpu(cpc_desc_ptr, cpu);
- if (!cpc_desc) {
- pr_debug("No CPC descriptor for CPU:%d\n", cpu);
- return -ENODEV;
- }
- raw_spin_lock_irqsave(&cpc_desc->rmw_lock, flags);
+ /* Partial fields and local overlaps use the descriptor lock. */
+ locked = reg_res->cpc_entry.use_rmw_lock;
+ if (locked) {
+ cpc_desc = per_cpu(cpc_desc_ptr, cpu);
+ if (!cpc_desc) {
+ pr_debug("No CPC descriptor for CPU:%d\n", cpu);
+ return -ENODEV;
}
+ raw_spin_lock_irqsave(&cpc_desc->rmw_lock, flags);
+ }
- if (reg->bit_offset || reg->bit_width != size) {
- switch (size) {
- case 8:
- prev_val = readb_relaxed(vaddr);
- break;
- case 16:
- prev_val = readw_relaxed(vaddr);
- break;
- case 32:
- prev_val = readl_relaxed(vaddr);
- break;
- case 64:
- prev_val = readq_relaxed(vaddr);
- break;
- default:
- if (locked)
- raw_spin_unlock_irqrestore(&cpc_desc->rmw_lock,
- flags);
- return -EFAULT;
- }
- val = MASK_VAL_WRITE(reg, prev_val, val);
+ if (reg->bit_offset || reg->bit_width != size) {
+ /*
+ * MASK_VAL_WRITE() discards the field's old bits, so undefined
+ * readback from a write-only field is not propagated.
+ */
+ switch (size) {
+ case 8:
+ prev_val = readb_relaxed(vaddr);
+ break;
+ case 16:
+ prev_val = readw_relaxed(vaddr);
+ break;
+ case 32:
+ prev_val = readl_relaxed(vaddr);
+ break;
+ case 64:
+ prev_val = readq_relaxed(vaddr);
+ break;
+ default:
+ if (locked)
+ raw_spin_unlock_irqrestore(&cpc_desc->rmw_lock,
+ flags);
+ return -EFAULT;
}
+ val = MASK_VAL_WRITE(reg, prev_val, val);
}
switch (size) {
@@ -1293,19 +2650,17 @@ static int cpc_write(int cpu, struct cpc_register_resource *reg_res, u64 val)
writeq_relaxed(val, vaddr);
break;
default:
- if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
- pr_debug("Error: Cannot write %u bit width to system memory: 0x%llx\n",
- size, reg->address);
- } else if (reg->space_id == ACPI_ADR_SPACE_PLATFORM_COMM) {
- pr_debug("Error: Cannot write %u bit width to PCC for ss: %d\n",
- size, pcc_ss_id);
- }
+ pr_debug("Error: Cannot write %u bit width to system memory: 0x%llx\n",
+ size, reg->address);
ret_val = -EFAULT;
break;
}
- if (locked)
+ if (locked) {
+ if (!ret_val)
+ mmiowb_set_pending();
raw_spin_unlock_irqrestore(&cpc_desc->rmw_lock, flags);
+ }
return ret_val;
}
@@ -1347,15 +2702,25 @@ static int cppc_get_reg_val(int cpu, enum cppc_regs reg_idx, u64 *val)
pr_debug("No CPC descriptor for CPU:%d\n", cpu);
return -ENODEV;
}
+ if (cpc_reg_is_write_only(cpc_desc, reg_idx))
+ return -EOPNOTSUPP;
reg = &cpc_desc->cpc_regs[reg_idx];
- if ((reg->type == ACPI_TYPE_INTEGER && IS_OPTIONAL_CPC_REG(reg_idx) &&
+ /*
+ * Desired and Performance Limited may be disabled despite not being
+ * generally optional.
+ */
+ if ((reg->type == ACPI_TYPE_INTEGER &&
+ (IS_OPTIONAL_CPC_REG(reg_idx) || reg_idx == DESIRED_PERF ||
+ reg_idx == PERF_LIMITED) &&
!reg->cpc_entry.int_value) || (reg->type != ACPI_TYPE_INTEGER &&
IS_NULL_REG(&reg->cpc_entry.reg))) {
pr_debug("CPC register is not supported\n");
return -EOPNOTSUPP;
}
+ if (!cpc_is_readable(reg))
+ return -EOPNOTSUPP;
if (CPC_IN_PCC(reg))
return cppc_get_reg_val_in_pcc(cpu, reg, val);
@@ -1366,23 +2731,33 @@ static int cppc_get_reg_val(int cpu, enum cppc_regs reg_idx, u64 *val)
static int cppc_set_reg_val_in_pcc(int cpu, struct cpc_register_resource *reg, u64 val)
{
int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu);
- struct cppc_pcc_data *pcc_ss_data = NULL;
+ struct cppc_pcc_data *pcc_ss_data;
int ret;
if (pcc_ss_id < 0) {
pr_debug("Invalid pcc_ss_id\n");
return -ENODEV;
}
+ pcc_ss_data = pcc_data[pcc_ss_id];
+ if (!pcc_ss_data)
+ return -ENODEV;
- ret = cpc_write(cpu, reg, val);
+ down_write(&pcc_ss_data->pcc_lock);
+
+ ret = check_pcc_chan(pcc_ss_id, false);
if (ret)
- return ret;
+ goto out;
- pcc_ss_data = pcc_data[pcc_ss_id];
+ ret = cpc_write(cpu, reg, val);
+ if (ret)
+ goto out;
- down_write(&pcc_ss_data->pcc_lock);
/* after writing CPC, transfer the ownership of PCC to platform */
ret = send_pcc_cmd(pcc_ss_id, CMD_WRITE);
+
+out:
+ if (ret)
+ cppc_abort_pending_pcc_write(pcc_ss_id, pcc_ss_data, ret);
up_write(&pcc_ss_data->pcc_lock);
return ret;
@@ -1400,8 +2775,13 @@ static int cppc_set_reg_val(int cpu, enum cppc_regs reg_idx, u64 val)
reg = &cpc_desc->cpc_regs[reg_idx];
+ /* Integer 1 describes autonomous selection that is always enabled. */
+ if (reg_idx == AUTO_SEL_ENABLE && reg->type == ACPI_TYPE_INTEGER &&
+ reg->cpc_entry.int_value == 1)
+ return val == 1 ? 0 : -EOPNOTSUPP;
+
/* if a register is writeable, it must be a buffer and not null */
- if ((reg->type != ACPI_TYPE_BUFFER) || IS_NULL_REG(&reg->cpc_entry.reg)) {
+ if (!cpc_is_writable(reg)) {
pr_debug("CPC register is not supported\n");
return -EOPNOTSUPP;
}
@@ -1412,11 +2792,6 @@ static int cppc_set_reg_val(int cpu, enum cppc_regs reg_idx, u64 val)
return cpc_write(cpu, reg, val);
}
-static bool cppc_desired_perf_readable(const struct cpc_desc *cpc_desc)
-{
- return cpc_desc->version < CPPC_V4_REV;
-}
-
/**
* cppc_get_desired_perf - Get the desired performance register value.
* @cpunum: CPU from which to get desired performance.
@@ -1427,15 +2802,6 @@ static bool cppc_desired_perf_readable(const struct cpc_desc *cpc_desc)
*/
int cppc_get_desired_perf(int cpunum, u64 *desired_perf)
{
- struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpunum);
-
- if (!cpc_desc)
- return -ENODEV;
-
- /* _CPC revision 4 no longer specifies Desired Performance as readable. */
- if (!cppc_desired_perf_readable(cpc_desc))
- return -EOPNOTSUPP;
-
return cppc_get_reg_val(cpunum, DESIRED_PERF, desired_perf);
}
EXPORT_SYMBOL_GPL(cppc_get_desired_perf);
@@ -1491,7 +2857,7 @@ int cppc_get_perf_caps(int cpunum, struct cppc_perf_caps *perf_caps)
struct cpc_register_resource *highest_reg, *lowest_reg,
*lowest_non_linear_reg, *nominal_reg, *reference_reg,
*guaranteed_reg, *low_freq_reg = NULL, *nom_freq_reg = NULL;
- u64 high, low, guaranteed, nom, ref, min_nonlinear,
+ u64 high, low, guaranteed = 0, nom, ref, min_nonlinear,
low_f = 0, nom_f = 0;
int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpunum);
struct cppc_pcc_data *pcc_ss_data = NULL;
@@ -1574,7 +2940,12 @@ int cppc_get_perf_caps(int cpunum, struct cppc_perf_caps *perf_caps)
goto out_err;
perf_caps->lowest_nonlinear_perf = min_nonlinear;
- if (!high || !low || !nom || !ref || !min_nonlinear) {
+ if (!high || !low || !nom || !ref || !min_nonlinear ||
+ high > U32_MAX || low > U32_MAX || guaranteed > U32_MAX ||
+ nom > U32_MAX || ref > U32_MAX || min_nonlinear > U32_MAX ||
+ high < nom || nom < min_nonlinear || min_nonlinear < low ||
+ (CPC_SUPPORTED(guaranteed_reg) &&
+ (guaranteed < low || guaranteed > nom))) {
ret = -EFAULT;
goto out_err;
}
@@ -1591,6 +2962,14 @@ int cppc_get_perf_caps(int cpunum, struct cppc_perf_caps *perf_caps)
if (ret)
goto out_err;
}
+ /* Require ordered anchors and a nonzero slope when frequencies differ. */
+ if (low_f > U32_MAX || nom_f > U32_MAX ||
+ (low_f && nom_f &&
+ (nom_f < low_f || nom < low ||
+ (nom_f != low_f && nom == low)))) {
+ ret = -EFAULT;
+ goto out_err;
+ }
perf_caps->lowest_freq = low_f;
perf_caps->nominal_freq = nom_f;
@@ -1613,6 +2992,9 @@ bool cppc_perf_ctrs_in_pcc_cpu(unsigned int cpu)
{
struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpu);
+ if (!cpc_desc)
+ return false;
+
return CPC_IN_PCC(&cpc_desc->cpc_regs[DELIVERED_CTR]) ||
CPC_IN_PCC(&cpc_desc->cpc_regs[REFERENCE_CTR]) ||
CPC_IN_PCC(&cpc_desc->cpc_regs[CTR_WRAP_TIME]);
@@ -1754,8 +3136,10 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable)
struct cpc_register_resource *auto_sel_reg;
struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpu);
struct cppc_pcc_data *pcc_ss_data = NULL;
- bool autosel_ffh_sysmem;
- bool epp_ffh_sysmem;
+ bool auto_sel_pcc;
+ bool auto_sel_non_pcc;
+ bool epp_pcc;
+ bool epp_non_pcc;
int ret;
if (!cpc_desc) {
@@ -1765,53 +3149,69 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable)
auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE];
epp_set_reg = &cpc_desc->cpc_regs[ENERGY_PERF];
+ if (!enable && auto_sel_reg->type == ACPI_TYPE_INTEGER &&
+ auto_sel_reg->cpc_entry.int_value == 1)
+ return -EOPNOTSUPP;
+
+ auto_sel_pcc = cpc_is_writable(auto_sel_reg) &&
+ CPC_IN_PCC(auto_sel_reg);
+ epp_pcc = cpc_is_writable(epp_set_reg) && CPC_IN_PCC(epp_set_reg);
- epp_ffh_sysmem = CPC_SUPPORTED(epp_set_reg) &&
- (CPC_IN_FFH(epp_set_reg) || CPC_IN_SYSTEM_MEMORY(epp_set_reg));
- autosel_ffh_sysmem = CPC_SUPPORTED(auto_sel_reg) &&
- (CPC_IN_FFH(auto_sel_reg) || CPC_IN_SYSTEM_MEMORY(auto_sel_reg));
+ auto_sel_non_pcc = cpc_is_writable(auto_sel_reg) && !auto_sel_pcc;
+ epp_non_pcc = cpc_is_writable(epp_set_reg) && !epp_pcc;
- if (CPC_IN_PCC(epp_set_reg) || CPC_IN_PCC(auto_sel_reg)) {
+ /* Complete fallible non-PCC writes before staging PCC data. */
+ if (auto_sel_non_pcc) {
+ ret = cpc_write(cpu, auto_sel_reg, enable);
+ if (ret)
+ return ret;
+ }
+ if (epp_non_pcc) {
+ ret = cpc_write(cpu, epp_set_reg, perf_ctrls->energy_perf);
+ if (ret)
+ return ret;
+ }
+
+ if (epp_pcc || auto_sel_pcc) {
if (pcc_ss_id < 0) {
pr_debug("Invalid pcc_ss_id for CPU:%d\n", cpu);
return -ENODEV;
}
- if (CPC_SUPPORTED(auto_sel_reg)) {
+ pcc_ss_data = pcc_data[pcc_ss_id];
+ if (!pcc_ss_data)
+ return -ENODEV;
+
+ down_write(&pcc_ss_data->pcc_lock);
+
+ ret = check_pcc_chan(pcc_ss_id, false);
+ if (ret)
+ goto out_unlock;
+
+ if (auto_sel_pcc) {
ret = cpc_write(cpu, auto_sel_reg, enable);
if (ret)
- return ret;
+ goto out_unlock;
}
- if (CPC_SUPPORTED(epp_set_reg)) {
+ if (epp_pcc) {
ret = cpc_write(cpu, epp_set_reg, perf_ctrls->energy_perf);
if (ret)
- return ret;
+ goto out_unlock;
}
- pcc_ss_data = pcc_data[pcc_ss_id];
-
- down_write(&pcc_ss_data->pcc_lock);
/* after writing CPC, transfer the ownership of PCC to platform */
ret = send_pcc_cmd(pcc_ss_id, CMD_WRITE);
- up_write(&pcc_ss_data->pcc_lock);
- } else if (osc_cpc_flexible_adr_space_confirmed &&
- (epp_ffh_sysmem || autosel_ffh_sysmem)) {
- if (autosel_ffh_sysmem) {
- ret = cpc_write(cpu, auto_sel_reg, enable);
- if (ret)
- return ret;
- }
- if (epp_ffh_sysmem) {
- ret = cpc_write(cpu, epp_set_reg,
- perf_ctrls->energy_perf);
- if (ret)
- return ret;
- }
+out_unlock:
+ if (ret)
+ cppc_abort_pending_pcc_write(pcc_ss_id, pcc_ss_data, ret);
+ up_write(&pcc_ss_data->pcc_lock);
+ } else if (epp_non_pcc || auto_sel_non_pcc) {
+ ret = 0;
} else {
- ret = -ENOTSUPP;
- pr_debug("_CPC in PCC/FFH/SystemMemory are not supported\n");
+ ret = -EOPNOTSUPP;
+ pr_debug("No writable EPP controls for CPU:%d\n", cpu);
}
return ret;
@@ -1925,6 +3325,28 @@ int cppc_get_auto_sel(int cpu, bool *enable)
EXPORT_SYMBOL_GPL(cppc_get_auto_sel);
/**
+ * cppc_auto_sel_is_immutable - Check for always-enabled autonomous selection.
+ * @cpu: CPU whose _CPC descriptor to check.
+ *
+ * Context: Process context.
+ * Return: true for Integer 1, false for a register or an absent descriptor.
+ */
+bool cppc_auto_sel_is_immutable(int cpu)
+{
+ struct cpc_desc *cpc_desc;
+ struct cpc_register_resource *reg;
+
+ guard(mutex)(&cpc_desc_lock);
+ cpc_desc = per_cpu(cpc_desc_ptr, cpu);
+ if (!cpc_desc)
+ return false;
+
+ reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE];
+ return reg->type == ACPI_TYPE_INTEGER && reg->cpc_entry.int_value == 1;
+}
+EXPORT_SYMBOL_GPL(cppc_auto_sel_is_immutable);
+
+/**
* cppc_set_auto_sel - Write autonomous selection register.
* @cpu : CPU to which to write register.
* @enable : the desired value of autonomous selection resiter to be updated.
@@ -1982,6 +3404,7 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
max_perf_reg = &cpc_desc->cpc_regs[MAX_PERF];
energy_perf_reg = &cpc_desc->cpc_regs[ENERGY_PERF];
auto_sel_reg = &cpc_desc->cpc_regs[AUTO_SEL_ENABLE];
+ perf_ctrls->min_perf_valid = false;
/* Are any of the regs PCC ?*/
if (CPC_IN_PCC(min_perf_reg) || CPC_IN_PCC(max_perf_reg) ||
@@ -2006,6 +3429,10 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
ret = cpc_read(cpu, max_perf_reg, &max);
if (ret)
goto out_err;
+ if (max > U32_MAX) {
+ ret = -EFAULT;
+ goto out_err;
+ }
}
perf_ctrls->max_perf = max;
@@ -2013,6 +3440,11 @@ int cppc_get_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
ret = cpc_read(cpu, min_perf_reg, &min);
if (ret)
goto out_err;
+ if (min > U32_MAX) {
+ ret = -EFAULT;
+ goto out_err;
+ }
+ perf_ctrls->min_perf_valid = true;
}
perf_ctrls->min_perf = min;
@@ -2052,7 +3484,9 @@ int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
struct cpc_register_resource *desired_reg, *min_perf_reg, *max_perf_reg;
int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu);
struct cppc_pcc_data *pcc_ss_data = NULL;
- bool regs_in_pcc;
+ bool desired_update, min_update, max_update;
+ bool desired_pcc, min_pcc, max_pcc, pcc_update;
+ bool pcc_layout, direct_layout, mixed_layout;
int ret = 0;
if (!cpc_desc) {
@@ -2063,54 +3497,162 @@ int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
desired_reg = &cpc_desc->cpc_regs[DESIRED_PERF];
min_perf_reg = &cpc_desc->cpc_regs[MIN_PERF];
max_perf_reg = &cpc_desc->cpc_regs[MAX_PERF];
- regs_in_pcc = CPC_IN_PCC(desired_reg) || CPC_IN_PCC(min_perf_reg) ||
- CPC_IN_PCC(max_perf_reg);
-
- /*
- * This is Phase-I where we want to write to CPC registers
- * -> We want all CPUs to be able to execute this phase in parallel
- *
- * Since read_lock can be acquired by multiple CPUs simultaneously we
- * achieve that goal here
- */
- if (regs_in_pcc) {
+ desired_update = cpc_is_writable(desired_reg);
+ min_update = cpc_is_writable(min_perf_reg) &&
+ (perf_ctrls->min_perf || perf_ctrls->min_perf_valid);
+ max_update = cpc_is_writable(max_perf_reg) &&
+ perf_ctrls->max_perf;
+ desired_pcc = desired_update && CPC_IN_PCC(desired_reg);
+ min_pcc = min_update && CPC_IN_PCC(min_perf_reg);
+ max_pcc = max_update && CPC_IN_PCC(max_perf_reg);
+ pcc_update = desired_pcc || min_pcc || max_pcc;
+ pcc_layout = (cpc_is_writable(desired_reg) && CPC_IN_PCC(desired_reg)) ||
+ (cpc_is_writable(min_perf_reg) && CPC_IN_PCC(min_perf_reg)) ||
+ (cpc_is_writable(max_perf_reg) && CPC_IN_PCC(max_perf_reg));
+ direct_layout = (cpc_is_writable(desired_reg) &&
+ !CPC_IN_PCC(desired_reg)) ||
+ (cpc_is_writable(min_perf_reg) &&
+ !CPC_IN_PCC(min_perf_reg)) ||
+ (cpc_is_writable(max_perf_reg) &&
+ !CPC_IN_PCC(max_perf_reg));
+ mixed_layout = pcc_layout && direct_layout;
+
+ if (mixed_layout || pcc_update) {
if (pcc_ss_id < 0) {
pr_debug("Invalid pcc_ss_id\n");
return -ENODEV;
}
pcc_ss_data = pcc_data[pcc_ss_id];
- down_read(&pcc_ss_data->pcc_lock); /* BEGIN Phase-I */
+ if (!pcc_ss_data)
+ return -ENODEV;
+ }
+
+ /*
+ * A mixed layout cannot batch fallible direct writes safely: another
+ * CPU's staged PCC values may no longer match if a direct write fails.
+ * Serialize the complete mixed transaction and drain an older batch
+ * before changing a direct control.
+ */
+ if (mixed_layout) {
+ down_write(&pcc_ss_data->pcc_lock);
+ if (pcc_ss_data->pending_pcc_write_cmd) {
+ ret = send_pcc_cmd(pcc_ss_id, CMD_WRITE);
+ if (ret)
+ goto out_mixed_unlock;
+ }
+
if (pcc_ss_data->platform_owns_pcc) {
ret = check_pcc_chan(pcc_ss_id, false);
- if (ret) {
- up_read(&pcc_ss_data->pcc_lock);
+ if (ret)
+ goto out_mixed_unlock;
+ }
+
+ if (desired_update && !desired_pcc) {
+ ret = cpc_write(cpu, desired_reg,
+ perf_ctrls->desired_perf);
+ if (ret)
+ goto out_mixed_unlock;
+ }
+ if (min_update && !min_pcc) {
+ ret = cpc_write(cpu, min_perf_reg,
+ perf_ctrls->min_perf);
+ if (ret)
+ goto out_mixed_unlock;
+ }
+ if (max_update && !max_pcc) {
+ ret = cpc_write(cpu, max_perf_reg,
+ perf_ctrls->max_perf);
+ if (ret)
+ goto out_mixed_unlock;
+ }
+
+ if (desired_pcc) {
+ ret = cpc_write(cpu, desired_reg,
+ perf_ctrls->desired_perf);
+ if (ret)
+ goto out_mixed_unlock;
+ }
+ if (min_pcc) {
+ ret = cpc_write(cpu, min_perf_reg,
+ perf_ctrls->min_perf);
+ if (ret)
+ goto out_mixed_unlock;
+ }
+ if (max_pcc) {
+ ret = cpc_write(cpu, max_perf_reg,
+ perf_ctrls->max_perf);
+ if (ret)
+ goto out_mixed_unlock;
+ }
+
+ if (pcc_update) {
+ WRITE_ONCE(pcc_ss_data->pending_pcc_write_cmd, true);
+ cpc_desc->write_cmd_id = pcc_ss_data->pcc_write_cnt;
+ cpc_desc->write_cmd_status = 0;
+ ret = send_pcc_cmd(pcc_ss_id, CMD_WRITE);
+ }
+
+out_mixed_unlock:
+ up_write(&pcc_ss_data->pcc_lock);
+ return ret;
+ }
+
+ /* A request without PCC updates has no payload to coordinate. */
+ if (!pcc_update) {
+ if (desired_update) {
+ ret = cpc_write(cpu, desired_reg,
+ perf_ctrls->desired_perf);
+ if (ret)
return ret;
- }
}
- /*
- * Update the pending_write to make sure a PCC CMD_READ will not
- * arrive and steal the channel during the switch to write lock
- */
- pcc_ss_data->pending_pcc_write_cmd = true;
- cpc_desc->write_cmd_id = pcc_ss_data->pcc_write_cnt;
- cpc_desc->write_cmd_status = 0;
+ if (min_update) {
+ ret = cpc_write(cpu, min_perf_reg,
+ perf_ctrls->min_perf);
+ if (ret)
+ return ret;
+ }
+ if (max_update)
+ ret = cpc_write(cpu, max_perf_reg,
+ perf_ctrls->max_perf);
+ return ret;
}
- if (CPC_SUPPORTED(desired_reg))
- cpc_write(cpu, desired_reg, perf_ctrls->desired_perf);
+ down_read(&pcc_ss_data->pcc_lock); /* BEGIN Phase-I */
+ if (pcc_ss_data->platform_owns_pcc) {
+ ret = check_pcc_chan(pcc_ss_id, false);
+ if (ret)
+ goto out_pcc_read_unlock;
+ }
/*
- * Only write if min_perf and max_perf not zero. Some drivers pass zero
- * value to min and max perf, but they don't mean to set the zero value,
- * they just don't want to write to those registers.
+ * This is Phase-I where we want to write to CPC registers
+ * -> We want all CPUs to be able to execute this phase in parallel
+ *
+ * Since read_lock can be acquired by multiple CPUs simultaneously we
+ * achieve that goal here.
*/
- if (perf_ctrls->min_perf && CPC_SUPPORTED(min_perf_reg))
- cpc_write(cpu, min_perf_reg, perf_ctrls->min_perf);
- if (perf_ctrls->max_perf && CPC_SUPPORTED(max_perf_reg))
- cpc_write(cpu, max_perf_reg, perf_ctrls->max_perf);
+ if (desired_pcc) {
+ ret = cpc_write(cpu, desired_reg, perf_ctrls->desired_perf);
+ if (ret)
+ goto out_pcc_read_unlock;
+ }
- if (regs_in_pcc)
- up_read(&pcc_ss_data->pcc_lock); /* END Phase-I */
+ if (min_pcc) {
+ ret = cpc_write(cpu, min_perf_reg, perf_ctrls->min_perf);
+ if (ret)
+ goto out_pcc_read_unlock;
+ }
+ if (max_pcc) {
+ ret = cpc_write(cpu, max_perf_reg, perf_ctrls->max_perf);
+ if (ret)
+ goto out_pcc_read_unlock;
+ }
+
+ /* Block a PCC read until the staged payload has been submitted. */
+ WRITE_ONCE(pcc_ss_data->pending_pcc_write_cmd, true);
+ cpc_desc->write_cmd_id = pcc_ss_data->pcc_write_cnt;
+ cpc_desc->write_cmd_status = 0;
+ up_read(&pcc_ss_data->pcc_lock); /* END Phase-I */
/*
* This is Phase-II where we transfer the ownership of PCC to Platform
*
@@ -2157,20 +3699,22 @@ int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls)
* case during a CMD_READ and if there are pending writes it delivers
* the write command before servicing the read command
*/
- if (regs_in_pcc) {
- if (down_write_trylock(&pcc_ss_data->pcc_lock)) {/* BEGIN Phase-II */
- /* Update only if there are pending write commands */
- if (pcc_ss_data->pending_pcc_write_cmd)
- send_pcc_cmd(pcc_ss_id, CMD_WRITE);
- up_write(&pcc_ss_data->pcc_lock); /* END Phase-II */
- } else
- /* Wait until pcc_write_cnt is updated by send_pcc_cmd */
- wait_event(pcc_ss_data->pcc_write_wait_q,
- cpc_desc->write_cmd_id != pcc_ss_data->pcc_write_cnt);
-
- /* send_pcc_cmd updates the status in case of failure */
- ret = cpc_desc->write_cmd_status;
+ if (down_write_trylock(&pcc_ss_data->pcc_lock)) {/* BEGIN Phase-II */
+ /* Update only if there are pending write commands */
+ if (pcc_ss_data->pending_pcc_write_cmd)
+ send_pcc_cmd(pcc_ss_id, CMD_WRITE);
+ up_write(&pcc_ss_data->pcc_lock); /* END Phase-II */
+ } else {
+ /* Wait until pcc_write_cnt is updated by send_pcc_cmd */
+ wait_event(pcc_ss_data->pcc_write_wait_q,
+ cpc_desc->write_cmd_id != pcc_ss_data->pcc_write_cnt);
}
+
+ /* send_pcc_cmd updates the status in case of failure */
+ return cpc_desc->write_cmd_status;
+
+out_pcc_read_unlock:
+ up_read(&pcc_ss_data->pcc_lock);
return ret;
}
EXPORT_SYMBOL_GPL(cppc_set_perf);
@@ -2194,7 +3738,7 @@ EXPORT_SYMBOL_GPL(cppc_get_perf_limited);
/**
* cppc_set_perf_limited() - Clear bits in the Performance Limited register.
* @cpu: CPU on which to write register.
- * @bits_to_clear: Bitmask of bits to clear in the perf_limited register.
+ * @bits_to_clear: Zero for no-op or CPPC_PERF_LIMITED_MASK to clear both bits.
*
* The Performance Limited register contains two sticky bits set by platform:
* - Bit 0 (Desired_Excursion): Set when delivered performance is constrained
@@ -2203,31 +3747,29 @@ EXPORT_SYMBOL_GPL(cppc_get_perf_limited);
* below minimum performance.
*
* These bits are sticky and remain set until OSPM explicitly clears them.
- * This function only allows clearing bits (the platform sets them).
+ * Selective clears are unsupported because they require an interlocked RMW.
*
* Return: 0 for success, -EINVAL for invalid bits, -EIO on register
* access failure, -EOPNOTSUPP if not supported.
*/
int cppc_set_perf_limited(int cpu, u64 bits_to_clear)
{
- u64 current_val, new_val;
- int ret;
-
/* Only bits 0 and 1 are valid */
- if (bits_to_clear & ~CPPC_PERF_LIMITED_MASK)
+ if (bits_to_clear & ~(u64)CPPC_PERF_LIMITED_MASK)
return -EINVAL;
if (!bits_to_clear)
return 0;
- ret = cppc_get_perf_limited(cpu, &current_val);
- if (ret)
- return ret;
-
- /* Clear the specified bits */
- new_val = current_val & ~bits_to_clear;
+ /*
+ * Writing zero clears both bits without depending on how a platform
+ * treats written ones. ACPI does not define the effect of writing one,
+ * so a selective clear cannot be implemented without an interlocked RMW.
+ */
+ if (bits_to_clear != CPPC_PERF_LIMITED_MASK)
+ return -EOPNOTSUPP;
- return cppc_set_reg_val(cpu, PERF_LIMITED, new_val);
+ return cppc_set_reg_val(cpu, PERF_LIMITED, 0);
}
EXPORT_SYMBOL_GPL(cppc_set_perf_limited);
@@ -2267,6 +3809,9 @@ int cppc_get_transition_latency(int cpu_num)
return -ENODATA;
desired_reg = &cpc_desc->cpc_regs[DESIRED_PERF];
+ if (!cpc_is_writable(desired_reg))
+ return -ENODATA;
+
if (CPC_IN_SYSTEM_MEMORY(desired_reg) || CPC_IN_SYSTEM_IO(desired_reg))
return 0;
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index aa55ecfc2923..76104f715efa 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -23,6 +23,8 @@
#include "fan.h"
#include "internal.h"
+#define ACPI_D_STATE_INVALID ACPI_D_STATE_COUNT
+
/**
* acpi_power_state_string - String representation of ACPI device power state.
* @state: ACPI device power state to return the string representation of.
@@ -75,15 +77,14 @@ static int acpi_dev_pm_explicit_get(struct acpi_device *device, int *state)
int acpi_device_get_power(struct acpi_device *device, int *state)
{
int result = ACPI_STATE_UNKNOWN;
- struct acpi_device *parent;
int error;
if (!device || !state)
return -EINVAL;
- parent = acpi_dev_parent(device);
-
if (!device->flags.power_manageable) {
+ struct acpi_device *parent = acpi_dev_parent(device);
+
/* TBD: Non-recursive algorithm for walking up hierarchy. */
*state = parent ? parent->power.state : ACPI_STATE_D0;
goto out;
@@ -119,16 +120,6 @@ int acpi_device_get_power(struct acpi_device *device, int *state)
result = psc > ACPI_STATE_D2 ? ACPI_STATE_D3_HOT : psc;
}
- /*
- * If we were unsure about the device parent's power state up to this
- * point, the fact that the device is in D0 implies that the parent has
- * to be in D0 too, except if ignore_parent is set.
- */
- if (!device->power.flags.ignore_parent && parent &&
- parent->power.state == ACPI_STATE_UNKNOWN &&
- result == ACPI_STATE_D0)
- parent->power.state = ACPI_STATE_D0;
-
*state = result;
out:
@@ -304,24 +295,28 @@ int acpi_bus_set_power(acpi_handle handle, int state)
}
EXPORT_SYMBOL(acpi_bus_set_power);
-int acpi_bus_init_power(struct acpi_device *device)
+static int acpi_device_init_power(struct acpi_device *device)
{
int state;
int result;
- if (!device)
- return -EINVAL;
-
- device->power.state = ACPI_STATE_UNKNOWN;
- if (!acpi_device_is_present(device)) {
- device->flags.initialized = false;
- return -ENXIO;
- }
-
result = acpi_device_get_power(device, &state);
if (result)
return result;
+ /*
+ * If the current power state of the device is D0 and it has a parent
+ * whose power state is not ignored, and the parent's power state
+ * initialization has failed, the parent's power state can be updated to
+ * D0 for consistency.
+ */
+ if (!device->power.flags.ignore_parent && state == ACPI_STATE_D0) {
+ struct acpi_device *parent = acpi_dev_parent(device);
+
+ if (parent && parent->power.state == ACPI_D_STATE_INVALID)
+ parent->power.state = ACPI_STATE_D0;
+ }
+
if (state < ACPI_STATE_D3_COLD && device->power.flags.power_resources) {
/* Reference count the power resources. */
result = acpi_power_on_resources(device, state);
@@ -351,9 +346,36 @@ int acpi_bus_init_power(struct acpi_device *device)
state = ACPI_STATE_D0;
}
device->power.state = state;
+
+ acpi_handle_debug(device->handle, "Initial power state: %s\n",
+ acpi_power_state_string(state));
+
return 0;
}
+int acpi_bus_init_power(struct acpi_device *device)
+{
+ int result;
+
+ if (device->power.state != ACPI_STATE_UNKNOWN)
+ return 0;
+
+ /*
+ * The ACPI device power state can be only initialized once. If this
+ * fails, ACPI power management will not be used for the device going
+ * forward.
+ */
+ result = acpi_device_init_power(device);
+ if (result) {
+ device->flags.power_manageable = 0;
+ device->power.state = ACPI_D_STATE_INVALID;
+ acpi_handle_info(device->handle,
+ "Initial power state undetermined, ACPI PM disabled\n");
+ }
+
+ return result;
+}
+
/**
* acpi_device_fix_up_power - Force device with missing _PSC into D0.
* @device: Device object whose power state is to be fixed up.
@@ -475,8 +497,13 @@ static int acpi_power_up_if_adr_present(struct acpi_device *adev, void *not_used
if (!(adev->flags.power_manageable && adev->pnp.type.bus_address))
return 0;
- acpi_handle_debug(adev->handle, "Power state: %s\n",
- acpi_power_state_string(adev->power.state));
+ /*
+ * This is done during the PCI root initialization which occurs before
+ * acpi_bus_attach() is called for the device, so the ACPI power state
+ * of the device needs to be initialized here.
+ */
+ if (acpi_bus_init_power(adev))
+ return 0;
if (adev->power.state == ACPI_STATE_D3_COLD)
return acpi_device_set_power(adev, ACPI_STATE_D0);
diff --git a/drivers/acpi/fan.h b/drivers/acpi/fan.h
index e20d6ad9df80..3faa247af514 100644
--- a/drivers/acpi/fan.h
+++ b/drivers/acpi/fan.h
@@ -52,7 +52,7 @@ struct acpi_fan_fst {
};
struct acpi_fan {
- acpi_handle handle;
+ struct acpi_device *adev;
bool acpi4;
bool has_fst;
struct acpi_fan_fif fif;
diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c
index 624d0736b581..3674f9613d40 100644
--- a/drivers/acpi/fan_core.c
+++ b/drivers/acpi/fan_core.c
@@ -54,8 +54,7 @@ MODULE_DEVICE_TABLE(acpi, fan_device_ids);
static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long
*state)
{
- struct acpi_device *device = cdev->devdata;
- struct acpi_fan *fan = acpi_driver_data(device);
+ struct acpi_fan *fan = cdev->devdata;
if (fan->acpi4) {
if (fan->fif.fine_grain_ctrl)
@@ -72,42 +71,34 @@ static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long
int acpi_fan_get_fst(acpi_handle handle, struct acpi_fan_fst *fst)
{
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
- union acpi_object *obj;
acpi_status status;
- int ret = 0;
status = acpi_evaluate_object(handle, "_FST", NULL, &buffer);
if (ACPI_FAILURE(status))
- return -EIO;
+ return -ENXIO;
- obj = buffer.pointer;
+ union acpi_object *obj __free(acpi_object_free) = buffer.pointer;
if (!obj)
return -ENODATA;
- if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count != 3) {
- ret = -EPROTO;
- goto err;
- }
+ if (obj->type != ACPI_TYPE_PACKAGE || obj->package.count != 3)
+ return -EPROTO;
if (obj->package.elements[0].type != ACPI_TYPE_INTEGER ||
obj->package.elements[1].type != ACPI_TYPE_INTEGER ||
- obj->package.elements[2].type != ACPI_TYPE_INTEGER) {
- ret = -EPROTO;
- goto err;
- }
+ obj->package.elements[2].type != ACPI_TYPE_INTEGER)
+ return -EPROTO;
fst->revision = obj->package.elements[0].integer.value;
fst->control = obj->package.elements[1].integer.value;
fst->speed = obj->package.elements[2].integer.value;
-err:
- kfree(obj);
- return ret;
+ return 0;
}
-static int fan_get_state_acpi4(struct acpi_device *device, unsigned long *state)
+static int fan_get_state_acpi4(struct acpi_fan *fan, unsigned long *state)
{
- struct acpi_fan *fan = acpi_driver_data(device);
+ struct acpi_device *device = fan->adev;
struct acpi_fan_fst fst;
int status, i;
@@ -159,13 +150,12 @@ static int fan_get_state(struct acpi_device *device, unsigned long *state)
static int fan_get_cur_state(struct thermal_cooling_device *cdev, unsigned long
*state)
{
- struct acpi_device *device = cdev->devdata;
- struct acpi_fan *fan = acpi_driver_data(device);
+ struct acpi_fan *fan = cdev->devdata;
if (fan->acpi4)
- return fan_get_state_acpi4(device, state);
+ return fan_get_state_acpi4(fan, state);
else
- return fan_get_state(device, state);
+ return fan_get_state(fan->adev, state);
}
static int fan_set_state(struct acpi_device *device, unsigned long state)
@@ -177,9 +167,9 @@ static int fan_set_state(struct acpi_device *device, unsigned long state)
state ? ACPI_STATE_D0 : ACPI_STATE_D3_COLD);
}
-static int fan_set_state_acpi4(struct acpi_device *device, unsigned long state)
+static int fan_set_state_acpi4(struct acpi_fan *fan, unsigned long state)
{
- struct acpi_fan *fan = acpi_driver_data(device);
+ struct acpi_device *device = fan->adev;
acpi_status status;
u64 value = state;
int max_state;
@@ -213,13 +203,12 @@ static int fan_set_state_acpi4(struct acpi_device *device, unsigned long state)
static int
fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
{
- struct acpi_device *device = cdev->devdata;
- struct acpi_fan *fan = acpi_driver_data(device);
+ struct acpi_fan *fan = cdev->devdata;
if (fan->acpi4)
- return fan_set_state_acpi4(device, state);
+ return fan_set_state_acpi4(fan, state);
else
- return fan_set_state(device, state);
+ return fan_set_state(fan->adev, state);
}
static const struct thermal_cooling_device_ops fan_cooling_ops = {
@@ -240,25 +229,22 @@ static int acpi_fan_get_fif(struct acpi_device *device)
struct acpi_buffer format = { sizeof("NNNN"), "NNNN" };
u64 fields[4];
struct acpi_buffer fif = { sizeof(fields), fields };
- union acpi_object *obj;
acpi_status status;
status = acpi_evaluate_object(device->handle, "_FIF", NULL, &buffer);
if (ACPI_FAILURE(status))
- return status;
+ return -ENXIO;
- obj = buffer.pointer;
+ union acpi_object *obj __free(acpi_object_free) = buffer.pointer;
if (!obj || obj->type != ACPI_TYPE_PACKAGE) {
dev_err(&device->dev, "Invalid _FIF data\n");
- status = -EINVAL;
- goto err;
+ return -ENODATA;
}
status = acpi_extract_package(obj, &format, &fif);
if (ACPI_FAILURE(status)) {
dev_err(&device->dev, "Invalid _FIF element\n");
- status = -EINVAL;
- goto err;
+ return -ENODATA;
}
fan->fif.revision = fields[0];
@@ -272,9 +258,8 @@ static int acpi_fan_get_fif(struct acpi_device *device)
/* If step size > 9, change to 9 (by spec valid values 1-9) */
else if (fan->fif.step_size > 9)
fan->fif.step_size = 9;
-err:
- kfree(obj);
- return status;
+
+ return 0;
}
static int acpi_fan_speed_cmp(const void *a, const void *b)
@@ -284,34 +269,28 @@ static int acpi_fan_speed_cmp(const void *a, const void *b)
return fps1->speed - fps2->speed;
}
-static int acpi_fan_get_fps(struct acpi_device *device)
+static int acpi_fan_get_fps(struct device *dev, struct acpi_device *device)
{
struct acpi_fan *fan = acpi_driver_data(device);
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
- union acpi_object *obj;
acpi_status status;
int i;
status = acpi_evaluate_object(device->handle, "_FPS", NULL, &buffer);
if (ACPI_FAILURE(status))
- return status;
+ return -ENXIO;
- obj = buffer.pointer;
+ union acpi_object *obj __free(acpi_object_free) = buffer.pointer;
if (!obj || obj->type != ACPI_TYPE_PACKAGE || obj->package.count < 2) {
dev_err(&device->dev, "Invalid _FPS data\n");
- status = -EINVAL;
- goto err;
+ return -ENODATA;
}
fan->fps_count = obj->package.count - 1; /* minus revision field */
- fan->fps = devm_kcalloc(&device->dev,
- fan->fps_count, sizeof(struct acpi_fan_fps),
- GFP_KERNEL);
- if (!fan->fps) {
- dev_err(&device->dev, "Not enough memory\n");
- status = -ENOMEM;
- goto err;
- }
+ fan->fps = devm_kcalloc(dev, fan->fps_count, sizeof(*fan->fps), GFP_KERNEL);
+ if (!fan->fps)
+ return -ENOMEM;
+
for (i = 0; i < fan->fps_count; i++) {
struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" };
struct acpi_buffer fps = { offsetof(struct acpi_fan_fps, name),
@@ -320,7 +299,7 @@ static int acpi_fan_get_fps(struct acpi_device *device)
&format, &fps);
if (ACPI_FAILURE(status)) {
dev_err(&device->dev, "Invalid _FPS element\n");
- goto err;
+ return -ENODATA;
}
}
@@ -328,9 +307,7 @@ static int acpi_fan_get_fps(struct acpi_device *device)
sort(fan->fps, fan->fps_count, sizeof(*fan->fps),
acpi_fan_speed_cmp, NULL);
-err:
- kfree(obj);
- return status;
+ return 0;
}
static int acpi_fan_dsm_init(struct device *dev)
@@ -343,30 +320,28 @@ static int acpi_fan_dsm_init(struct device *dev)
},
};
struct acpi_fan *fan = dev_get_drvdata(dev);
- union acpi_object *obj;
- int ret = 0;
+ acpi_handle fan_handle = fan->adev->handle;
- if (!acpi_check_dsm(fan->handle, &acpi_fan_microsoft_guid, 0,
+ if (!acpi_check_dsm(fan_handle, &acpi_fan_microsoft_guid, 0,
BIT(ACPI_FAN_DSM_GET_TRIP_POINT_GRANULARITY) |
BIT(ACPI_FAN_DSM_SET_TRIP_POINTS)))
return 0;
dev_info(dev, "Using Microsoft fan extensions\n");
- obj = acpi_evaluate_dsm_typed(fan->handle, &acpi_fan_microsoft_guid, 0,
- ACPI_FAN_DSM_GET_TRIP_POINT_GRANULARITY, &dummy,
- ACPI_TYPE_INTEGER);
+ union acpi_object *obj __free(acpi_object_free) =
+ acpi_evaluate_dsm_typed(fan_handle, &acpi_fan_microsoft_guid, 0,
+ ACPI_FAN_DSM_GET_TRIP_POINT_GRANULARITY,
+ &dummy, ACPI_TYPE_INTEGER);
if (!obj)
- return -EIO;
+ return -ENXIO;
if (obj->integer.value > U32_MAX)
- ret = -EOVERFLOW;
- else
- fan->fan_trip_granularity = obj->integer.value;
+ return -EOVERFLOW;
- kfree(obj);
+ fan->fan_trip_granularity = obj->integer.value;
- return ret;
+ return 0;
}
static int acpi_fan_dsm_set_trip_points(struct device *dev, u64 upper, u64 lower)
@@ -395,9 +370,9 @@ static int acpi_fan_dsm_set_trip_points(struct device *dev, u64 upper, u64 lower
};
union acpi_object *obj;
- obj = acpi_evaluate_dsm(fan->handle, &acpi_fan_microsoft_guid, 0,
- ACPI_FAN_DSM_SET_TRIP_POINTS, &in);
- kfree(obj);
+ obj = acpi_evaluate_dsm(fan->adev->handle, &acpi_fan_microsoft_guid,
+ 0, ACPI_FAN_DSM_SET_TRIP_POINTS, &in);
+ ACPI_FREE(obj);
return 0;
}
@@ -506,7 +481,7 @@ static int acpi_fan_probe(struct platform_device *pdev)
return -ENOMEM;
}
- fan->handle = device->handle;
+ fan->adev = device;
device->driver_data = fan;
platform_set_drvdata(pdev, fan);
@@ -522,7 +497,7 @@ static int acpi_fan_probe(struct platform_device *pdev)
if (result)
return result;
- result = acpi_fan_get_fps(device);
+ result = acpi_fan_get_fps(&pdev->dev, device);
if (result)
return result;
}
@@ -567,8 +542,7 @@ static int acpi_fan_probe(struct platform_device *pdev)
else
name = acpi_device_bid(device);
- cdev = thermal_cooling_device_register(name, device,
- &fan_cooling_ops);
+ cdev = thermal_cooling_device_create(&pdev->dev, name, fan, &fan_cooling_ops);
if (IS_ERR(cdev)) {
result = PTR_ERR(cdev);
goto err_end;
@@ -577,28 +551,9 @@ static int acpi_fan_probe(struct platform_device *pdev)
dev_dbg(&pdev->dev, "registered as cooling_device%d\n", cdev->id);
fan->cdev = cdev;
- result = sysfs_create_link(&pdev->dev.kobj,
- &cdev->device.kobj,
- "thermal_cooling");
- if (result) {
- dev_err(&pdev->dev, "Failed to create sysfs link 'thermal_cooling'\n");
- goto err_unregister;
- }
-
- result = sysfs_create_link(&cdev->device.kobj,
- &pdev->dev.kobj,
- "device");
- if (result) {
- dev_err(&pdev->dev, "Failed to create sysfs link 'device'\n");
- goto err_remove_link;
- }
return 0;
-err_remove_link:
- sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling");
-err_unregister:
- thermal_cooling_device_unregister(cdev);
err_end:
if (fan->has_fst)
acpi_fan_delete_attributes(device);
@@ -615,8 +570,6 @@ static void acpi_fan_remove(struct platform_device *pdev)
acpi_fan_delete_attributes(device);
}
- sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling");
- sysfs_remove_link(&fan->cdev->device.kobj, "device");
thermal_cooling_device_unregister(fan->cdev);
}
diff --git a/drivers/acpi/fan_hwmon.c b/drivers/acpi/fan_hwmon.c
index d3374f8f524b..c5d8419f41c5 100644
--- a/drivers/acpi/fan_hwmon.c
+++ b/drivers/acpi/fan_hwmon.c
@@ -94,7 +94,7 @@ static int acpi_fan_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
struct acpi_fan_fst fst;
int ret;
- ret = acpi_fan_get_fst(fan->handle, &fst);
+ ret = acpi_fan_get_fst(fan->adev->handle, &fst);
if (ret < 0)
return ret;
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index b1776809279d..0959f58cb77c 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -59,19 +59,37 @@ int unregister_acpi_bus_type(struct acpi_bus_type *type)
}
EXPORT_SYMBOL_GPL(unregister_acpi_bus_type);
-static struct acpi_bus_type *acpi_get_bus_type(struct device *dev)
+static struct acpi_device *acpi_companion_lookup(struct device *dev)
{
- struct acpi_bus_type *tmp, *ret = NULL;
+ struct acpi_bus_type *type;
- down_read(&bus_type_sem);
- list_for_each_entry(tmp, &bus_type_list, list) {
- if (tmp->match(dev)) {
- ret = tmp;
- break;
+ if (!dev->type)
+ return NULL;
+
+ guard(rwsem_read)(&bus_type_sem);
+
+ list_for_each_entry(type, &bus_type_list, list) {
+ struct acpi_device *adev;
+
+ if (!type->match(dev))
+ continue;
+
+ adev = type->find_companion(dev);
+ if (!adev) {
+ dev_dbg(dev, "ACPI companion not found\n");
+ return NULL;
}
+ if (acpi_bind_one(dev, adev)) {
+ dev_dbg(dev, "Binding to ACPI companion failed\n");
+ return NULL;
+ }
+ if (type->setup)
+ type->setup(dev);
+
+ return adev;
}
- up_read(&bus_type_sem);
- return ret;
+
+ return NULL;
}
#define FIND_CHILD_MIN_SCORE 1
@@ -228,31 +246,25 @@ static void acpi_physnode_link_name(char *buf, unsigned int node_id)
int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
{
struct acpi_device_physical_node *physical_node, *pn;
+ struct acpi_device *comp_dev = ACPI_COMPANION(dev);
char physical_node_name[PHYSICAL_NODE_NAME_SIZE];
struct list_head *physnode_list;
unsigned int node_id;
int retval = -EINVAL;
- if (has_acpi_companion(dev)) {
- if (acpi_dev) {
- dev_warn(dev, "ACPI companion already set\n");
+ if (!acpi_dev) {
+ if (!comp_dev)
return -EINVAL;
- } else {
- acpi_dev = ACPI_COMPANION(dev);
- }
- }
- if (!acpi_dev)
- return -EINVAL;
- acpi_dev_get(acpi_dev);
- get_device(dev);
- physical_node = kzalloc_obj(*physical_node);
- if (!physical_node) {
- retval = -ENOMEM;
- goto err;
+ /* If the companion has been set upfront, pick it up. */
+ acpi_dev = comp_dev;
+ } else if (comp_dev && acpi_dev != comp_dev) {
+ dev_warn(dev, "ACPI companion already set to %s which is not %s\n",
+ acpi_dev_name(comp_dev), acpi_dev_name(acpi_dev));
+ return -EEXIST;
}
- mutex_lock(&acpi_dev->physical_node_lock);
+ guard(mutex)(&acpi_dev->physical_node_lock);
/*
* Keep the list sorted by node_id so that the IDs of removed nodes can
@@ -263,15 +275,12 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
list_for_each_entry(pn, &acpi_dev->physical_node_list, node) {
/* Sanity check. */
if (pn->dev == dev) {
- mutex_unlock(&acpi_dev->physical_node_lock);
-
- dev_warn(dev, "Already associated with ACPI node\n");
- kfree(physical_node);
- if (ACPI_COMPANION(dev) != acpi_dev)
- goto err;
-
- put_device(dev);
- acpi_dev_put(acpi_dev);
+ if (!comp_dev) {
+ /* Really unexpected. */
+ ACPI_COMPANION_SET(dev, acpi_dev);
+ dev_warn(&acpi_dev->dev,
+ "Physical device list corruption fixed up\n");
+ }
return 0;
}
if (pn->node_id == node_id) {
@@ -280,12 +289,19 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
}
}
+ physical_node = kzalloc_obj(*physical_node);
+ if (!physical_node)
+ return -ENOMEM;
+
+ acpi_dev_get(acpi_dev);
+ get_device(dev);
+
physical_node->node_id = node_id;
physical_node->dev = dev;
list_add(&physical_node->node, physnode_list);
acpi_dev->physical_node_count++;
- if (!has_acpi_companion(dev))
+ if (!comp_dev)
ACPI_COMPANION_SET(dev, acpi_dev);
acpi_physnode_link_name(physical_node_name, node_id);
@@ -301,28 +317,20 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)
dev_err(dev, "Failed to create link firmware_node (%d)\n",
retval);
- mutex_unlock(&acpi_dev->physical_node_lock);
-
if (acpi_dev->wakeup.flags.valid)
device_set_wakeup_capable(dev, true);
return 0;
-
- err:
- ACPI_COMPANION_SET(dev, NULL);
- put_device(dev);
- acpi_dev_put(acpi_dev);
- return retval;
}
EXPORT_SYMBOL_GPL(acpi_bind_one);
-int acpi_unbind_one(struct device *dev)
+void acpi_unbind_one(struct device *dev)
{
struct acpi_device *acpi_dev = ACPI_COMPANION(dev);
struct acpi_device_physical_node *entry;
if (!acpi_dev)
- return 0;
+ return;
mutex_lock(&acpi_dev->physical_node_lock);
@@ -337,15 +345,17 @@ int acpi_unbind_one(struct device *dev)
sysfs_remove_link(&acpi_dev->dev.kobj, physnode_name);
sysfs_remove_link(&dev->kobj, "firmware_node");
ACPI_COMPANION_SET(dev, NULL);
+
+ mutex_unlock(&acpi_dev->physical_node_lock);
+
/* Drop references taken by acpi_bind_one(). */
put_device(dev);
acpi_dev_put(acpi_dev);
kfree(entry);
- break;
+ return;
}
mutex_unlock(&acpi_dev->physical_node_lock);
- return 0;
}
EXPORT_SYMBOL_GPL(acpi_unbind_one);
@@ -354,48 +364,29 @@ void acpi_device_notify(struct device *dev)
struct acpi_device *adev;
int ret;
+ /* ACPI devices have no ACPI companions. */
+ if (dev->bus == &acpi_bus_type)
+ return;
+
ret = acpi_bind_one(dev, NULL);
if (ret) {
- struct acpi_bus_type *type = acpi_get_bus_type(dev);
-
- if (!type)
- goto err;
-
- adev = type->find_companion(dev);
- if (!adev) {
- dev_dbg(dev, "ACPI companion not found\n");
- goto err;
- }
- ret = acpi_bind_one(dev, adev);
- if (ret)
- goto err;
-
- if (type->setup) {
- type->setup(dev);
- goto done;
- }
+ adev = acpi_companion_lookup(dev);
+ if (!adev)
+ return;
} else {
adev = ACPI_COMPANION(dev);
if (dev_is_pci(dev)) {
pci_acpi_setup(dev, adev);
- goto done;
} else if (dev_is_platform(dev)) {
acpi_configure_pmsi_domain(dev);
+
+ if (adev->handler && adev->handler->bind)
+ adev->handler->bind(dev);
}
}
- if (adev->handler && adev->handler->bind)
- adev->handler->bind(dev);
-
-done:
- acpi_handle_debug(ACPI_HANDLE(dev), "Bound to device %s\n",
- dev_name(dev));
-
- return;
-
-err:
- dev_dbg(dev, "No ACPI support\n");
+ dev_dbg(dev, "Bound to ACPI device %s\n", acpi_dev_name(adev));
}
void acpi_device_notify_remove(struct device *dev)
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 40f875b265a9..011da4ed6a80 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -157,6 +157,7 @@ void acpi_turn_off_unused_power_resources(void);
Device Power Management
-------------------------------------------------------------------------- */
int acpi_device_get_power(struct acpi_device *device, int *state);
+int acpi_bus_init_power(struct acpi_device *device);
int acpi_wakeup_device_init(void);
/* --------------------------------------------------------------------------
diff --git a/drivers/acpi/numa/hmat.c b/drivers/acpi/numa/hmat.c
index 9792dc394756..3006789ae31f 100644
--- a/drivers/acpi/numa/hmat.c
+++ b/drivers/acpi/numa/hmat.c
@@ -995,7 +995,7 @@ static int hmat_calculate_adistance(struct notifier_block *self,
return NOTIFY_STOP;
}
-static struct notifier_block hmat_adist_nb __meminitdata = {
+static struct notifier_block hmat_adist_nb = {
.notifier_call = hmat_calculate_adistance,
.priority = 100,
};
diff --git a/drivers/acpi/numa/srat.c b/drivers/acpi/numa/srat.c
index 5c407dc6401e..f5616830f5a9 100644
--- a/drivers/acpi/numa/srat.c
+++ b/drivers/acpi/numa/srat.c
@@ -111,7 +111,7 @@ int __init fix_pxm_node_maps(int max_nid)
for (j = 0; j <= max_nid; j++) {
if ((emu_nid_to_phys[j] == i) &&
WARN(node_to_pxm_map_copy[j] != PXM_INVAL,
- "Node %d is already binded to PXM %d\n",
+ "Node %d is already bound to PXM %d\n",
j, node_to_pxm_map_copy[j]))
return -1;
if (emu_nid_to_phys[j] == i) {
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index ed2162a97bd2..5b7aefb48eeb 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -159,7 +159,7 @@ void __printf(1, 0) acpi_os_vprintf(const char *fmt, va_list args)
{
static char buffer[512];
- vsprintf(buffer, fmt, args);
+ vsnprintf(buffer, sizeof(buffer), fmt, args);
#ifdef ENABLE_DEBUGGER
if (acpi_in_debugger) {
diff --git a/drivers/acpi/pfr_update.c b/drivers/acpi/pfr_update.c
index 9afd2c52fdbd..98ace679601b 100644
--- a/drivers/acpi/pfr_update.c
+++ b/drivers/acpi/pfr_update.c
@@ -422,7 +422,7 @@ free_acpi_buffer:
static long pfru_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
- struct pfru_update_cap_info cap_hdr;
+ struct pfru_update_cap_info cap_hdr = {};
struct pfru_device *pfru_dev = to_pfru_dev(file);
void __user *p = (void __user *)arg;
u32 rev;
diff --git a/drivers/acpi/power.c b/drivers/acpi/power.c
index 23a4e207a01e..c6955d1ad29d 100644
--- a/drivers/acpi/power.c
+++ b/drivers/acpi/power.c
@@ -1121,6 +1121,19 @@ static const struct dmi_system_id dmi_leave_unused_power_resources_on[] = {
}
},
+ {
+ /*
+ * Acer Swift 3 SF314-56G with NVIDIA MX250 suffers from the
+ * same ACPI power resource regression as the Thunderobot ZERO.
+ * The power resource controlling the dGPU is incorrectly turned off
+ * during initialization, causing the GPU to fall off the bus (D3cold).
+ */
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "Swift SF314-56G"),
+ }
+
+ },
{}
};
diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
index cdc2ae1632b2..bdd1529d79f0 100644
--- a/drivers/acpi/processor_driver.c
+++ b/drivers/acpi/processor_driver.c
@@ -164,7 +164,7 @@ static int __acpi_processor_start(struct acpi_device *device)
acpi_pss_perf_init(pr);
- result = acpi_processor_thermal_init(pr, device);
+ result = acpi_processor_thermal_init(pr);
if (result)
goto err_power_exit;
@@ -179,7 +179,7 @@ static int __acpi_processor_start(struct acpi_device *device)
return 0;
err_thermal_exit:
- acpi_processor_thermal_exit(pr, device);
+ acpi_processor_thermal_exit(pr);
err_power_exit:
acpi_processor_power_exit(pr);
return result;
@@ -203,7 +203,7 @@ static int acpi_processor_stop(struct device *dev)
acpi_cppc_processor_exit(pr);
- acpi_processor_thermal_exit(pr, device);
+ acpi_processor_thermal_exit(pr);
return 0;
}
diff --git a/drivers/acpi/processor_thermal.c b/drivers/acpi/processor_thermal.c
index c7b1dc5687ec..11036f0d2b94 100644
--- a/drivers/acpi/processor_thermal.c
+++ b/drivers/acpi/processor_thermal.c
@@ -235,15 +235,7 @@ static int
processor_get_max_state(struct thermal_cooling_device *cdev,
unsigned long *state)
{
- struct acpi_device *device = cdev->devdata;
- struct acpi_processor *pr;
-
- if (!device)
- return -EINVAL;
-
- pr = acpi_driver_data(device);
- if (!pr)
- return -EINVAL;
+ struct acpi_processor *pr = cdev->devdata;
*state = acpi_processor_max_state(pr);
return 0;
@@ -253,15 +245,7 @@ static int
processor_get_cur_state(struct thermal_cooling_device *cdev,
unsigned long *cur_state)
{
- struct acpi_device *device = cdev->devdata;
- struct acpi_processor *pr;
-
- if (!device)
- return -EINVAL;
-
- pr = acpi_driver_data(device);
- if (!pr)
- return -EINVAL;
+ struct acpi_processor *pr = cdev->devdata;
*cur_state = cpufreq_get_cur_state(pr->id);
if (pr->flags.throttling)
@@ -273,18 +257,10 @@ static int
processor_set_cur_state(struct thermal_cooling_device *cdev,
unsigned long state)
{
- struct acpi_device *device = cdev->devdata;
- struct acpi_processor *pr;
+ struct acpi_processor *pr = cdev->devdata;
int result = 0;
int max_pstate;
- if (!device)
- return -EINVAL;
-
- pr = acpi_driver_data(device);
- if (!pr)
- return -EINVAL;
-
max_pstate = cpufreq_get_max_state(pr->id);
if (state > acpi_processor_max_state(pr))
@@ -308,55 +284,21 @@ const struct thermal_cooling_device_ops processor_cooling_ops = {
.set_cur_state = processor_set_cur_state,
};
-int acpi_processor_thermal_init(struct acpi_processor *pr,
- struct acpi_device *device)
+int acpi_processor_thermal_init(struct acpi_processor *pr)
{
- int result = 0;
-
- pr->cdev = thermal_cooling_device_register("Processor", device,
- &processor_cooling_ops);
- if (IS_ERR(pr->cdev)) {
- result = PTR_ERR(pr->cdev);
- return result;
- }
-
- dev_dbg(&device->dev, "registered as cooling_device%d\n",
- pr->cdev->id);
+ pr->cdev = thermal_cooling_device_create(pr->dev, "Processor", pr,
+ &processor_cooling_ops);
+ if (IS_ERR(pr->cdev))
+ return PTR_ERR(pr->cdev);
- result = sysfs_create_link(&device->dev.kobj,
- &pr->cdev->device.kobj,
- "thermal_cooling");
- if (result) {
- dev_err(&device->dev,
- "Failed to create sysfs link 'thermal_cooling'\n");
- goto err_thermal_unregister;
- }
-
- result = sysfs_create_link(&pr->cdev->device.kobj,
- &device->dev.kobj,
- "device");
- if (result) {
- dev_err(&pr->cdev->device,
- "Failed to create sysfs link 'device'\n");
- goto err_remove_sysfs_thermal;
- }
+ dev_dbg(pr->dev, "registered as cooling_device%d\n", pr->cdev->id);
return 0;
-
-err_remove_sysfs_thermal:
- sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
-err_thermal_unregister:
- thermal_cooling_device_unregister(pr->cdev);
-
- return result;
}
-void acpi_processor_thermal_exit(struct acpi_processor *pr,
- struct acpi_device *device)
+void acpi_processor_thermal_exit(struct acpi_processor *pr)
{
- if (pr->cdev) {
- sysfs_remove_link(&device->dev.kobj, "thermal_cooling");
- sysfs_remove_link(&pr->cdev->device.kobj, "device");
+ if (!IS_ERR_OR_NULL(pr->cdev)) {
thermal_cooling_device_unregister(pr->cdev);
pr->cdev = NULL;
}
diff --git a/drivers/acpi/riscv/cppc.c b/drivers/acpi/riscv/cppc.c
index 42c1a9052470..4ea4ddedd91f 100644
--- a/drivers/acpi/riscv/cppc.c
+++ b/drivers/acpi/riscv/cppc.c
@@ -97,6 +97,7 @@ bool cpc_ffh_supported(void)
int cpc_read_ffh(int cpu, struct cpc_reg *reg, u64 *val)
{
struct sbi_cppc_data data;
+ int ret;
if (WARN_ON_ONCE(irqs_disabled()))
return -EPERM;
@@ -107,19 +108,27 @@ int cpc_read_ffh(int cpu, struct cpc_reg *reg, u64 *val)
data.reg = FFH_CPPC_SBI_REG(reg->address);
- smp_call_function_single(cpu, sbi_cppc_read, &data, 1);
+ ret = smp_call_function_single(cpu, sbi_cppc_read, &data, 1);
+ if (ret)
+ return ret;
+ if (data.ret.error)
+ return sbi_err_map_linux_errno(data.ret.error);
*val = data.ret.value;
- return (data.ret.error) ? sbi_err_map_linux_errno(data.ret.error) : 0;
+ return 0;
} else if (FFH_CPPC_TYPE(reg->address) == FFH_CPPC_CSR) {
data.reg = FFH_CPPC_CSR_NUM(reg->address);
- smp_call_function_single(cpu, cppc_ffh_csr_read, &data, 1);
+ ret = smp_call_function_single(cpu, cppc_ffh_csr_read, &data, 1);
+ if (ret)
+ return ret;
+ if (data.ret.error)
+ return data.ret.error;
*val = data.ret.value;
- return data.ret.error;
+ return 0;
}
return -EINVAL;
@@ -128,6 +137,7 @@ int cpc_read_ffh(int cpu, struct cpc_reg *reg, u64 *val)
int cpc_write_ffh(int cpu, struct cpc_reg *reg, u64 val)
{
struct sbi_cppc_data data;
+ int ret;
if (WARN_ON_ONCE(irqs_disabled()))
return -EPERM;
@@ -139,14 +149,18 @@ int cpc_write_ffh(int cpu, struct cpc_reg *reg, u64 val)
data.reg = FFH_CPPC_SBI_REG(reg->address);
data.val = val;
- smp_call_function_single(cpu, sbi_cppc_write, &data, 1);
+ ret = smp_call_function_single(cpu, sbi_cppc_write, &data, 1);
+ if (ret)
+ return ret;
return (data.ret.error) ? sbi_err_map_linux_errno(data.ret.error) : 0;
} else if (FFH_CPPC_TYPE(reg->address) == FFH_CPPC_CSR) {
data.reg = FFH_CPPC_CSR_NUM(reg->address);
data.val = val;
- smp_call_function_single(cpu, cppc_ffh_csr_write, &data, 1);
+ ret = smp_call_function_single(cpu, cppc_ffh_csr_write, &data, 1);
+ if (ret)
+ return ret;
return data.ret.error;
}
diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c
index 86b7c7975852..f10bbf13c242 100644
--- a/drivers/acpi/sbs.c
+++ b/drivers/acpi/sbs.c
@@ -318,7 +318,7 @@ static struct acpi_battery_reader state_readers[] = {
{0x0a, SMBUS_READ_WORD, offsetof(struct acpi_battery, rate_now)},
{0x0b, SMBUS_READ_WORD, offsetof(struct acpi_battery, rate_avg)},
{0x0f, SMBUS_READ_WORD, offsetof(struct acpi_battery, capacity_now)},
- {0x0e, SMBUS_READ_WORD, offsetof(struct acpi_battery, state_of_charge)},
+ {0x0d, SMBUS_READ_WORD, offsetof(struct acpi_battery, state_of_charge)},
{0x16, SMBUS_READ_WORD, offsetof(struct acpi_battery, state)},
};
@@ -639,10 +639,8 @@ static int acpi_sbs_probe(struct platform_device *pdev)
return -ENODEV;
sbs = kzalloc_obj(struct acpi_sbs);
- if (!sbs) {
- result = -ENOMEM;
- goto end;
- }
+ if (!sbs)
+ return -ENOMEM;
mutex_init(&sbs->lock);
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 163a3cccf197..30bfef67cbaa 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -20,6 +20,7 @@
#include <linux/kthread.h>
#include <linux/dmi.h>
#include <linux/dma-map-ops.h>
+#include <linux/pci.h>
#include <linux/platform_data/x86/apple.h>
#include <linux/pgtable.h>
#include <linux/crc32.h>
@@ -637,10 +638,9 @@ static struct acpi_device *handle_to_device(acpi_handle handle,
status = acpi_get_data_full(handle, acpi_scan_drop_device,
(void **)&adev, callback);
- if (ACPI_FAILURE(status) || !adev) {
- acpi_handle_debug(handle, "No context!\n");
+ if (ACPI_FAILURE(status) || !adev)
return NULL;
- }
+
return adev;
}
@@ -1143,8 +1143,7 @@ static void acpi_bus_get_power_flags(struct acpi_device *device)
device->power.states[ACPI_STATE_D3_COLD].flags.valid = 1;
}
- if (acpi_bus_init_power(device))
- device->flags.power_manageable = 0;
+ device->power.state = ACPI_STATE_UNKNOWN;
}
static void acpi_bus_get_flags(struct acpi_device *device)
@@ -2338,50 +2337,57 @@ static int acpi_scan_attach_handler(struct acpi_device *device)
static int acpi_bus_attach(struct acpi_device *device, void *first_pass)
{
bool skip = !first_pass && device->flags.visited;
+ struct pci_dev *pci;
acpi_handle ejd;
int ret;
if (skip)
goto ok;
+ device->flags.initialized = true;
+
if (ACPI_SUCCESS(acpi_bus_get_ejd(device->handle, &ejd)))
register_dock_dependent_device(device, ejd);
acpi_bus_get_status(device);
- /* Skip devices that are not ready for enumeration (e.g. not present) */
- if (!acpi_dev_ready_for_enumeration(device)) {
- device->flags.initialized = false;
+ /*
+ * If the given ACPI device object has been already associated with a
+ * PCI device found on the bus, its status is effectively "present and
+ * enabled", and dependencies are not tracked for PCI devices, so it is
+ * not necessary or even useful to check the device's readiness in that
+ * case.
+ */
+ pci = acpi_dev_get_pci_dev(device);
+ if (pci) {
+ acpi_handle_debug(device->handle, "PCI companion %s found\n",
+ pci_name(pci));
+
+ if (!acpi_device_is_present(device))
+ pci_info(pci, FW_BUG "ACPI status differs from reality\n");
+
+ pci_dev_put(pci);
+ } else if (!acpi_dev_ready_for_enumeration(device)) {
+ /* The device is not ready (e.g. not present), so skip it. */
acpi_device_clear_enumerated(device);
- device->flags.power_manageable = 0;
return 0;
}
+
if (device->handler)
goto ok;
acpi_ec_register_opregions(device);
- if (!device->flags.initialized) {
- device->flags.power_manageable =
- device->power.states[ACPI_STATE_D0].flags.valid;
- if (acpi_bus_init_power(device))
- device->flags.power_manageable = 0;
+ acpi_bus_init_power(device);
- device->flags.initialized = true;
- } else if (device->flags.visited) {
+ if (device->flags.visited)
goto ok;
- }
ret = acpi_scan_attach_handler(device);
if (ret < 0)
return 0;
- if (ret > 0 && !device->flags.enumeration_by_parent) {
- acpi_device_set_enumerated(device);
- goto ok;
- }
-
- if (device->pnp.type.platform_id || device->pnp.type.backlight ||
- device->flags.enumeration_by_parent)
+ if (device->flags.enumeration_by_parent ||
+ (!ret && (device->pnp.type.platform_id || device->pnp.type.backlight)))
acpi_default_enumeration(device);
else
acpi_device_set_enumerated(device);
diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index dd4a99f09efe..a99373547126 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -11,6 +11,7 @@
#include <linux/kernel.h>
#include <linux/kstrtox.h>
#include <linux/moduleparam.h>
+#include <linux/string.h>
#include "internal.h"
@@ -181,10 +182,10 @@ static int param_set_trace_method_name(const char *val,
/* This is a hack. We can't kmalloc in early boot. */
if (is_abs_path)
- strcpy(trace_method_name, val);
+ strscpy(trace_method_name, val, sizeof(trace_method_name));
else {
trace_method_name[0] = '\\';
- strcpy(trace_method_name+1, val);
+ strscpy(trace_method_name + 1, val, sizeof(trace_method_name) - 1);
}
/* Restore the original tracer state */
diff --git a/drivers/acpi/tables.c b/drivers/acpi/tables.c
index eb93c060426f..aaa1de79bccf 100644
--- a/drivers/acpi/tables.c
+++ b/drivers/acpi/tables.c
@@ -560,6 +560,9 @@ acpi_table_initrd_override(struct acpi_table_header *existing_table,
while (table_offset + ACPI_HEADER_SIZE <= all_tables_size) {
table = acpi_os_map_memory(acpi_tables_addr + table_offset,
ACPI_HEADER_SIZE);
+ if (!table)
+ return AE_NO_MEMORY;
+
if (table_offset + table->length > all_tables_size) {
acpi_os_unmap_memory(table, ACPI_HEADER_SIZE);
WARN_ON(1);
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index dd7666c176a0..13e9a3a79d92 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -564,17 +564,20 @@ static bool acpi_thermal_should_bind_cdev(struct thermal_zone_device *thermal,
struct cooling_spec *c)
{
struct acpi_thermal_trip *acpi_trip = trip->priv;
- struct acpi_device *cdev_adev = cdev->devdata;
+ struct device *parent = cdev->device.parent;
+ acpi_handle parent_handle;
int i;
- /* Skip critical and hot trips. */
- if (!acpi_trip)
+ /* Skip critical and hot trips and parentless cooling devices. */
+ if (!acpi_trip || !parent)
return false;
- for (i = 0; i < acpi_trip->devices.count; i++) {
- acpi_handle handle = acpi_trip->devices.handles[i];
+ parent_handle = ACPI_HANDLE(parent);
+ if (!parent_handle)
+ return false;
- if (acpi_fetch_acpi_dev(handle) == cdev_adev)
+ for (i = 0; i < acpi_trip->devices.count; i++) {
+ if (acpi_trip->devices.handles[i] == parent_handle)
return true;
}
@@ -738,7 +741,9 @@ static void acpi_thermal_aml_dependency_fix(struct acpi_thermal *tz)
*/
static void acpi_thermal_guess_offset(struct acpi_thermal *tz, long crit_temp)
{
- if (crit_temp != THERMAL_TEMP_INVALID && crit_temp % 5 == 1)
+ if (crit_temp != THERMAL_TEMP_INVALID && crit_temp % 5 == 0)
+ tz->kelvin_offset = 273000;
+ else if (crit_temp != THERMAL_TEMP_INVALID && crit_temp % 5 == 1)
tz->kelvin_offset = 273100;
else
tz->kelvin_offset = 273200;
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index d499b72574ab..7c584d490d6a 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -1069,19 +1069,26 @@ EXPORT_SYMBOL(acpi_dev_is_video_device);
* @plat: pointer to acpi_platform_list table terminated by a NULL entry
*
* Return the matched index if the system is found in the platform list.
- * Otherwise, return a negative error code.
+ * Return -ENODEV for no match, or another negative error code if a table
+ * header could not be read and no entry matched.
*/
int acpi_match_platform_list(const struct acpi_platform_list *plat)
{
struct acpi_table_header hdr;
+ acpi_status status;
+ int ret = -ENODEV;
int idx = 0;
if (acpi_disabled)
return -ENODEV;
for (; plat->oem_id[0]; plat++, idx++) {
- if (ACPI_FAILURE(acpi_get_table_header(plat->table, 0, &hdr)))
+ status = acpi_get_table_header(plat->table, 0, &hdr);
+ if (ACPI_FAILURE(status)) {
+ if (status != AE_NOT_FOUND)
+ ret = status == AE_NO_MEMORY ? -ENOMEM : -EIO;
continue;
+ }
if (strncmp(plat->oem_id, hdr.oem_id, ACPI_OEM_ID_SIZE))
continue;
@@ -1096,6 +1103,6 @@ int acpi_match_platform_list(const struct acpi_platform_list *plat)
return idx;
}
- return -ENODEV;
+ return ret;
}
EXPORT_SYMBOL(acpi_match_platform_list);
diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c
index e3b69f876d24..3037fd18d420 100644
--- a/drivers/acpi/video_detect.c
+++ b/drivers/acpi/video_detect.c
@@ -929,6 +929,14 @@ static const struct dmi_system_id video_detect_dmi_table[] = {
DMI_MATCH(DMI_PRODUCT_NAME, "Nitro AN515-46"),
},
},
+ {
+ .callback = video_detect_force_native,
+ /* Acer Nitro AN515-58 */
+ .matches = {
+ DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
+ DMI_MATCH(DMI_PRODUCT_NAME, "Nitro AN515-58"),
+ },
+ },
/*
* x86 android tablets which directly control the backlight through
diff --git a/drivers/acpi/x86/s2idle.c b/drivers/acpi/x86/s2idle.c
index b6b1dd76a06b..c278ea14c0b3 100644
--- a/drivers/acpi/x86/s2idle.c
+++ b/drivers/acpi/x86/s2idle.c
@@ -24,6 +24,34 @@
#ifdef CONFIG_SUSPEND
+static void acpi_setup_ixx_gpes(void)
+{
+ acpi_handle gpe_root;
+ unsigned int i;
+ char gpe_nr_str[5];
+
+ if (ACPI_FAILURE(acpi_get_handle(NULL, "\\_GPE", &gpe_root)))
+ return;
+
+ for (i = 0; i <= 0xff; i++) {
+ scnprintf(gpe_nr_str, sizeof(gpe_nr_str), "_I%02X", i);
+ if (!acpi_has_method(gpe_root, gpe_nr_str))
+ continue;
+
+ /*
+ * Enable the GPE if it has a handler method because marking it
+ * as wake-capable causes acpi_update_all_gpes() to skip it.
+ */
+ if (ACPI_FAILURE(acpi_enable_gpe_cond(NULL, i, ACPI_GPE_DISPATCH_METHOD)))
+ continue;
+
+ acpi_mark_gpe_for_wake(NULL, i);
+ acpi_set_gpe_wake_mask(NULL, i, ACPI_GPE_ENABLE);
+
+ pm_pr_dbg("ACPI: GPE0x%02x armed for wake via %s\n", i, gpe_nr_str);
+ }
+}
+
static bool sleep_no_lps0 __read_mostly;
module_param(sleep_no_lps0, bool, 0644);
MODULE_PARM_DESC(sleep_no_lps0, "Do not use the special LPS0 device interface");
@@ -649,6 +677,7 @@ void __init acpi_s2idle_setup(void)
{
acpi_scan_add_handler(&lps0_handler);
s2idle_set_ops(&acpi_s2idle_ops_lps0);
+ acpi_setup_ixx_gpes();
}
int acpi_register_lps0_dev(struct acpi_s2idle_dev_ops *arg)