From patchwork Tue May 6 14:10:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashwin Chaugule X-Patchwork-Id: 29709 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A4624202E6 for ; Tue, 6 May 2014 14:10:49 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rd18sf49607964iec.4 for ; Tue, 06 May 2014 07:10:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=OkwXXjyceXdLy22GUAuBUDTdlg+69oHqx1w7bxyBIAE=; b=ifgNt/2GK4I7ATDf9IwT6eR5+BBZS2wLnScWBLHrqIhKAZB37GEs5ByVo//BJKysD1 6L5h934Tnyn/qXSuu4frot4UWYwdVPjcxoOwq9UoijHIhhwZtHCDivRIyesTtcfm75D/ 12dHoNQduXl6TjmI/Eoqoz/CXvvRCG7W5xHi1jECDxM6VuBF6RPWYPVjxl45DmAzIb8F Ta/b2bEoV3bUx57G+9/Vh1mMw3RTbpwJ+25EbpiOpEBEtl/USNJ5eIjg9TtYEqiPEnE6 /etekTXRnyOkVasOn+djeL6cBCG2189dAO30mwCxwp6kib7JrQC0w/0Hudh/O42DyMyP otcg== X-Gm-Message-State: ALoCoQnDVq5U4nLRxQbTX2mAMZ+nMjQaiM9dArJkiRUUC5gsCQjNLB8b5NPUQEEBCKtUfF1T9Uwu X-Received: by 10.182.75.193 with SMTP id e1mr1178444obw.1.1399385448089; Tue, 06 May 2014 07:10:48 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.86.146 with SMTP id p18ls1450958qgd.14.gmail; Tue, 06 May 2014 07:10:48 -0700 (PDT) X-Received: by 10.58.105.105 with SMTP id gl9mr33018531veb.3.1399385447976; Tue, 06 May 2014 07:10:47 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id db15si2035485vec.46.2014.05.06.07.10.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 06 May 2014 07:10:47 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id lc6so999965vcb.2 for ; Tue, 06 May 2014 07:10:47 -0700 (PDT) X-Received: by 10.58.154.10 with SMTP id vk10mr33671724veb.18.1399385447861; Tue, 06 May 2014 07:10:47 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp226877vcb; Tue, 6 May 2014 07:10:47 -0700 (PDT) X-Received: by 10.66.190.73 with SMTP id go9mr6820834pac.18.1399385447049; Tue, 06 May 2014 07:10:47 -0700 (PDT) Received: from mail-pd0-f169.google.com (mail-pd0-f169.google.com [209.85.192.169]) by mx.google.com with ESMTPS id hp1si12043023pad.467.2014.05.06.07.10.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 06 May 2014 07:10:46 -0700 (PDT) Received-SPF: none (google.com: ashwin.chaugule@linaro.org does not designate permitted sender hosts) client-ip=209.85.192.169; Received: by mail-pd0-f169.google.com with SMTP id z10so8247832pdj.0 for ; Tue, 06 May 2014 07:10:46 -0700 (PDT) X-Received: by 10.66.191.39 with SMTP id gv7mr6696300pac.150.1399385446490; Tue, 06 May 2014 07:10:46 -0700 (PDT) Received: from linaro5.qualcomm.com (rrcs-67-52-130-30.west.biz.rr.com. [67.52.130.30]) by mx.google.com with ESMTPSA id oa3sm615845pbb.15.2014.05.06.07.10.43 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 06 May 2014 07:10:45 -0700 (PDT) From: Ashwin Chaugule To: linaro-acpi@lists.linaro.org Cc: linda.knippers@hp.com, andanappa.mallikarjunappa.kori@hp.com, Thomas.Mingarelli@hp.com, Eden.Cardenas@hp.com, ilias.biris@linaro.org, patches@linaro.org, al.stone@linaro.org, hanjun.guo@linaro.org, graeme.gregory@linaro.org, andrea.gallo@linaro.org, Ashwin Chaugule Subject: [RFC 1/2] ACPI: Add support for Platform Communication Channel Date: Tue, 6 May 2014 10:10:31 -0400 Message-Id: <1399385432-22157-2-git-send-email-ashwin.chaugule@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1399385432-22157-1-git-send-email-ashwin.chaugule@linaro.org> References: <1399385432-22157-1-git-send-email-ashwin.chaugule@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ashwin.chaugule@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , ACPI 5.0a+ spec defines a generic mode of communication between the OS and a platform such as the BMC. This medium (PCC) is typically used by CPPC (ACPI CPU Performance management), RAS (ACPI reliability protocol) and MPST (ACPI Memory power states). This patch adds initial support for PCC to be usable by the aforementioned PCC clients. Signed-off-by: Ashwin Chaugule --- drivers/acpi/Kconfig | 10 +++ drivers/acpi/Makefile | 2 +- drivers/acpi/pcc.c | 194 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 drivers/acpi/pcc.c diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index cbc5dfc..8893fa5 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -361,6 +361,16 @@ config ACPI_REDUCED_HARDWARE_ONLY If you are unsure what to do, do not enable this option. +config ACPI_PCC + bool "ACPI Platform Communication Channel" + def_bool n + depends on ACPI + help + Enable this option if your platform supports PCC as defined in the + ACPI spec 5.0a+. PCC is a generic mechanism for the OS to communicate + with a platform such as a BMC. PCC is typically used by CPPC, RAS + and MPST. + source "drivers/acpi/apei/Kconfig" config ACPI_EXTLOG diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index fc133d4..d8aa613 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -74,7 +74,7 @@ obj-$(CONFIG_ACPI_HED) += hed.o obj-$(CONFIG_ACPI_EC_DEBUGFS) += ec_sys.o obj-$(CONFIG_ACPI_CUSTOM_METHOD)+= custom_method.o obj-$(CONFIG_ACPI_BGRT) += bgrt.o - +obj-$(CONFIG_ACPI_PCC) += pcc.o # processor has its own "processor." module_param namespace processor-y := processor_driver.o processor_throttling.o processor-y += processor_idle.o processor_thermal.o diff --git a/drivers/acpi/pcc.c b/drivers/acpi/pcc.c new file mode 100644 index 0000000..7961ad6 --- /dev/null +++ b/drivers/acpi/pcc.c @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2014 Linaro Ltd. + * Author: Ashwin Chaugule + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define MAX_PCC_SUBSPACES 256 +#define PCCS_SS_SIG_MAGIC 0x50434300 +#define GEN_SCI_SHIFT 0x15 +#define PCC_CMD_COMPLETE 0x1 + +/* Array of pointers to Type 0 Generic Communication Subspace Structures */ +struct acpi_pcct_subspace *pcc_ss_arr[MAX_PCC_SUBSPACES]; + +/* + * TODO: Serialize OSPM control flow per PCC channel. + */ +static DEFINE_SPINLOCK(pcc_lock); + +/* Total number of subspaces detected in PCCT. */ +static int total_ss; + +/* + * PCC clients call this function to get a base address of their + * Communication channel + */ +int get_pcc_comm_channel(u32 ss_idx, u64 __iomem *addr, int *len) +{ + struct acpi_pcct_subspace *pcct_subspace = pcc_ss_arr[ss_idx]; + + if (pcct_subspace) { + *addr = pcct_subspace->base_address; + *len = pcct_subspace->length; + } else + return -EINVAL; + + return 0; +} + +/* Send PCC cmd on behalf of this (subspace id) PCC client */ +u16 send_pcc_cmd(u8 cmd, u8 sci, u32 ss_idx, u64 __iomem *base_addr) +{ + struct acpi_pcct_subspace *pcct_subspace = pcc_ss_arr[ss_idx]; + struct acpi_pcct_shared_memory *generic_comm_base = + (struct acpi_pcct_shared_memory *)base_addr; + struct acpi_generic_address doorbell; + u16 pcc_cmd; + u64 doorbell_preserve; + u64 doorbell_val; + u64 doorbell_write; + /* + * Min time in usec that OSPM is expected to wait + * before sending the next PCC cmd. + */ + u16 cmd_delay = pcct_subspace->min_turnaround_time; + + if (!generic_comm_base) { + pr_err("No Generic Communication Channel provided.\n"); + return -EINVAL; + } + + spin_lock(&pcc_lock); + + /* TODO: Add support for SCI. */ + pcc_cmd |= cmd; + + /* Get doorbell details for this subspace. */ + doorbell = pcct_subspace->doorbell_register; + doorbell_preserve = pcct_subspace->preserve_mask; + doorbell_write = pcct_subspace->write_mask; + + /* Loop until CMD complete bit is set. For prev cmds. */ + while (!(ioread16(&generic_comm_base->status) & PCC_CMD_COMPLETE)) + udelay(cmd_delay); + + /* Write to the shared comm region. */ + iowrite16(cmd, &generic_comm_base->command); + + iowrite32((PCCS_SS_SIG_MAGIC | ss_idx), &generic_comm_base->signature); + + /* Flip CMD COMPLETE bit */ + /* TODO: When we add SCI support then preserve SCI status bit. */ + iowrite16(0, &generic_comm_base->status); + + /* Sync notification from OSPM to Platform. */ + acpi_read(&doorbell_val, &doorbell); + acpi_write((doorbell_val & doorbell_preserve) | doorbell_write, + &doorbell); + + /* Wait for Platform to consume. */ + while (!(ioread16(&generic_comm_base->status) & PCC_CMD_COMPLETE)) + udelay(cmd_delay); + + spin_unlock(&pcc_lock); + + /* PCC clients should check for ERR */ + return generic_comm_base->status; +} + +static int parse_pcc_subspace(struct acpi_subtable_header *header, + const unsigned long end) +{ + struct acpi_pcct_subspace *pcct_ss; + + pcct_ss = (struct acpi_pcct_subspace*) header; + + if (pcct_ss->header.type != ACPI_PCCT_TYPE_GENERIC_SUBSPACE) { + pr_err("Incorrect PCC Subspace type detected\n"); + return -EINVAL; + } + + /* TODO: Replace with idr API. */ + pcc_ss_arr[total_ss++] = pcct_ss; + + return 0; +} + +static int __init pcc_probe(void) +{ + acpi_status status = AE_OK; + acpi_size pcct_tbl_header_size; + struct acpi_table_pcct *pcct_tbl; + + /* Search for PCCT */ + status = acpi_get_table_with_size(ACPI_SIG_PCCT, 0, + (struct acpi_table_header **)&pcct_tbl, + &pcct_tbl_header_size); + + if (ACPI_SUCCESS(status) && !pcct_tbl) { + pr_warn("PCCT header not found.\n"); + status = AE_NOT_FOUND; + goto out_err; + } + + /* Found PCCT. Enumerate PCC subspaces. + * Currently there is only type of Subspace + * defined in the ACPI 5.0 spec. If there + * is more than one type, then we'll need + * to rework this to parse multiple types of + * subspaces. + */ + status = acpi_table_parse_entries(ACPI_SIG_PCCT, + sizeof(struct acpi_table_pcct), ACPI_PCCT_TYPE_GENERIC_SUBSPACE, + parse_pcc_subspace, MAX_PCC_SUBSPACES); + + if (ACPI_SUCCESS(status)) + pr_err("Error parsing PCC subspaces from PCCT\n"); + + pr_info("Detected %d PCC Subspaces\n", total_ss); + +out_err: + return (ACPI_SUCCESS(status) ? 1 : 0); +} + +static int __init pcc_init(void) +{ + int ret; + + if (acpi_disabled) + return -ENODEV; + + /* Check if PCC support is available. */ + ret = pcc_probe(); + + if (ret) { + pr_debug("PCC probe failed.\n"); + return -EINVAL; + } + + return ret; +} + +device_initcall(pcc_init);