From patchwork Fri Sep 15 17:28:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13387302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D917EED61A for ; Fri, 15 Sep 2023 17:29:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B8516B0361; Fri, 15 Sep 2023 13:29:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 968396B0362; Fri, 15 Sep 2023 13:29:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 809D16B0364; Fri, 15 Sep 2023 13:29:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 6F6746B0361 for ; Fri, 15 Sep 2023 13:29:08 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 47CC91A028C for ; Fri, 15 Sep 2023 17:29:08 +0000 (UTC) X-FDA: 81239517576.03.B261E4F Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf06.hostedemail.com (Postfix) with ESMTP id E72D1180021 for ; Fri, 15 Sep 2023 17:29:05 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694798946; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M5aUR/vlrRYmP7Pk4usIoxYK5h7qF6WXIovLVSg1Fgc=; b=R/f89gh2hGGsiCjRcOIcH4r5gzE9eoTkzMY2rNIURMT/L294M4ngrXgk7AdDVyqZ9MM3ql kaiGvaryUprokRKW6sfpMivIFV3UjDUb/0Rx1CVfKQQBxJ0Wvqm61j2xqctZGrGAV8fM0K aQUOhZZE3BxQk0WrsETxCfJ65tu98h0= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694798946; a=rsa-sha256; cv=none; b=QeDRPrI6WmcUyoDGaLI8c0s/LJCR1ONlyK0VE3kiG9ttipKiE28VgDCPQuMLkb5vhEwx9b XWp1E97TlQ6t2f8xdujynTOUz1w6YD1MNSm0I/zbzKgGdARkId6hB9hYYPp3EIAAfUKL0B CRZCQ5nI1FcL7uAOXVSWSC29NvLXbuM= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RnLkb2JTKz6K6CT; Sat, 16 Sep 2023 01:28:23 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 15 Sep 2023 18:29:03 +0100 From: To: , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH 1/9] memory: scrub: Add scrub driver supports configuring memory scrubbers in the system Date: Sat, 16 Sep 2023 01:28:10 +0800 Message-ID: <20230915172818.761-2-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20230915172818.761-1-shiju.jose@huawei.com> References: <20230915172818.761-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: E72D1180021 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 7rqz66apsc4gxmzkua4csmbyxj3ucrth X-HE-Tag: 1694798945-533532 X-HE-Meta: U2FsdGVkX1/0ia47T6isbflVvCMDoZDcvDQfUmPHPkuHfOyq6qpXX6PkKSQBlSxg1kzawCWfw184k6/0cVDTKBD4jMrunJkvaTUC7rMPCyoZ3yeS/x0/9sErpxI1SgFehOHhoALScN2bQtTcsUE2wWen3ftaO5TlShHiXnS81QINckzaP5/Xi+q+P/Yt9HgZ+DSYzfRoGjeOz3+R6UwDjyokDpk2wgexs9mY0xuOL1kEgPe2IY5KBGlW47DBTl0Ph/iHVxQUIsLFg8fn04AXCF/b01XjAjPAAUIFGYOrqIyy4A8U9uE/IixIbDhIe1+L+HsFQ8iDNTFOorQy2fhlvDIWnfk/aurC7xHs9opKpCYi2s4aDfV1mdxac35eyy43oEHSLfQ0V6VsBTtyT2326NopxvMwSg2GQ9gKc1/WudKg6c4xEaCMk+ptL9pebjr6Z3SZ5WOHJ0cqJP0XCbEB8uuj5ch/8Q3M3/vCHUob0HnDCJj2T+pCSKRnFCDItpnyAjw/tCkqq0PvMaXINdZ//+emXFlaOn4vrPSPu2iRU/otAasC3jYghGSVISt1VUXc/t0tK8Hchbjwtjcv37k2BtAVOS1T0S6KE+HS8FY9atxSCJ1Vn8A1jF4qPaofcFi+M0Y/ue5hSh4qfbB7Aa775Xk987OSI3neWp2C5eR/dgBSyrMtMlzxsdVWj+GlzFMMEa08FXJAMF2W/0DlUZUqV6ibJDYLhvh0DEw6eblB3SQ6mt0DaDggG2hnwE8HIe0tj9Qss6GV4AWQh5lM7HGXP9RCXinPzbORpnlUXyUSxqkmHcrYCMDofbJbwucZ8b23UtjkULwB2kQVk0NC406I/1R0P/ZTtokW1WsUZ4t8bAuVyasvHNxzZPMWksAWnjcEnlrrJyC0tsSkqTi/87s4+LWHJzRSk6y0cdipGvqsk/mcNvktXgm4mlzdVhKgvWOj3Vp6AwTA2MDVCbFrFfu eZJ8FRRy FPr8/Mx8/LMJr0Skup5/bXOAvMAHmgKeeTbB5QZE9Qnuf5NzUBBtZt8B3G0j0JeJpvA39ycQ9jmMLiVpmlHsQHgxa01qeycLWpFI2fjYN+pSFhsgOLnCW1l5mt/EUzQzvloCl5Qu3OkqGucM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Shiju Jose Add scrub driver supports configuring the memory scrubbers in the system. The scrub driver provides the interface for registering the scrub devices and to configure the parameters of memory scrubbers in the system. Driver exposes the scrub parameter attributes to the user via sysfs in /sys/class/scrub/scrubX/regionY/ This driver has been implemented based on the hwmon subsystem. Signed-off-by: Shiju Jose --- drivers/memory/Kconfig | 1 + drivers/memory/Makefile | 1 + drivers/memory/scrub/Kconfig | 11 + drivers/memory/scrub/Makefile | 6 + drivers/memory/scrub/memory-scrub.c | 452 ++++++++++++++++++++++++++++ include/memory/memory-scrub.h | 85 ++++++ 6 files changed, 556 insertions(+) create mode 100644 drivers/memory/scrub/Kconfig create mode 100644 drivers/memory/scrub/Makefile create mode 100755 drivers/memory/scrub/memory-scrub.c create mode 100755 include/memory/memory-scrub.h diff --git a/drivers/memory/Kconfig b/drivers/memory/Kconfig index 8efdd1f97139..d2e015c09d83 100644 --- a/drivers/memory/Kconfig +++ b/drivers/memory/Kconfig @@ -227,5 +227,6 @@ config STM32_FMC2_EBI source "drivers/memory/samsung/Kconfig" source "drivers/memory/tegra/Kconfig" +source "drivers/memory/scrub/Kconfig" endif diff --git a/drivers/memory/Makefile b/drivers/memory/Makefile index d2e6ca9abbe0..4b37312cb342 100644 --- a/drivers/memory/Makefile +++ b/drivers/memory/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_STM32_FMC2_EBI) += stm32-fmc2-ebi.o obj-$(CONFIG_SAMSUNG_MC) += samsung/ obj-$(CONFIG_TEGRA_MC) += tegra/ +obj-$(CONFIG_SCRUB) += scrub/ obj-$(CONFIG_TI_EMIF_SRAM) += ti-emif-sram.o obj-$(CONFIG_FPGA_DFL_EMIF) += dfl-emif.o diff --git a/drivers/memory/scrub/Kconfig b/drivers/memory/scrub/Kconfig new file mode 100644 index 000000000000..fa7d68f53a69 --- /dev/null +++ b/drivers/memory/scrub/Kconfig @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Memory scrub driver configurations +# + +config SCRUB + bool "Memory scrub driver" + help + This option selects the memory scrub subsystem, supports + configuring the parameters of underlying scrubbers in the + system for the DRAM memories. diff --git a/drivers/memory/scrub/Makefile b/drivers/memory/scrub/Makefile new file mode 100644 index 000000000000..1b677132ca13 --- /dev/null +++ b/drivers/memory/scrub/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for memory scrub drivers +# + +obj-$(CONFIG_SCRUB) += memory-scrub.o diff --git a/drivers/memory/scrub/memory-scrub.c b/drivers/memory/scrub/memory-scrub.c new file mode 100755 index 000000000000..b3011e7cd062 --- /dev/null +++ b/drivers/memory/scrub/memory-scrub.c @@ -0,0 +1,452 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Memory scrub controller driver support to configure + * the parameters of the memory scrubbers and enable. + * + * Copyright (c) 2023 HiSilicon Limited. + */ + +#define pr_fmt(fmt) "MEM SCRUB: " fmt + +#include +#include +#include +#include +#include +#include +#include + +/* memory scrubber config definitions */ +#define SCRUB_ID_PREFIX "scrub" +#define SCRUB_ID_FORMAT SCRUB_ID_PREFIX "%d" +#define SCRUB_DEV_MAX_NAME_LENGTH 128 + +static DEFINE_IDA(scrub_ida); + +struct scrub_device { + char name[SCRUB_DEV_MAX_NAME_LENGTH]; + int id; + struct device dev; + const struct scrub_source_info *source_info; + struct list_head tzdata; + char (*region_name)[]; + struct attribute_group group; + int ngroups; + struct attribute_group *region_groups; + const struct attribute_group **groups; +}; + +#define to_scrub_device(d) container_of(d, struct scrub_device, dev) +#define SCRUB_MAX_SYSFS_ATTR_NAME_LENGTH 64 + +struct scrub_device_attribute { + struct device_attribute dev_attr; + const struct scrub_ops *ops; + u32 attr; + int region_id; + char name[SCRUB_MAX_SYSFS_ATTR_NAME_LENGTH]; +}; + +#define to_scrub_attr(d) \ + container_of(d, struct scrub_device_attribute, dev_attr) +#define to_dev_attr(a) container_of(a, struct device_attribute, attr) + +static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + return sprintf(buf, "%s\n", to_scrub_device(dev)->name); +} +static DEVICE_ATTR_RO(name); + +static struct attribute *scrub_dev_attrs[] = { + &dev_attr_name.attr, + NULL +}; + +static umode_t scrub_dev_attr_is_visible(struct kobject *kobj, + struct attribute *attr, int n) +{ + struct device *dev = kobj_to_dev(kobj); + struct scrub_device *scrub_dev = to_scrub_device(dev); + + if (attr == &dev_attr_name.attr && scrub_dev->name == NULL) + return 0; + + return attr->mode; +} + +static const struct attribute_group scrub_dev_attr_group = { + .attrs = scrub_dev_attrs, + .is_visible = scrub_dev_attr_is_visible, +}; + +static const struct attribute_group *scrub_dev_attr_groups[] = { + &scrub_dev_attr_group, + NULL +}; + +static void scrub_free_attrs(struct attribute **attrs) +{ + int i; + + for (i = 0; attrs[i]; i++) { + struct device_attribute *dattr = to_dev_attr(attrs[i]); + struct scrub_device_attribute *hattr = to_scrub_attr(dattr); + + kfree(hattr); + } + kfree(attrs); +} + +static void scrub_dev_release(struct device *dev) +{ + int count; + struct attribute_group *group; + struct scrub_device *scrub_dev = to_scrub_device(dev); + + for (count = 0; count < scrub_dev->ngroups; count++) { + group = (struct attribute_group *)scrub_dev->groups[count]; + if (group) + scrub_free_attrs(group->attrs); + } + kfree(scrub_dev->region_name); + kfree(scrub_dev->region_groups); + kfree(scrub_dev->groups); + ida_free(&scrub_ida, scrub_dev->id); + kfree(scrub_dev); +} + +static struct class scrub_class = { + .name = "scrub", + .dev_groups = scrub_dev_attr_groups, + .dev_release = scrub_dev_release, +}; + +/* sysfs attribute management */ + +static ssize_t scrub_attr_show(struct device *dev, + struct device_attribute *devattr, char *buf) +{ + int ret; + u64 val; + struct scrub_device_attribute *hattr = to_scrub_attr(devattr); + + ret = hattr->ops->read(dev, hattr->attr, hattr->region_id, &val); + if (ret < 0) + return ret; + + return sprintf(buf, "0x%llx\n", val); +} + +static ssize_t scrub_attr_show_string(struct device *dev, + struct device_attribute *devattr, + char *buf) +{ + int ret; + struct scrub_device_attribute *hattr = to_scrub_attr(devattr); + + ret = hattr->ops->read_string(dev, hattr->attr, hattr->region_id, buf); + if (ret < 0) + return ret; + + return strlen(buf); +} + +static ssize_t scrub_attr_store(struct device *dev, + struct device_attribute *devattr, + const char *buf, size_t count) +{ + int ret; + long val; + struct scrub_device_attribute *hattr = to_scrub_attr(devattr); + + ret = kstrtol(buf, 10, &val); + if (ret < 0) + return ret; + + ret = hattr->ops->write(dev, hattr->attr, hattr->region_id, val); + if (ret < 0) + return ret; + + return count; +} + +static ssize_t scrub_attr_store_hex(struct device *dev, + struct device_attribute *devattr, + const char *buf, size_t count) +{ + int ret; + u64 val; + struct scrub_device_attribute *hattr = to_scrub_attr(devattr); + + ret = kstrtou64(buf, 16, &val); + if (ret < 0) + return ret; + + ret = hattr->ops->write(dev, hattr->attr, hattr->region_id, val); + if (ret < 0) + return ret; + + return count; +} + +static bool is_hex_attr(u32 attr) +{ + return (attr == scrub_addr_base) || + (attr == scrub_addr_size); +} + +static bool is_string_attr(u32 attr) +{ + return attr == scrub_speed_available; +} + +static struct attribute *scrub_genattr(const void *drvdata, + u32 attr, + const char *attrb_name, + const struct scrub_ops *ops, + int region_id) +{ + umode_t mode; + struct attribute *a; + struct device_attribute *dattr; + bool is_hex = is_hex_attr(attr); + struct scrub_device_attribute *hattr; + bool is_string = is_string_attr(attr); + + /* The attribute is invisible if there is no template string */ + if (!attrb_name) + return ERR_PTR(-ENOENT); + + mode = ops->is_visible(drvdata, attr, region_id); + if (!mode) + return ERR_PTR(-ENOENT); + + if ((mode & 0444) && ((is_string && !ops->read_string) || + (!is_string && !ops->read))) + return ERR_PTR(-EINVAL); + if ((mode & 0222) && (!ops->write)) + return ERR_PTR(-EINVAL); + + hattr = kzalloc(sizeof(*hattr), GFP_KERNEL); + if (!hattr) + return ERR_PTR(-ENOMEM); + + hattr->attr = attr; + hattr->ops = ops; + hattr->region_id = region_id; + + dattr = &hattr->dev_attr; + dattr->show = is_string ? scrub_attr_show_string : scrub_attr_show; + dattr->store = is_hex ? scrub_attr_store_hex : scrub_attr_store; + + a = &dattr->attr; + sysfs_attr_init(a); + a->name = attrb_name; + a->mode = mode; + + return a; +} + +static const char * const scrub_common_attrs[] = { + [scrub_addr_base] = "addr_base", + [scrub_addr_size] = "addr_size", + [scrub_enable] = "enable", + [scrub_speed] = "speed", + [scrub_speed_available] = "speed_available", +}; + +static struct attribute ** +scrub_create_attrs(const void *drvdata, const struct scrub_ops *ops, int region_id) +{ + u32 attr; + int aindex = 0; + struct attribute *a; + struct attribute **attrs; + + attrs = kcalloc(max_attrs, sizeof(*attrs), GFP_KERNEL); + if (!attrs) + return ERR_PTR(-ENOMEM); + + for (attr = 0; attr < max_attrs; attr++) { + a = scrub_genattr(drvdata, attr, scrub_common_attrs[attr], + ops, region_id); + if (IS_ERR(a)) { + if (PTR_ERR(a) != -ENOENT) { + scrub_free_attrs(attrs); + return ERR_PTR(PTR_ERR(a)); + } + continue; + } + attrs[aindex++] = a; + } + + return attrs; +} + +static struct device * +scrub_device_register(struct device *dev, const char *name, void *drvdata, + const struct scrub_ops *ops, + int nregions) +{ + struct device *hdev; + struct attribute **attrs; + int err, count, region_id; + struct attribute_group *group; + struct scrub_device *scrub_dev; + char (*region_name)[SCRUB_MAX_SYSFS_ATTR_NAME_LENGTH]; + + scrub_dev = kzalloc(sizeof(*scrub_dev), GFP_KERNEL); + if (!scrub_dev) + return ERR_PTR(-ENOMEM); + hdev = &scrub_dev->dev; + + scrub_dev->id = ida_alloc(&scrub_ida, GFP_KERNEL); + if (scrub_dev->id < 0) { + err = -ENOMEM; + goto free_scrub_dev; + } + int ngroups = 2; /* terminating NULL plus &scrub_dev->groups */ + + ngroups += nregions; + + scrub_dev->groups = kcalloc(ngroups, sizeof(struct attribute_group *), GFP_KERNEL); + if (!scrub_dev->groups) { + err = -ENOMEM; + goto free_ida; + } + + if (nregions) { + scrub_dev->region_groups = kcalloc(nregions, sizeof(struct attribute_group), + GFP_KERNEL); + if (!scrub_dev->groups) { + err = -ENOMEM; + goto free_groups; + } + scrub_dev->region_name = kcalloc(nregions, SCRUB_MAX_SYSFS_ATTR_NAME_LENGTH, + GFP_KERNEL); + if (!scrub_dev->region_name) { + err = -ENOMEM; + goto free_region_groups; + } + } + + ngroups = 0; + scrub_dev->ngroups = 0; + if (nregions) { + region_name = scrub_dev->region_name; + for (region_id = 0; region_id < nregions; region_id++) { + attrs = scrub_create_attrs(drvdata, ops, region_id); + if (IS_ERR(attrs)) { + err = PTR_ERR(attrs); + goto free_attrs; + } + snprintf((char *)region_name, SCRUB_MAX_SYSFS_ATTR_NAME_LENGTH, + "region%d", region_id); + scrub_dev->region_groups[region_id].name = (char *)region_name; + scrub_dev->region_groups[region_id].attrs = attrs; + region_name++; + scrub_dev->groups[ngroups++] = &scrub_dev->region_groups[region_id]; + scrub_dev->ngroups = ngroups; + } + } else { + attrs = scrub_create_attrs(drvdata, ops, -1); + if (IS_ERR(attrs)) { + err = PTR_ERR(attrs); + goto free_region_name; + } + scrub_dev->group.attrs = attrs; + scrub_dev->groups[ngroups++] = &scrub_dev->group; + scrub_dev->ngroups = ngroups; + } + + hdev->groups = scrub_dev->groups; + hdev->class = &scrub_class; + hdev->parent = dev; + dev_set_drvdata(hdev, drvdata); + dev_set_name(hdev, SCRUB_ID_FORMAT, scrub_dev->id); + snprintf(scrub_dev->name, SCRUB_DEV_MAX_NAME_LENGTH, "%s", name); + err = device_register(hdev); + if (err) { + put_device(hdev); + return ERR_PTR(err); + } + + return hdev; + +free_attrs: + for (count = 0; count < scrub_dev->ngroups; count++) { + group = (struct attribute_group *)scrub_dev->groups[count]; + if (group) + scrub_free_attrs(group->attrs); + } + +free_region_name: + kfree(scrub_dev->region_name); + +free_region_groups: + kfree(scrub_dev->region_groups); + +free_groups: + kfree(scrub_dev->groups); + +free_ida: + ida_free(&scrub_ida, scrub_dev->id); + +free_scrub_dev: + kfree(scrub_dev); + return ERR_PTR(err); +} + +static void devm_scrub_release(void *dev) +{ + struct device *hdev = dev; + + device_unregister(hdev); +} + +/** + * devm_scrub_device_register - register hw scrubber device + * @dev: the parent device (mandatory) + * @name: hw scrubber name attribute (mandatory) + * @drvdata: driver data to attach to created device (mandatory) + * @ops: pointer to scrub_ops structure (mandatory) + * @nregions: number of scrub regions to create (optional) + * + * Returns the pointer to the new device. The new device is automatically + * unregistered with the parent device. + */ +struct device * +devm_scrub_device_register(struct device *dev, const char *name, + void *drvdata, + const struct scrub_ops *ops, + int nregions) +{ + struct device *hdev; + + if (!dev || !name || !ops) + return ERR_PTR(-EINVAL); + + hdev = scrub_device_register(dev, name, drvdata, ops, nregions); + if (IS_ERR(hdev)) + return hdev; + + if (devm_add_action_or_reset(dev, devm_scrub_release, hdev)) + return NULL; + + return hdev; +} +EXPORT_SYMBOL_GPL(devm_scrub_device_register); + +static int __init memory_scrub_control_init(void) +{ + int err; + + err = class_register(&scrub_class); + if (err) { + pr_err("couldn't register memory scrub control sysfs class\n"); + return err; + } + + return 0; +} +subsys_initcall(memory_scrub_control_init); diff --git a/include/memory/memory-scrub.h b/include/memory/memory-scrub.h new file mode 100755 index 000000000000..8e999c9daaed --- /dev/null +++ b/include/memory/memory-scrub.h @@ -0,0 +1,85 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Memory scrub controller driver support to configure + * the parameters of the memory scrubbers and enable. + * + * Copyright (c) 2023 HiSilicon Limited. + */ + +#ifndef __MEMORY_SCRUB_H +#define __MEMORY_SCRUB_H + +#include + +enum scrub_types { + scrub_common, + scrub_max, +}; + +enum scrub_attributes { + scrub_addr_base, + scrub_addr_size, + scrub_enable, + scrub_speed, + scrub_speed_available, + max_attrs, +}; + +#define SCRUB_ENABLE BIT(scrub_enable) +#define SCRUB_ADDR_BASE BIT(scrub_addr_base) +#define SCRUB_ADDR_SIZE BIT(scrub_addr_size) +#define SCRUB_SPEED BIT(scrub_speed) +#define SCRUB_SPEED_AVAILABLE BIT(scrub_speed_available) + +/** + * struct scrub_ops - scrub device operations + * @is_visible: Callback to return attribute visibility. Mandatory. + * Parameters are: + * @drvdata: + * pointer to driver-private data structure passed + * as argument to scrub_device_register(). + * @attr: scrubber attribute + * @region_id: + * memory region id + * The function returns the file permissions. + * If the return value is 0, no attribute will be created. + * @read: Read callback for data attributes. Mandatory if readable + * data attributes are present. + * Parameters are: + * @dev: pointer to hardware scrub device + * @attr: scrubber attribute + * @region_id: + * memory region id + * @val: pointer to returned value + * The function returns 0 on success or a negative error number. + * @read_string: Read callback for string attributes. Mandatory if string + * attributes are present. + * Parameters are: + * @dev: pointer to hardware scrub device + * @attr: scrubber attribute + * @region_id: + * memory region id + * @buf: pointer to buffer to copy string + * The function returns 0 on success or a negative error number. + * @write: Write callback for data attributes. Mandatory if writeable + * data attributes are present. + * Parameters are: + * @dev: pointer to hardware scrub device + * @attr: scrubber attribute + * @region_id: + * memory region id + * @val: value to write + * The function returns 0 on success or a negative error number. + */ +struct scrub_ops { + umode_t (*is_visible)(const void *drvdata, u32 attr, int region_id); + int (*read)(struct device *dev, u32 attr, int region_id, u64 *val); + int (*read_string)(struct device *dev, u32 attr, int region_id, char *buf); + int (*write)(struct device *dev, u32 attr, int region_id, u64 val); +}; + +struct device * +devm_scrub_device_register(struct device *dev, const char *name, + void *drvdata, const struct scrub_ops *ops, + int nregions); +#endif /* __MEMORY_SCRUB_H */ From patchwork Fri Sep 15 17:28:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13387304 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFDA6EED61C for ; Fri, 15 Sep 2023 17:29:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80BC56B0364; Fri, 15 Sep 2023 13:29:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E26B6B0366; Fri, 15 Sep 2023 13:29:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 635CA6B036C; Fri, 15 Sep 2023 13:29:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 2DBE56B0366 for ; Fri, 15 Sep 2023 13:29:09 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 058691207AC for ; Fri, 15 Sep 2023 17:29:08 +0000 (UTC) X-FDA: 81239517618.27.F90D506 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf24.hostedemail.com (Postfix) with ESMTP id 1510D18000D for ; Fri, 15 Sep 2023 17:29:06 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694798947; a=rsa-sha256; cv=none; b=Af5CMYEonxbauKer6pP+IfWfbpg397q3fs+b/0cizUHF8BhLOfWng55m5ZfZ13o2WBL9g8 io+CPp4qVvR1NYqQrHypgh7RMzcVHZKtEk1oA1bym+spXVyCugh+pQM+SI5JwalwHT1umT Z2FsnV0y2bfw6dy/l6Uov0+z59reluI= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694798947; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T7oaJA45CCb4UP4mn8TvsGwQjEz3z96hQRobhJyZbCw=; b=Om39G9pminBtatXk0EzdG6949kFWOzWU7MwERTAKHLkascOFBKAIuPw7Yx1KHefMxSItbj g6CMuR3PJRa7NCElZZCkUCUWol4Xp/jYN7hL0UdphXxjbJtlqexkSM4p4+27tFtv8ZHKBf txKX+IKZ2U0ecNPJFz3ILrLAe20n/Y0= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RnLkc2nYbz6K6LG; Sat, 16 Sep 2023 01:28:24 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 15 Sep 2023 18:29:04 +0100 From: To: , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH 2/9] memory: scrub: sysfs: Add Documentation entries for set of scrub attributes Date: Sat, 16 Sep 2023 01:28:11 +0800 Message-ID: <20230915172818.761-3-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20230915172818.761-1-shiju.jose@huawei.com> References: <20230915172818.761-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1510D18000D X-Stat-Signature: iyxr9du9tcxoxj9yb698w1k4wygcybhc X-HE-Tag: 1694798946-271825 X-HE-Meta: U2FsdGVkX1+Ul/l/FKFO/sFqmrmzpRGgDmZeuYRA33m9Fgi4hA7NiY5ylieDthYGeQw9MxoFoQlIIt7nZ9RESdQyoKnY/24NU/WM+g1eWYso5S8cRFSu8quzxPpLbwbN/r7iKMze8zGBoKtt4d/YaU5gtnFMw5goaEEpb4978dKFIoD1qIpwSpM2r+U20fBMzyXE328qFixkjp/fK2zEhm3VKyk6bEJ+FIEduuMhiVXFV3hcGxCbgC9Bg/6ov9F1t1H/3/dJV2e/j1zYHrvhL0sz2BKa0qHa7Zoq2JKI7gAXI6kbF4XhXk7TFmeJbNoRTnZjY4r67zgV8IF8ERO7j2KptEIJtMCW06WSs1cuX3hPbYTFYCwOQS1btg1jZ454ZWR9JlFk7UVLEulxBgazECPZtRH/S6gUvndIU/AB/z6Y+IZxOQUxDoQH66ImgmymB34etmKeTTmLalqKK0IohsbVGkHS1ojGOkSAfeajugK+f4S5mnxLUKD6jIeWd6Jj9MrogtvtCwtefOc22780S/EmcuaHe7LbKN6conO+08BBiMzhwvwQxLfYplzasUpvO3Jp1zJ0DJlHvplrBUH8WLzl8JtVAwqAhg3vutSZ+1iSFuE0yPnxGInqaO9uDVr8TMh8vEmLxWPvd+jd9ZmuG1OLLwXCnkx+FPs79CIlDR0KiUMusL9V/1BmjMRdsM8kFlBRoRh2GFgZgNBrN1CPrRuOXHD6296FrvPVRh4Ta43uzM/KrYPoGxxmyGVhjV7Z3pBSE8y4ZdY5SdhpxsBsNe0AThZBBgT8UdSW5Tb5jR7WZgh7Fn6eeLJ62h8J+0EtHuzxE8yVUAoSRUY9pRK6d62FCEE6VB+hxT9Vzt70psh9wyv4N/OtZjauNRw6sl5EO96YSePMwwHBaZScGR982x0oyHrkda4XTlWE9u7AtVIMpunu+ScAj44MsPo1rqM+npYK++pZgOf+HWKLCY0 btlibjc8 gskEC0b4qgXC8fAEhCPx8dleY31371x1+8XEUs8MwGVovE8vULoQmtx4y9/Nh5wI1IdmFYUD2UKzXGNlxUNloo7LS4x1Tu2TzUzDi1wAZHsM227Z1rn2D1GXKzDAa80yWmnWZPnvRXkw/k230eZ3C/z/oq+ghcuGWDKOjW+dOywx0rBHLaWpu1lbCxUx+KhIJHQjw33zqNoI+Yi4IUJtlM6uVSjIJqWJrQsAQ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Shiju Jose Add sysfs documentation entries for the set of attributes those are exposed in /sys/class/scrub/ by the scrub driver. These attributes support configuring parameters of a scrub device. Signed-off-by: Shiju Jose --- .../ABI/testing/sysfs-class-scrub-configure | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-scrub-configure diff --git a/Documentation/ABI/testing/sysfs-class-scrub-configure b/Documentation/ABI/testing/sysfs-class-scrub-configure new file mode 100644 index 000000000000..347e2167dc62 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-scrub-configure @@ -0,0 +1,82 @@ +What: /sys/class/scrub/ +Date: September 2023 +KernelVersion: 6.7 +Contact: linux-kernel@vger.kernel.org +Description: + The scrub/ class subdirectory belongs to the + scrubber subsystem. + +What: /sys/class/scrub/scrubX/ +Date: September 2023 +KernelVersion: 6.7 +Contact: linux-kernel@vger.kernel.org +Description: + The /sys/class/scrub/scrub{0,1,2,3,...} directories + correspond to each scrub device. + +What: /sys/class/scrub/scrubX/name +Date: September 2023 +KernelVersion: 6.7 +Contact: linux-kernel@vger.kernel.org +Description: + (RO) name of the memory scrub device + +What: /sys/class/scrub/scrubX/regionY/ +Date: September 2023 +KernelVersion: 6.7 +Contact: linux-kernel@vger.kernel.org +Description: + The /sys/class/scrub/scrubX/region{0,1,2,3,...} + directories correspond to each scrub region under a scrub device. + Scrub region is a physical address range for which scrub may be + separately controlled. Regions may overlap in which case the + scrubbing rate of the overlapped memory will be at least that + expected due to each overlapping region. + +What: /sys/class/scrub/scrubX/regionY/addr_base +Date: September 2023 +KernelVersion: 6.7 +Contact: linux-kernel@vger.kernel.org +Description: + (RW) The base of the address range of the memory region + to be patrol scrubbed. + On reading, returns the base of the memory region for + the actual address range(The platform calculates + the nearest patrol scrub boundary address from where + it can start scrubbing). + +What: /sys/class/scrub/scrubX/regionY/addr_size +Date: September 2023 +KernelVersion: 6.7 +Contact: linux-kernel@vger.kernel.org +Description: + (RW) The size of the address range to be patrol scrubbed. + On reading, returns the size of the memory region for + the actual address range. + +What: /sys/class/scrub/scrubX/regionY/enable +Date: September 2023 +KernelVersion: 6.7 +Contact: linux-kernel@vger.kernel.org +Description: + (WO) Start/Stop scrubbing the memory region. + 1 - enable the memory scrubbing. + 0 - disable the memory scrubbing.. + +What: /sys/class/scrub/scrubX/regionY/speed_available +Date: September 2023 +KernelVersion: 6.7 +Contact: linux-kernel@vger.kernel.org +Description: + (RO) Supported range for the partol speed(scrub rate) + by the scrubber for a memory region. + The unit of the scrub rate vary depends on the scrubber. + +What: /sys/class/scrub/scrubX/regionY/speed +Date: September 2023 +KernelVersion: 6.7 +Contact: linux-kernel@vger.kernel.org +Description: + (RW) The partol speed(scrub rate) on the memory region specified and + it must be with in the supported range by the scrubber. + The unit of the scrub rate vary depends on the scrubber. From patchwork Fri Sep 15 17:28:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13387303 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F448EED61B for ; Fri, 15 Sep 2023 17:29:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 23F436B0362; Fri, 15 Sep 2023 13:29:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1EF426B0364; Fri, 15 Sep 2023 13:29:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 068DA6B0366; Fri, 15 Sep 2023 13:29:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EDAE36B0362 for ; Fri, 15 Sep 2023 13:29:08 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C5F711C9EA6 for ; Fri, 15 Sep 2023 17:29:08 +0000 (UTC) X-FDA: 81239517576.27.AEE59B2 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf28.hostedemail.com (Postfix) with ESMTP id E8BF0C0020 for ; Fri, 15 Sep 2023 17:29:06 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694798947; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gfs2p+DyXsPzwXua36eDZRhODnON6WUq3RWvT23VnpE=; b=F7A4kUSLFD74Yd9X0Dk2BGCT3yW0gBs6nnj19jWaXmDuz6i3V4Jufw5JMc14p3HzmgmEno UD5Az7o9p+fa9160JxXx4jf64UwphQzN6dBR4HFVcyRiIK+OqzhA0hLgfuOyrtZIDp2Kjr CRAfLLRCZuGSmLH8cNWHhqoeBuxAiC8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694798947; a=rsa-sha256; cv=none; b=naekG85dsJCiUu4LxNynLcwxbOiHeGRYmsT5b5Un4Ej8RzzWDi5k8O5Envy7+tjqaWv660 SqMAaaZG/8sdVgsAFPtgiUr6bBgFDoFanpnoKOtI55w/dvIDRd2IqZM+EvdSKn9D+f6uXv iUBr1VKxMs6IX5ypXFxvfQMR39wBDWI= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.200]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RnLkc52pkz6K6LZ; Sat, 16 Sep 2023 01:28:24 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 15 Sep 2023 18:29:04 +0100 From: To: , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH 3/9] Documentation/scrub-configure.rst: Add documentation for scrub driver Date: Sat, 16 Sep 2023 01:28:12 +0800 Message-ID: <20230915172818.761-4-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20230915172818.761-1-shiju.jose@huawei.com> References: <20230915172818.761-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: E8BF0C0020 X-Rspam-User: X-Stat-Signature: noske7qu1nqbo44qtoka3gyzwhe8pdu9 X-Rspamd-Server: rspam03 X-HE-Tag: 1694798946-927003 X-HE-Meta: U2FsdGVkX1+66VA1MLE6uX9oc8ie/llnVtmGRQkJCklx6GvmMLV1l0bz5eTFIwkgyED99K7DnxEIM8EZb5cvGJn09LkENxseO4rs2bWXGCHH97ZDFUIRqnVUrZwbS8IVHxhC3rtmkm9HhHbYLtyxTj8yEwrp0JheoIdMTMWpC9Tw6BJCzji2xcMNGx231IukAyeB67MJMrdFMxY/25QCZvzoyOMnLrmPj5VNf73FeDKyUEHVTPKMSTTYIkvD2it4Yw4cqe2lsYiQkM5iDlBiErOj+U3r8G1yYvisfyJ4TDS83FrLWUOTwr04ylzUmjsRJF1JXCVR0RUL3wqPTNhahsx/KK+gViOmMPaIh0Z6riyxHCLqC7vOgM37CtUAPoIIaR946YaLRzhyDQAbiyYhc+VvyXIbxztBBEOXxg5EvIKxOATCrfWZGNkg/KaaYosYHBZoSh4mRHOsqLUUuZwqdYUdn2N+dWcbnSvZLFk9KEi8ieYs5dn1sGx1v1VhnkG3Df7uwBJpP8RLdU+5QVtv8aP9JOAO2E2phcey1gMoSynJUVzQQ5DexWARXmJcrJpCRqzW1opb0J7+dYTSVycmb23rE7QNIEoZKfGIN7MfxYf7Lz0efUECBzXRwnGnaalXF5Q509eQLDeaFPv7cgAs+JFjOfdRxrdqj1/3sKJXaMZCDznd8FutXzUkrqSbKrQf3hupvXaKW7GHuaP48s7xYWDcWxBiBJIttLL2Ds9BvDQg3hG9C/diAzmD1ApQ8o12nC6I8jFCvuptp/bYWOOF1SHhgpyHZ22QWQUsDQKEIyaMIP18WvwTKv0j5A+Pr1zu4z3NDMjXFj/DJQ4nTMs5oegRVapfk1hT0WjcwEdh7wZDmtEALMTp5jIcU7lfGXw1H2VISU/RPwU1lXUkfes2qKtvqnVBHk7IXrCKLjQwmv/1ctO+OasbRVqfkvOM5fHMk/krPh2UUfAthEFTFZ5 piootqvO Wrc1XdvVImB3p+mK4259ZmSLEKCMTrGjKuzxHLZrhGoZMAPb4x77jR6nWPqPB2dsELD8txrZmuPeOsgJITRYd4g10Z8dVxPPZklcfY3PZk/Vt5yeB1/MQ+p1gqh34xfdLi58xTC0jpQVySQ8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Shiju Jose Add documentation for scrub driver, supports configure scrub parameters, in Documentation/scrub-configure.rst Signed-off-by: Shiju Jose --- Documentation/scrub-configure.rst | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Documentation/scrub-configure.rst diff --git a/Documentation/scrub-configure.rst b/Documentation/scrub-configure.rst new file mode 100644 index 000000000000..9f8581b88788 --- /dev/null +++ b/Documentation/scrub-configure.rst @@ -0,0 +1,55 @@ +========================== +Scrub subsystem driver +========================== + +Copyright (c) 2023 HiSilicon Limited. + +:Author: Shiju Jose +:License: The GNU Free Documentation License, Version 1.2 + (dual licensed under the GPL v2) +:Original Reviewers: + +- Written for: 6.7 +- Updated for: + +Introduction +------------ +The scrub subsystem driver provides the interface for configure the +parameters of memory scrubbers in the system. The scrub device drivers +in the system register with the scrub configure subsystem. + +The scrub configure driver exposes the scrub controls to the user +via sysfs. + +The File System +--------------- + +The configuration parameters of the registered scrubbers could be +accessed via the /sys/class/scrub/scrubX/regionN/ + +sysfs +----- + +Sysfs files are documented in +`Documentation/ABI/testing/sysfs-class-scrub-configure`. + +Example +------- + + The usage takes the form shown in this example:: + + # echo 0x300000 > /sys/class/scrub/scrub0/region0/addr_base + # echo 0x100000 > /sys/class/scrub/scrub0/region0/addr_size + # cat /sys/class/scrub/scrub0/region0/speed_available + # 1-60 + # echo 25 > /sys/class/scrub/scrub0/region0/speed + # echo 1 > /sys/class/scrub/scrub0/region0/enable + + # cat /sys/class/scrub/scrub0/region0/speed + # 0x19 + # cat /sys/class/scrub/scrub0/region0/addr_base + # 0x100000 + # cat /sys/class/scrub/scrub0/region0/addr_size + # 0x200000 + + # echo 0 > /sys/class/scrub/scrub0/region0/enable From patchwork Fri Sep 15 17:28:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13387305 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74142EED61B for ; Fri, 15 Sep 2023 17:29:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 59A2B6B0366; Fri, 15 Sep 2023 13:29:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 54BC26B036C; Fri, 15 Sep 2023 13:29:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3C4EF6B0372; Fri, 15 Sep 2023 13:29:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 2C91C6B0366 for ; Fri, 15 Sep 2023 13:29:10 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 044A516074C for ; Fri, 15 Sep 2023 17:29:09 +0000 (UTC) X-FDA: 81239517660.16.E016E29 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf26.hostedemail.com (Postfix) with ESMTP id 02455140014 for ; Fri, 15 Sep 2023 17:29:07 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694798948; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wKczdbJT+oVHZL8dcYt3Ei+/nsqkhBkfQPnKcVTovyA=; b=sdECg66coIxPGMG+QamJePYBIsF5ae3qucWS4SRCLQ/gkWS7VpdJJ5lMEUegYIdAOdAlVP YU81YPXe/iF9uJxaZcT0y3Ywcy908vicAJ4tV477Nr54nkbuDW8IcAOLcmDmZ0veHXSfko xDmgRKh7EwlwENBCg3lys4+BqSS9Z+E= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694798948; a=rsa-sha256; cv=none; b=tISeT32tjegZ8u3xldlVcPG0t3KUnK4ZdAXfPfUaHRpepCdtmV7tB682BLXj5o/6oB0NVn 8JS+Nv1Ksw6RtRyr+isjZABfRcP/lt+wgLBmHROYHGUHXZ/pmmkoOB7EfJ9xM7RfbQN0+6 XczBqtV042XD4+uJII7X5iad8Kn5dXI= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RnLdz1rJyz67nfn; Sat, 16 Sep 2023 01:24:23 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 15 Sep 2023 18:29:05 +0100 From: To: , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH 4/9] ACPI:RASF: Add extract RASF table to register RASF platform devices Date: Sat, 16 Sep 2023 01:28:13 +0800 Message-ID: <20230915172818.761-5-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20230915172818.761-1-shiju.jose@huawei.com> References: <20230915172818.761-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 02455140014 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: usqrjki33gwnhqmmpgwfy3ct4qxocrj9 X-HE-Tag: 1694798947-456133 X-HE-Meta: U2FsdGVkX183I60A3K0Wf1Zs9vKhDe59wFOmJdmzL3KOV1x4/EsveXRceXHOWB++a28TGouJrCTVtFXnunjYKP5h5Lf4F82peoiSapKMM7Gmx2HAh2HnTRFf39W/R61lTWvm1BkGpDirz3GTDlTafSXL91TDWEzD1XrGpqMQMHC4iJao9pdotfv4Fxx0wBWreKzuiKt+EGCCOkDkNFTm+yPHuGl0XEG/+WOL4wCIgrzjl9f/0N0g3HF7kwRfe5MCwOyr594KppIxpvJ2l0M/+7ik/pgPGCrKeq0luDMv7eSJto8mQIv46GyVMz1iCJKLx3+KQnmXVS00eeWsUckZ7qa284cQEXQ/D8mB9YKxr2rZMiDziBz5cebdcja2pMx7R0xYh6f2dBNvPSNIhm2Xe/KrY/6zYNOn3EWsy1t12yTCcrUsfNqbgkhg8jNl3xaSL028ax7UMQrQquuV/ox2yJwiY8CHDpCGGSJP1jaV/Cj/LrCQUkCK6gmjxzpOz03Y88zjLHTDIVtIT1cD20519CHpx0BP0xXsbXR2wdrkBi+6MKwPGIwnZ0Wowq+pu8c2/Auij9+q4bNDIP2cGTvmRBVK+bC1a46/uAmMAGZw4hOlt0hc8dii4uGWEPCy48b72rgKU2OJ8F9Ln74Qihe8t4MPNqGoHT9OT5F3gA0hEhb8koR3pXdJoct0MsyCHv29quGSS7i1LRJw0disnUIi86ESOoUQkKRRZ4J4XIyhs6ihZSpXdSjQEQxx3i3ZtnGPa+jPiOMP6DV8JCQRAk5mWNleNZ3I+5+eXjoH/H9P5Gnmj9hTn0Qrf/u/PK2sj3aWOeBZ8qu8ODVKAL6dL180M63MoHFoSyob0DWsadumo3BTMSvmBvVn3DH2DxuU6zD4/DtkWqcEf5qPLmSO9xJXNFGtg9eXp1H+9JmVpjvjr7soJkt0mgcoVM5oxtmXy87aXsBOYHOqLEQr6jYBh8F KVgVdlrt eKUdPezC0MWkhD2XcF9X23oT2uk98Ukg7X9QxIeGWd+wS0Rg1/yDBvUo7GH2U1GVlhFA5X1YCQjfCsPRnPN9fgCDR0TXHZkNqxSi8PKyvoXn1dJG9qcLIpy1mVuD41S6G28LJ5jkpqVJSyk/QAZnaDuQPXZ2297BLg8Yt31km8saK5fuON14Vq4SyP2oowm4V1EAzJfAca5b5U3Q= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: A Somasundaram The driver adds extraction of ACPI RASF table as per ACPI 5.1 & upwards revision. ACPI specification section 5.2.20 for RASF table is the reference for this implementation. Driver adds a platform device which binds to the RASF memory driver. Signed-off-by: A Somasundaram Co-developed-by: Shiju Jose Signed-off-by: Shiju Jose --- drivers/acpi/Kconfig | 9 ++++ drivers/acpi/Makefile | 1 + drivers/acpi/rasf_acpi.c | 97 ++++++++++++++++++++++++++++++++++++++++ include/acpi/rasf_acpi.h | 19 ++++++++ 4 files changed, 126 insertions(+) create mode 100755 drivers/acpi/rasf_acpi.c create mode 100755 include/acpi/rasf_acpi.h diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index cee82b473dc5..e5fd8edc5b35 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -279,6 +279,15 @@ config ACPI_CPPC_LIB If your platform does not support CPPC in firmware, leave this option disabled. +config ACPI_RASF + bool "ACPI RASF driver" + depends on ACPI_PROCESSOR + select MAILBOX + help + The driver adds support for extraction of RASF table from OS + system table. Driver adds platform device which binds to the + RASF memory driver. + config ACPI_PROCESSOR tristate "Processor" depends on X86 || IA64 || ARM64 || LOONGARCH diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index eaa09bf52f17..f8a1263f6128 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -104,6 +104,7 @@ obj-$(CONFIG_ACPI_CUSTOM_METHOD)+= custom_method.o obj-$(CONFIG_ACPI_BGRT) += bgrt.o obj-$(CONFIG_ACPI_CPPC_LIB) += cppc_acpi.o obj-$(CONFIG_ACPI_SPCR_TABLE) += spcr.o +obj-$(CONFIG_ACPI_RASF) += rasf_acpi.o obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o obj-$(CONFIG_ACPI_PPTT) += pptt.o obj-$(CONFIG_ACPI_PFRUT) += pfr_update.o pfr_telemetry.o diff --git a/drivers/acpi/rasf_acpi.c b/drivers/acpi/rasf_acpi.c new file mode 100755 index 000000000000..b30ba2a5e4ff --- /dev/null +++ b/drivers/acpi/rasf_acpi.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * rasf_acpi.c - ACPI RASF table processing functions + * + * (C) Copyright 2014, 2015 Hewlett-Packard Enterprises. + * + * Copyright (c) 2023 HiSilicon Limited. + * + * Support for + * RASF - ACPI 6.5 Specification, section 5.2.20 + * + * Code contains RASF init, which extracts the ACPI RASF table and + * RASF platform communication channel identifier for communicating + * with the ACPI compliant platform that contains RASF command + * support in the hardware. Driver adds platform device which + * binds to the RASF memory driver. + */ + +#define pr_fmt(fmt) "ACPI RASF: " fmt + +#include +#include +#include +#include +#include +#include + +static struct platform_device *rasf_add_platform_device(char *name, const void *data, + size_t size) +{ + int ret; + struct platform_device *pdev; + + pdev = platform_device_alloc(name, PLATFORM_DEVID_AUTO); + if (!pdev) + return NULL; + + ret = platform_device_add_data(pdev, data, size); + if (ret) + goto dev_put; + + ret = platform_device_add(pdev); + if (ret) + goto dev_put; + + return pdev; + +dev_put: + platform_device_put(pdev); + + return NULL; +} + +int __init rasf_acpi_init(void) +{ + acpi_status status; + acpi_size rasf_size; + int pcc_subspace_idx; + struct platform_device *pdev; + struct acpi_table_rasf *pRasfTable; + struct acpi_table_header *pAcpiTable = NULL; + + status = acpi_get_table("RASF", 0, &pAcpiTable); + if (ACPI_FAILURE(status) || !pAcpiTable) { + pr_err("ACPI RASF driver failed to initialize, get table failed\n"); + return RASF_FAILURE; + } + + rasf_size = pAcpiTable->length; + if (rasf_size < sizeof(struct acpi_table_rasf)) { + pr_err("ACPI RASF table present but broken (too short #1)\n"); + goto free_rasf_table; + } + + pRasfTable = (struct acpi_table_rasf *)pAcpiTable; + + /* Extract the PCC subspace channel id from the table */ + memcpy(&pcc_subspace_idx, &pRasfTable->channel_id, sizeof(pcc_subspace_idx)); + pr_debug("ACPI RASF pcc subspace channel id =%d\n", + pcc_subspace_idx); + if (pcc_subspace_idx < 0) + goto free_rasf_table; + + /* Add the platform device and bind rasf memory driver */ + pdev = rasf_add_platform_device("rasf", &pcc_subspace_idx, + sizeof(pcc_subspace_idx)); + if (!pdev) + goto free_rasf_table; + + acpi_put_table(pAcpiTable); + return RASF_SUCCESS; + +free_rasf_table: + acpi_put_table(pAcpiTable); + return RASF_FAILURE; +} +late_initcall(rasf_acpi_init) diff --git a/include/acpi/rasf_acpi.h b/include/acpi/rasf_acpi.h new file mode 100755 index 000000000000..1c4c3e94d472 --- /dev/null +++ b/include/acpi/rasf_acpi.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * RASF Diagnostic driver header file + * + * (C) Copyright 2014, 2015 Hewlett-Packard Enterprises + * + * Copyright (c) 2023 HiSilicon Limited + */ + +#ifndef _RASF_ACPI_H +#define _RASF_ACPI_H + +#include +#include + +#define RASF_FAILURE 0 +#define RASF_SUCCESS 1 + +#endif /* _RASF_ACPI_H */ From patchwork Fri Sep 15 17:28:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13387306 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95BDBEED61C for ; Fri, 15 Sep 2023 17:29:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8AD16B036C; Fri, 15 Sep 2023 13:29:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D3AA36B0372; Fri, 15 Sep 2023 13:29:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B66506B0383; Fri, 15 Sep 2023 13:29:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9D73B6B0372 for ; Fri, 15 Sep 2023 13:29:10 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 76ADF1A05A9 for ; Fri, 15 Sep 2023 17:29:10 +0000 (UTC) X-FDA: 81239517660.11.ABD6FB9 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf13.hostedemail.com (Postfix) with ESMTP id 5D6072002E for ; Fri, 15 Sep 2023 17:29:08 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694798948; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FHAU3zMpaz6YfNbIxl84w6JNtmNTEhNBeSn1h4RlwOo=; b=oAzyKTxZCd+aLHxgS9ZSPaodEnF82d4VZJpaTPRtOsFrFbgSVFofYfGuYZJGJN4whExRm3 qMJah0c0in1DNXbFgVdFiLiLS1s7by6IpUPesUWzX4TpuyNWGoRMtvWmr7iTjpDa/SClAp Hmu1+qqywfN2xy0hNOCWkWzYxpLAdSU= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694798948; a=rsa-sha256; cv=none; b=jP10BV1sSopWrnJ6K8NfXIn+G6MA8vKOY0lLq/fy1kmuoNOrELe1bvCwmd9oz0y5bbr7Ht aW5PvKL80UVdxF18IEUcbPisiE/c3+KIIDj0TRjhKkt6VKVp9XjB2Iqr/uj4+YgtSqoSmq tPBguGURBukOdmh07NLzN6UYSP/LPQE= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RnLdz49S5z67nH3; Sat, 16 Sep 2023 01:24:23 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 15 Sep 2023 18:29:06 +0100 From: To: , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH 5/9] ACPI:RASF: Add common library for RASF and RAS2 PCC interfaces Date: Sat, 16 Sep 2023 01:28:14 +0800 Message-ID: <20230915172818.761-6-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20230915172818.761-1-shiju.jose@huawei.com> References: <20230915172818.761-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspam-User: X-Stat-Signature: haaa1kpxbwf5kq4m3fjh74jsoyhn4fbq X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5D6072002E X-HE-Tag: 1694798948-95778 X-HE-Meta: U2FsdGVkX1+/ChETBK0CfYDD+l5a4aIQKVUrkzXWjpZxgjaPO09JG1drYjtXTcTuRt+qdiWjDYTdGEoa507RmFk5ZPHq7DiuerCkN8E5ZSNigW/BllZbxrIzC0tR3NihM4APZx7llnED4gErIL5/Mn0WQkOE8/eLgkQhVszd6kRav8GkZrAqpqDQwItN2fHvcmYouiYyKCarLT9QTlGj3PU94GGQQmiUESDn7vatKTxhXK5zGUPFcs9ka/zMh/zXyS/wmxvUuC3twP/xsCKe/tsRVBXX4wlnKwa9wvGPhmo/IzMq9xsaL1SawnASIsGXf7GE5SOAn1aX8SLgI2APBrLXyRueTiux5FsL1bTsaE60hUsfQ0YK8L3bLY1gRfzmF+0ik50qjHDDWLcrwr4t5n4xrEL4Pt5NBtP/23v3hB0QzazjChraRzsYzsqoHQnMMGqQ88kFSH/QJuk2J3b22t4QWAC193GiKMvMIg1DigQJgBJ4LRKNDIrVXhWOwE+m0VCl5L1zXtOV5d7vzrXjne6IjFC5AU8GK52psdYmwd8EP6DXng3+bC1DWKBGSsgvsAiRjpRdf16jQDmlaBzkjMoAIoMJ3Dj0+xfWZiySPlNkmshtyUMESLbjPSfOwjhm9Off7Sa63xwrSjsHjS+pWy0+w0U3TESt+nJw57CEjgMnXa6SbFTpQmskXEDfx7luG5TjkcXoGlrQ5k1imG9xSikzK+fdHGjUCyoMvB+mTGwuWzaW/8bsRSlwc4bbjhwbCle4eBTWRJv+5oCC3vlX3OUVn4XFVtTdxxURCpMBk34TIg6JKzxWHT15DpG2O3v1L8WAKwcsPo3XgUtyPLEnx2wWYeH/GJPrCXUWeEM3+2yA8v2D5sFcBZNdAESRMoXhCh6RXFRPoxSP+h6lfSeC9f4jN9hz4wOv9ZhUF6utWcxbwIKSFsl07KwRF9RQ2wNRcNXcC0EdjiedvuHnghj 0ix/jOVp fWCp0R7dXGeJM7guv1sSAGpGXxmxzkkR3nzviiqZky2cXDui3/MJX23ulKvvogFOZU4P61/bOL8bDHoTGNqmk4pnSKD2UpCYZKrc6TazxofCB+4oYI4YRzYAX61t6R/w2EPbMhRR5K71yEatTBrsAYni8CImzqmXdBcCtH/tADoq3z2WOrseu9qJKuABYGRueHTAsWDzZbi/2rMA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: A Somasundaram The code contains PCC interfaces for RASF and RAS2 table, functions to send RASF commands as per ACPI 5.1 and RAS2 commands as per ACPI 6.5 & upwards revision. References for this implementation, ACPI specification, section 5.2.20 for RASF table, section 5.2.21 for RAS2 table and chapter 14 for PCC (Platform Communication Channel). Driver uses PCC interfaces to communicate to the ACPI HW. This code implements PCC interfaces and the functions to send the RASF/RAS2 commands to be used by OSPM. Signed-off-by: A Somasundaram Co-developed-by: Shiju Jose Signed-off-by: Shiju Jose --- drivers/acpi/Kconfig | 12 +- drivers/acpi/Makefile | 2 +- drivers/acpi/rasf_acpi.c | 26 --- drivers/acpi/rasf_acpi_common.c | 272 ++++++++++++++++++++++++++++++++ include/acpi/rasf_acpi.h | 40 +++++ 5 files changed, 322 insertions(+), 30 deletions(-) create mode 100755 drivers/acpi/rasf_acpi_common.c diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig index e5fd8edc5b35..057f7fbc9887 100644 --- a/drivers/acpi/Kconfig +++ b/drivers/acpi/Kconfig @@ -283,10 +283,16 @@ config ACPI_RASF bool "ACPI RASF driver" depends on ACPI_PROCESSOR select MAILBOX + select PCC help - The driver adds support for extraction of RASF table from OS - system table. Driver adds platform device which binds to the - RASF memory driver. + The driver adds support for PCC (platform communication + channel) interfaces to communicate with the ACPI complaint + hardware platform supports RASF(RAS Feature table) or + and RAS2(RAS2 Feature table). + The driver adds support for RASF(extraction of RASF tables + from OS system table), PCC interfaces and OSPM interfaces to + send RASF & RAS2 commands. Driver adds platform device which + binds to the RASF/RAS2 memory driver. config ACPI_PROCESSOR tristate "Processor" diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index f8a1263f6128..dd62d936cbe1 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -104,7 +104,7 @@ obj-$(CONFIG_ACPI_CUSTOM_METHOD)+= custom_method.o obj-$(CONFIG_ACPI_BGRT) += bgrt.o obj-$(CONFIG_ACPI_CPPC_LIB) += cppc_acpi.o obj-$(CONFIG_ACPI_SPCR_TABLE) += spcr.o -obj-$(CONFIG_ACPI_RASF) += rasf_acpi.o +obj-$(CONFIG_ACPI_RASF) += rasf_acpi_common.o rasf_acpi.o obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o obj-$(CONFIG_ACPI_PPTT) += pptt.o obj-$(CONFIG_ACPI_PFRUT) += pfr_update.o pfr_telemetry.o diff --git a/drivers/acpi/rasf_acpi.c b/drivers/acpi/rasf_acpi.c index b30ba2a5e4ff..4c752fab9c4c 100755 --- a/drivers/acpi/rasf_acpi.c +++ b/drivers/acpi/rasf_acpi.c @@ -25,32 +25,6 @@ #include #include -static struct platform_device *rasf_add_platform_device(char *name, const void *data, - size_t size) -{ - int ret; - struct platform_device *pdev; - - pdev = platform_device_alloc(name, PLATFORM_DEVID_AUTO); - if (!pdev) - return NULL; - - ret = platform_device_add_data(pdev, data, size); - if (ret) - goto dev_put; - - ret = platform_device_add(pdev); - if (ret) - goto dev_put; - - return pdev; - -dev_put: - platform_device_put(pdev); - - return NULL; -} - int __init rasf_acpi_init(void) { acpi_status status; diff --git a/drivers/acpi/rasf_acpi_common.c b/drivers/acpi/rasf_acpi_common.c new file mode 100755 index 000000000000..3ee34f5d12d3 --- /dev/null +++ b/drivers/acpi/rasf_acpi_common.c @@ -0,0 +1,272 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * rasf_acpi_common.c - ACPI RASF table processing common functions + * + * (C) Copyright 2014, 2015 Hewlett-Packard Enterprises. + * + * Copyright (c) 2023 HiSilicon Limited. + * + * Support for + * RASF - ACPI 6.5 Specification, section 5.2.20 + * RAS2 - ACPI 6.5 Specification, section 5.2.21 + * PCC(Platform Communications Channel) - ACPI 6.5 Specification, + * chapter 14. + * + * Code contains common functions for RASF. + * PCC(Platform communication channel) interfaces for the RASF & RAS2 + * and the functions for sending RASF & RAS2 commands to the ACPI HW. + */ + +#define pr_fmt(fmt) "ACPI RASF COMMON: " fmt + +#include +#include +#include +#include +#include +#include + +static int rasf_check_pcc_chan(struct rasf_context *rasf_ctx) +{ + int ret = -EIO; + struct acpi_rasf_shared_memory __iomem *generic_comm_base = rasf_ctx->pcc_comm_addr; + ktime_t next_deadline = ktime_add(ktime_get(), rasf_ctx->deadline); + + while (!ktime_after(ktime_get(), next_deadline)) { + /* + * As per ACPI spec, the PCC space wil be initialized by + * platform and should have set the command completion bit when + * PCC can be used by OSPM + */ + if (readw_relaxed(&generic_comm_base->status) & RASF_PCC_CMD_COMPLETE) { + ret = 0; + break; + } + /* + * Reducing the bus traffic in case this loop takes longer than + * a few retries. + */ + udelay(10); + } + + return ret; +} + +/** + * rasf_send_pcc_cmd() - Send RASF command via PCC channel + * @rasf_ctx: pointer to the rasf context structure + * @cmd: command to send + * + * Returns: 0 on success, an error otherwise + */ +int rasf_send_pcc_cmd(struct rasf_context *rasf_ctx, u16 cmd) +{ + int ret = -EIO; + struct acpi_rasf_shared_memory *generic_comm_base = + (struct acpi_rasf_shared_memory *)rasf_ctx->pcc_comm_addr; + static ktime_t last_cmd_cmpl_time, last_mpar_reset; + static int mpar_count; + unsigned int time_delta; + + if (cmd == RASF_PCC_CMD_EXEC) { + ret = rasf_check_pcc_chan(rasf_ctx); + if (ret) + return ret; + } + + /* + * Handle the Minimum Request Turnaround Time(MRTT) + * "The minimum amount of time that OSPM must wait after the completion + * of a command before issuing the next command, in microseconds" + */ + if (rasf_ctx->pcc_mrtt) { + time_delta = ktime_us_delta(ktime_get(), last_cmd_cmpl_time); + if (rasf_ctx->pcc_mrtt > time_delta) + udelay(rasf_ctx->pcc_mrtt - time_delta); + } + + /* + * Handle the non-zero Maximum Periodic Access Rate(MPAR) + * "The maximum number of periodic requests that the subspace channel can + * support, reported in commands per minute. 0 indicates no limitation." + * + * This parameter should be ideally zero or large enough so that it can + * handle maximum number of requests that all the cores in the system can + * collectively generate. If it is not, we will follow the spec and just + * not send the request to the platform after hitting the MPAR limit in + * any 60s window + */ + if (rasf_ctx->pcc_mpar) { + if (mpar_count == 0) { + time_delta = ktime_ms_delta(ktime_get(), last_mpar_reset); + if (time_delta < 60 * MSEC_PER_SEC) { + pr_debug("PCC cmd not sent due to MPAR limit"); + return -EIO; + } + last_mpar_reset = ktime_get(); + mpar_count = rasf_ctx->pcc_mpar; + } + mpar_count--; + } + + /* Write to the shared comm region. */ + writew_relaxed(cmd, &generic_comm_base->command); + + /* Flip CMD COMPLETE bit */ + writew_relaxed(0, &generic_comm_base->status); + + /* Ring doorbell */ + ret = mbox_send_message(rasf_ctx->pcc_channel, &cmd); + if (ret < 0) { + pr_err("Err sending PCC mbox message. cmd:%d, ret:%d\n", + cmd, ret); + return ret; + } + + /* + * For READs we need to ensure the cmd completed to ensure + * the ensuing read()s can proceed. For WRITEs we dont care + * because the actual write()s are done before coming here + * and the next READ or WRITE will check if the channel + * is busy/free at the entry of this call. + * + * If Minimum Request Turnaround Time is non-zero, we need + * to record the completion time of both READ and WRITE + * command for proper handling of MRTT, so we need to check + * for pcc_mrtt in addition to CMD_READ + */ + if (cmd == RASF_PCC_CMD_EXEC || rasf_ctx->pcc_mrtt) { + ret = rasf_check_pcc_chan(rasf_ctx); + if (rasf_ctx->pcc_mrtt) + last_cmd_cmpl_time = ktime_get(); + } + + if (rasf_ctx->pcc_channel->mbox->txdone_irq) + mbox_chan_txdone(rasf_ctx->pcc_channel, ret); + else + mbox_client_txdone(rasf_ctx->pcc_channel, ret); + + return ret; +} +EXPORT_SYMBOL_GPL(rasf_send_pcc_cmd); + +/** + * rasf_register_pcc_channel() - Register PCC channel + * @rasf_ctx: pointer to the rasf context structure + * + * Returns: 0 on success, an error otherwise + */ +int rasf_register_pcc_channel(struct rasf_context *rasf_ctx) +{ + u64 usecs_lat; + unsigned int len; + struct pcc_mbox_chan *pcc_chan; + struct mbox_client *rasf_mbox_cl; + struct acpi_pcct_hw_reduced *rasf_ss; + + rasf_mbox_cl = &rasf_ctx->mbox_client; + if (!rasf_mbox_cl || rasf_ctx->pcc_subspace_idx < 0) + return -EINVAL; + + pcc_chan = pcc_mbox_request_channel(rasf_mbox_cl, + rasf_ctx->pcc_subspace_idx); + + if (IS_ERR(pcc_chan)) { + pr_err("Failed to find PCC channel for subspace %d\n", + rasf_ctx->pcc_subspace_idx); + return -ENODEV; + } + rasf_ctx->pcc_chan = pcc_chan; + rasf_ctx->pcc_channel = pcc_chan->mchan; + /* + * The PCC mailbox controller driver should + * have parsed the PCCT (global table of all + * PCC channels) and stored pointers to the + * subspace communication region in con_priv. + */ + rasf_ss = rasf_ctx->pcc_channel->con_priv; + + if (!rasf_ss) { + pr_err("No PCC subspace found for RASF\n"); + pcc_mbox_free_channel(rasf_ctx->pcc_chan); + return -ENODEV; + } + + /* + * This is the shared communication region + * for the OS and Platform to communicate over. + */ + rasf_ctx->comm_base_addr = rasf_ss->base_address; + len = rasf_ss->length; + pr_debug("PCC subspace for RASF=0x%llx len=%d\n", + rasf_ctx->comm_base_addr, len); + + /* + * rasf_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 = RASF_NUM_RETRIES * rasf_ss->latency; + rasf_ctx->deadline = ns_to_ktime(usecs_lat * NSEC_PER_USEC); + rasf_ctx->pcc_mrtt = rasf_ss->min_turnaround_time; + rasf_ctx->pcc_mpar = rasf_ss->max_access_rate; + rasf_ctx->pcc_comm_addr = acpi_os_ioremap(rasf_ctx->comm_base_addr, len); + pr_debug("pcc_comm_addr=%p\n", rasf_ctx->pcc_comm_addr); + + /* Set flag so that we dont come here for each CPU. */ + rasf_ctx->pcc_channel_acquired = true; + + return 0; +} +EXPORT_SYMBOL_GPL(rasf_register_pcc_channel); + +/** + * rasf_unregister_pcc_channel() - Unregister PCC channel + * @rasf_ctx: pointer to the rasf context structure + * + * Returns: 0 on success, an error otherwise + */ +int rasf_unregister_pcc_channel(struct rasf_context *rasf_ctx) +{ + if (!rasf_ctx->pcc_chan) + return -EINVAL; + + pcc_mbox_free_channel(rasf_ctx->pcc_chan); + + return 0; +} +EXPORT_SYMBOL_GPL(rasf_unregister_pcc_channel); + +/** + * rasf_add_platform_device() - Add a platform device for RASF + * @name: name of the device we're adding + * @data: platform specific data for this platform device + * @size: size of platform specific data + * + * Returns: pointer to platform device on success, an error otherwise + */ +struct platform_device *rasf_add_platform_device(char *name, const void *data, + size_t size) +{ + int ret; + struct platform_device *pdev; + + pdev = platform_device_alloc(name, PLATFORM_DEVID_AUTO); + if (!pdev) + return NULL; + + ret = platform_device_add_data(pdev, data, size); + if (ret) + goto dev_put; + + ret = platform_device_add(pdev); + if (ret) + goto dev_put; + + return pdev; + +dev_put: + platform_device_put(pdev); + + return NULL; +} diff --git a/include/acpi/rasf_acpi.h b/include/acpi/rasf_acpi.h index 1c4c3e94d472..e91a451c5dc1 100755 --- a/include/acpi/rasf_acpi.h +++ b/include/acpi/rasf_acpi.h @@ -11,9 +11,49 @@ #define _RASF_ACPI_H #include +#include +#include #include +#include + +#define RASF_PCC_CMD_COMPLETE 1 + +/* RASF specific PCC commands */ +#define RASF_PCC_CMD_EXEC 0x01 #define RASF_FAILURE 0 #define RASF_SUCCESS 1 +/* + * Arbitrary Retries for PCC commands. + */ +#define RASF_NUM_RETRIES 600 + +/* + * Data structures for PCC communication and RASF table + */ +struct rasf_context { + struct device *dev; + int id; + struct mbox_client mbox_client; + struct mbox_chan *pcc_channel; + struct pcc_mbox_chan *pcc_chan; + void __iomem *pcc_comm_addr; + u64 comm_base_addr; + int pcc_subspace_idx; + bool pcc_channel_acquired; + ktime_t deadline; + unsigned int pcc_mpar; + unsigned int pcc_mrtt; + spinlock_t spinlock; /* Lock to provide mutually exclusive access to PCC channel */ + struct device *scrub_dev; + u8 n_regions; + const struct rasf_hw_scrub_ops *ops; +}; + +struct platform_device *rasf_add_platform_device(char *name, const void *data, + size_t size); +int rasf_send_pcc_cmd(struct rasf_context *rasf_ctx, u16 cmd); +int rasf_register_pcc_channel(struct rasf_context *rasf_ctx); +int rasf_unregister_pcc_channel(struct rasf_context *rasf_ctx); #endif /* _RASF_ACPI_H */ From patchwork Fri Sep 15 17:28:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13387308 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 570A5EED61C for ; Fri, 15 Sep 2023 17:29:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F38E06B0380; Fri, 15 Sep 2023 13:29:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E994B6B0383; Fri, 15 Sep 2023 13:29:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEBA16B0385; Fri, 15 Sep 2023 13:29:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B9BBC6B0380 for ; Fri, 15 Sep 2023 13:29:11 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 90F3AC0775 for ; Fri, 15 Sep 2023 17:29:11 +0000 (UTC) X-FDA: 81239517702.25.89B337E Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf02.hostedemail.com (Postfix) with ESMTP id 7A2F38001C for ; Fri, 15 Sep 2023 17:29:09 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694798949; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=frvZl/ugHQWbNuFr8dwpsRGQ5MFuZCvHnZ9/Zy1CXWk=; b=dSMx0522MRIxAb4FbmLF6YRtM4pZwtf96aQRfKRw9rumnYwPvqU6IXdAknPFM4CwzX2c8J BU9RI9pebKSzl4Ixj/bih5/15Wm4ubycrwRfOOHnI1c6SmqguU5RByEdLTwbw3l7zZgXc2 0RHj8aRaVTqXelqbAdU5nm7JnnBVU3o= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694798949; a=rsa-sha256; cv=none; b=F5gPH1Xk5sGj/F501wpQCWi27elKTzRLzXplm/bPkVVUIW/zr/yVhHeR94AOWjvqHYHuVw O6GfKrMSl5JbhCzf6sysaV30Ksbrs22qEGLDdmMhzuI/pJYFUZ4+0r0ZXXxcsDzniAVvAp kYAD3xezM82+Vsam7zbk9dVzEpX3fDE= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RnLkg1TSqz6K6Qn; Sat, 16 Sep 2023 01:28:27 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 15 Sep 2023 18:29:06 +0100 From: To: , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH 6/9] memory: RASF: Add memory RASF driver Date: Sat, 16 Sep 2023 01:28:15 +0800 Message-ID: <20230915172818.761-7-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20230915172818.761-1-shiju.jose@huawei.com> References: <20230915172818.761-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 7A2F38001C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: t4udfk7p74ngmd8hghnj6rzc85tjb5az X-HE-Tag: 1694798949-113442 X-HE-Meta: U2FsdGVkX18HsWHqpQEroFy6U7Lqu3rvnNGFyEMYqQSyQdAnTiJ6ZrMMYgVkp4r7B1lJT/F5xPjZmOkILTbsCkykU2dqaWzjnsStpH4LsbLfgCCczc+f3t0+yZ2zcO64w1R9WWzPgPMQEnag0oRtNSg1oZstm6E8xEVpARRDlgygy65DT6moCKIb6/o/LxRtajR5KUYZ1Eif399yTtXyLi1PbIBwqhcMbxsrvonMAV9otIcW48cica7TSWAEfXOpfNgxnEMXmflR5J9j1BIFmExqe05nAXNXRW5VtINp3JNhd20Wtfd3Tpy54IYPsnLsQVY4Vm2UphtLmHgK09ha1yM4/gXssDXaJumTs/ndPdh9vzoLu9AM1B7IqyG8RJhtFZyiuTzwM4kxlY4XF9hCclIw8xbFrAibp9y6d2RtcoXJNnGAwU1/iOE7F96lbZFMPm2ZK1r28i5rrEMYDWOmdyl4LJiEg5xjI01Orz5wlI+K6F+qYgdo07vpXyroaS7pCTfR1E0ecjAZTGKfCX60Ym9j4aiqgKpoB90pvfVdrm+H5JDY3DSc3qTPVMXXn5KiRUMzryR2OsCTAma0TI4km8xQ59nHmCGdX9aUxzhHqKG1awhV19+gqmyktx88o62hj3CYuYaOeiIhUXxM9x/UGl8XnWeCThdd8QG7wEgsEYUzwyb4wItJ4fmmz9rcuFmj5oRHzK+8UK4J9Di0SDrvCS1hDJ5XDJUdOJqJUTOSR9t8R4rdx6Dp7GrcjiKxpAfDz153j/xnN/PZ5RMwcF6KWq/XYsCXhmXth4y4xeI/D/BKTt/HVI3losOf3QCOM93GvlCwox0UFytMEYVlUiSGSEEKH71qZ/zRaBQkhHt2+ZDbMk0iY4bxhj7JWkcUcuv0DPV+GGy2/N09ZAGw7JfrfnZBx8XUNWAmHV1a5JHfgbvswsfY9AcwoBlkozk/lLN4VQ9LBMCg+N6QS4pDETy aeFzNH7L CtLy2zqLwi8VG9IqbRpeWFNlitkWB32n/G7L6qJZOXUoLSQGYYhlaKqkZKU6108BHgjVl2g4n4T1k/V3kUk/OF2YFFJmWWeZ5e7E2mWhphxTSoktB3w0/RLh5EjUqqPsrLx8FqpyifQ2Gq/mvoTW6+sJh+w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Shiju Jose Memory RASF driver binds to the platform device add by the ACPI RASF driver. Driver registers the PCC channel for communicating with the ACPI compliant platform that contains RASF command support in the hardware. Add interface functions to support configuring the parameters of HW patrol scrubber in the system, which exposed to the kernel via the RASF and PCC, using the RASF commands. Add support for RASF scrub devices to register with scrub driver. This enables user to configure the parameters of HW patrol scrubbers, which exposed to the kernel via the RASF table, using the scrub sysfs attributes. Signed-off-by: Shiju Jose --- drivers/memory/Kconfig | 14 ++ drivers/memory/Makefile | 2 + drivers/memory/rasf.c | 335 +++++++++++++++++++++++++++++++++++ drivers/memory/rasf_common.c | 251 ++++++++++++++++++++++++++ include/memory/rasf.h | 82 +++++++++ 5 files changed, 684 insertions(+) create mode 100644 drivers/memory/rasf.c create mode 100644 drivers/memory/rasf_common.c create mode 100755 include/memory/rasf.h diff --git a/drivers/memory/Kconfig b/drivers/memory/Kconfig index d2e015c09d83..b831e76fcdbf 100644 --- a/drivers/memory/Kconfig +++ b/drivers/memory/Kconfig @@ -225,6 +225,20 @@ config STM32_FMC2_EBI devices (like SRAM, ethernet adapters, FPGAs, LCD displays, ...) on SOCs containing the FMC2 External Bus Interface. +config MEM_RASF + bool "Memory RASF driver" + depends on ACPI_RASF + depends on SCRUB + help + The driver bound to the platform device added by the ACPI RASF + driver. Driver registers the PCC channel for communicating with + the ACPI compliant platform that contains RASF/RAS2 command support + in the hardware. + Registers with the scrub configure driver to provide sysfs interfaces + for configuring the hw patrol scrubber in the system, which exposed + via the ACPI RASF/RAS2 table and PCC. Provides the interface functions + support configuring the HW patrol scrubbers in the system. + source "drivers/memory/samsung/Kconfig" source "drivers/memory/tegra/Kconfig" source "drivers/memory/scrub/Kconfig" diff --git a/drivers/memory/Makefile b/drivers/memory/Makefile index 4b37312cb342..49340cd100fc 100644 --- a/drivers/memory/Makefile +++ b/drivers/memory/Makefile @@ -7,6 +7,8 @@ obj-$(CONFIG_DDR) += jedec_ddr_data.o ifeq ($(CONFIG_DDR),y) obj-$(CONFIG_OF) += of_memory.o endif +obj-$(CONFIG_MEM_RASF) += rasf_common.o rasf.o + obj-$(CONFIG_ARM_PL172_MPMC) += pl172.o obj-$(CONFIG_ATMEL_EBI) += atmel-ebi.o obj-$(CONFIG_BRCMSTB_DPFE) += brcmstb_dpfe.o diff --git a/drivers/memory/rasf.c b/drivers/memory/rasf.c new file mode 100644 index 000000000000..b33024c0ed15 --- /dev/null +++ b/drivers/memory/rasf.c @@ -0,0 +1,335 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * rasf.c - Memory RASF Driver + * + * Copyright (c) 2023 HiSilicon Limited. + * + * This driver: + * - Registers the PCC channel for communicating with the + * ACPI compliant platform that contains RASF command + * support in the hardware. + * - Provides functions to configure HW patrol scrubber + * in the system. + * - Registers with the scrub configure driver for the + * hw patrol scrubber in the system, which exposed via + * the ACPI RASF table and PCC. + */ + +#define pr_fmt(fmt) "MEMORY RASF: " fmt + +#include +#include +#include +#include + +#include +#include + +/* RASF specific definitions. */ +#define RASF_SCRUB "rasf_scrub" +#define RASF_SUPPORT_HW_PARTOL_SCRUB BIT(0) +#define RASF_EXPOSE_HW_PARTOL_SCRUB_TO_SW BIT(1) + +#define RASF_TYPE_PATROL_SCRUB 0x0000 + +#define RASF_GET_PATROL_PARAMETERS 0x01 +#define RASF_START_PATROL_SCRUBBER 0x02 +#define RASF_STOP_PATROL_SCRUBBER 0x03 + +#define RASF_PATROL_SCRUB_RATE_VALID BIT(0) +#define RASF_PATROL_SCRUB_SPEED_MASK GENMASK(3, 1) +#define RASF_PATROL_SCRUB_SLOW 0x0 +#define RASF_PATROL_SCRUB_MEDIUM 0x4 +#define RASF_PATROL_SCRUB_FAST 0x7 + +/* + * The number of regions may not be relavent for RASF + */ +#define RASF_NUM_REGIONS 1 + +#define to_rasf_ctx(cl) \ + container_of(cl, struct rasf_context, mbox_client) + +static void rasf_tx_done(struct mbox_client *cl, void *msg, int ret) +{ + if (ret) { + dev_dbg(cl->dev, "TX did not complete: CMD sent:%x, ret:%d\n", + *(u16 *)msg, ret); + } else { + dev_dbg(cl->dev, "TX completed. CMD sent:%x, ret:%d\n", + *(u16 *)msg, ret); + } +} + +/* + * The below functions are exposed to OSPM, to query, configure and + * initiate memory patrol scrubber. + */ +static int rasf_is_patrol_scrub_support(struct rasf_context *rasf_ctx) +{ + int ret; + struct acpi_rasf_shared_memory __iomem *generic_comm_base; + + if (!rasf_ctx || !rasf_ctx->pcc_comm_addr) + return -EFAULT; + + generic_comm_base = rasf_ctx->pcc_comm_addr; + guard(spinlock_irqsave)(&rasf_ctx->spinlock); + generic_comm_base->set_capabilities[0] = 0; + + /* send command for reading RASF capabilities */ + ret = rasf_send_pcc_cmd(rasf_ctx, RASF_PCC_CMD_EXEC); + if (ret) { + pr_err("%s: rasf_send_pcc_cmd failed\n", __func__); + return ret; + } + + return FIELD_GET(RASF_EXPOSE_HW_PARTOL_SCRUB_TO_SW, + generic_comm_base->capabilities[0]); +} + +static int rasf_get_patrol_scrub_params(struct rasf_context *rasf_ctx, + struct rasf_scrub_params *params) +{ + int ret = 0; + struct acpi_rasf_shared_memory __iomem *generic_comm_base; + struct acpi_rasf_patrol_scrub_parameter __iomem *patrol_scrub_params; + + if (!rasf_ctx || !rasf_ctx->pcc_comm_addr) + return -EFAULT; + + generic_comm_base = rasf_ctx->pcc_comm_addr; + patrol_scrub_params = rasf_ctx->pcc_comm_addr + sizeof(*generic_comm_base); + + guard(spinlock_irqsave)(&rasf_ctx->spinlock); + generic_comm_base->set_capabilities[0] = RASF_EXPOSE_HW_PARTOL_SCRUB_TO_SW; + + /* send command for reading RASF capabilities */ + ret = rasf_send_pcc_cmd(rasf_ctx, RASF_PCC_CMD_EXEC); + if (ret) { + pr_err("%s: rasf_send_pcc_cmd failed\n", __func__); + return ret; + } + + if (!(generic_comm_base->capabilities[0] & RASF_EXPOSE_HW_PARTOL_SCRUB_TO_SW) || + !(generic_comm_base->num_parameter_blocks)) { + pr_err("%s: Platform does not support HW Patrol Scrubber\n", __func__); + return -ENOTSUPP; + } + + if (!patrol_scrub_params->requested_address_range[1]) { + pr_err("%s: Invalid requested address range, \ + requested_address base=0x%llx \ + requested_address size=0x%llx\n", + __func__, + patrol_scrub_params->requested_address_range[0], + patrol_scrub_params->requested_address_range[1]); + return -ENOTSUPP; + } + + generic_comm_base->set_capabilities[0] = RASF_EXPOSE_HW_PARTOL_SCRUB_TO_SW; + patrol_scrub_params->header.type = RASF_TYPE_PATROL_SCRUB; + patrol_scrub_params->patrol_scrub_command = RASF_GET_PATROL_PARAMETERS; + + /* send command for reading the HW patrol scrub parameters */ + ret = rasf_send_pcc_cmd(rasf_ctx, RASF_PCC_CMD_EXEC); + if (ret) { + pr_err("%s: failed to read HW patrol scrub parameters\n", __func__); + return ret; + } + + /* copy output scrubber parameters */ + params->addr_base = patrol_scrub_params->actual_address_range[0]; + params->addr_size = patrol_scrub_params->actual_address_range[1]; + params->flags = patrol_scrub_params->flags; + if (patrol_scrub_params->flags & RASF_PATROL_SCRUB_RATE_VALID) { + params->speed = FIELD_GET(RASF_PATROL_SCRUB_SPEED_MASK, + patrol_scrub_params->flags); + snprintf(params->speed_avail, RASF_MAX_SPEED_RANGE_LENGTH, + "%d,%d,%d", RASF_PATROL_SCRUB_SLOW, + RASF_PATROL_SCRUB_MEDIUM, RASF_PATROL_SCRUB_FAST); + } else { + params->speed = 0; + snprintf(params->speed_avail, RASF_MAX_SPEED_RANGE_LENGTH, + "%s", "Unavailable"); + } + + return 0; +} + +static int rasf_enable_patrol_scrub(struct rasf_context *rasf_ctx, bool enable) +{ + int ret = 0; + struct rasf_scrub_params params; + struct acpi_rasf_shared_memory __iomem *generic_comm_base; + struct acpi_rasf_patrol_scrub_parameter __iomem *patrol_scrub_params; + + if (!rasf_ctx || !rasf_ctx->pcc_comm_addr) + return -EFAULT; + + generic_comm_base = rasf_ctx->pcc_comm_addr; + patrol_scrub_params = rasf_ctx->pcc_comm_addr + sizeof(*generic_comm_base); + + if (enable) { + ret = rasf_get_patrol_scrub_params(rasf_ctx, ¶ms); + if (ret) + return ret; + } + + guard(spinlock_irqsave)(&rasf_ctx->spinlock); + generic_comm_base->set_capabilities[0] = RASF_EXPOSE_HW_PARTOL_SCRUB_TO_SW; + patrol_scrub_params->header.type = RASF_TYPE_PATROL_SCRUB; + + if (enable) { + patrol_scrub_params->patrol_scrub_command = RASF_START_PATROL_SCRUBBER; + patrol_scrub_params->requested_address_range[0] = params.addr_base; + patrol_scrub_params->requested_address_range[1] = params.addr_size; + /* requested speed already set in the rasf_set_patrol_scrub_params */ + } else + patrol_scrub_params->patrol_scrub_command = RASF_STOP_PATROL_SCRUBBER; + + /* send command for enable/disable the HW patrol scrub */ + ret = rasf_send_pcc_cmd(rasf_ctx, RASF_PCC_CMD_EXEC); + if (ret) { + pr_err("%s: failed to enable/disable the HW patrol scrub\n", __func__); + return ret; + } + + return 0; +} + +static int rasf_set_patrol_scrub_params(struct rasf_context *rasf_ctx, + struct rasf_scrub_params *params, u8 param_type) +{ + struct acpi_rasf_shared_memory __iomem *generic_comm_base; + struct acpi_rasf_patrol_scrub_parameter __iomem *patrol_scrub_params; + + if (!rasf_ctx || !rasf_ctx->pcc_comm_addr) + return -EFAULT; + + generic_comm_base = rasf_ctx->pcc_comm_addr; + patrol_scrub_params = rasf_ctx->pcc_comm_addr + sizeof(*generic_comm_base); + + guard(spinlock_irqsave)(&rasf_ctx->spinlock); + patrol_scrub_params->header.type = RASF_TYPE_PATROL_SCRUB; + if (param_type == RASF_MEM_SCRUB_PARAM_ADDR_BASE && params->addr_base) { + patrol_scrub_params->requested_address_range[0] = params->addr_base; + } else if (param_type == RASF_MEM_SCRUB_PARAM_ADDR_SIZE && params->addr_size) { + patrol_scrub_params->requested_address_range[1] = params->addr_size; + } else if (param_type == RASF_MEM_SCRUB_PARAM_SPEED) { + if ((params->speed != RASF_PATROL_SCRUB_SLOW) && + (params->speed != RASF_PATROL_SCRUB_MEDIUM) && + params->speed != RASF_PATROL_SCRUB_FAST) { + pr_warn("rasf driver failed to set patrol scrub speed=%d\n", + params->speed); + pr_warn("Supported speeds: slow:%d medium:%d fast:%d\n", + RASF_PATROL_SCRUB_SLOW, RASF_PATROL_SCRUB_MEDIUM, + RASF_PATROL_SCRUB_FAST); + return -EINVAL; + } + + /* + * ACPI 6.5 Spec Table 5.78: Parameter Block Structure for PATROL_SCRUB + * Requested Speed (INPUT) + * Bit [0]: Will be set if patrol scrub is already running + * for address range specified in “Actual Address Range” + * Bits [2:0]: Requested Patrol Speeds + */ + + /* Is the description about Bit[0] in the Spec an error? */ + + patrol_scrub_params->requested_speed &= ~RASF_PATROL_SCRUB_SPEED_MASK; + patrol_scrub_params->requested_speed |= FIELD_PREP(RASF_PATROL_SCRUB_SPEED_MASK, params->speed); + } else { + pr_err("Invalid patrol scrub parameter to set\n"); + return -EINVAL; + } + + return 0; +} + +static const struct rasf_hw_scrub_ops rasf_hw_ops = { + .enable_scrub = rasf_enable_patrol_scrub, + .get_scrub_params = rasf_get_patrol_scrub_params, + .set_scrub_params = rasf_set_patrol_scrub_params, +}; + +static const struct scrub_ops rasf_scrub_ops = { + .is_visible = rasf_hw_scrub_is_visible, + .read = rasf_hw_scrub_read, + .write = rasf_hw_scrub_write, + .read_string = rasf_hw_scrub_read_strings, +}; + +static void devm_rasf_release(void *rasf_ctx) +{ + rasf_unregister_pcc_channel(rasf_ctx); +} + +static int rasf_probe(struct platform_device *pdev) +{ + int ret; + struct mbox_client *cl; + struct device *hw_scrub_dev; + struct rasf_context *rasf_ctx; + char scrub_name[RASF_MAX_NAME_LENGTH]; + + rasf_ctx = devm_kzalloc(&pdev->dev, sizeof(*rasf_ctx), GFP_KERNEL); + if (!rasf_ctx) + return -ENOMEM; + + rasf_ctx->dev = &pdev->dev; + rasf_ctx->ops = &rasf_hw_ops; + spin_lock_init(&rasf_ctx->spinlock); + + platform_set_drvdata(pdev, rasf_ctx); + cl = &rasf_ctx->mbox_client; + + /* Request mailbox channel */ + cl->dev = &pdev->dev; + cl->tx_done = rasf_tx_done; + cl->knows_txdone = true; + + rasf_ctx->pcc_subspace_idx = *((int *)pdev->dev.platform_data); + dev_dbg(&pdev->dev, "pcc-subspace-id=%d\n", rasf_ctx->pcc_subspace_idx); + + ret = rasf_register_pcc_channel(rasf_ctx); + if (ret < 0) + return ret; + + ret = devm_add_action_or_reset(&pdev->dev, devm_rasf_release, rasf_ctx); + if (ret < 0) + return ret; + + if (rasf_is_patrol_scrub_support(rasf_ctx)) { + rasf_ctx->n_regions = RASF_NUM_REGIONS; + snprintf(scrub_name, sizeof(scrub_name), "%s", RASF_SCRUB); + hw_scrub_dev = devm_scrub_device_register(&pdev->dev, scrub_name, rasf_ctx, + &rasf_scrub_ops, + rasf_ctx->n_regions); + if (PTR_ERR_OR_ZERO(hw_scrub_dev)) + return PTR_ERR_OR_ZERO(hw_scrub_dev); + } + rasf_ctx->scrub_dev = hw_scrub_dev; + + return 0; +} + +static const struct platform_device_id rasf_id_table[] = { + { .name = "rasf", }, + { } +}; +MODULE_DEVICE_TABLE(platform, rasf_id_table); + +static struct platform_driver rasf_driver = { + .probe = rasf_probe, + .driver = { + .name = "rasf", + .suppress_bind_attrs = true, + }, + .id_table = rasf_id_table, +}; +module_driver(rasf_driver, platform_driver_register, platform_driver_unregister); + +MODULE_DESCRIPTION("rasf driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/memory/rasf_common.c b/drivers/memory/rasf_common.c new file mode 100644 index 000000000000..aa0deb0d6d1e --- /dev/null +++ b/drivers/memory/rasf_common.c @@ -0,0 +1,251 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * rasf_common.c - Common functions for memory RASF driver + * + * Copyright (c) 2023 HiSilicon Limited. + * + * This driver implements call back functions for the scrub + * configure driver to configure the parameters of the hw patrol + * scrubbers in the system, which exposed via the ACPI RASF/RAS2 + * table and PCC. + */ + +#define pr_fmt(fmt) "MEMORY RASF COMMON: " fmt + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +static int enable_write(struct rasf_context *rasf_ctx, long val) +{ + int ret; + bool scrub_enable = val; + + ret = rasf_ctx->ops->enable_scrub(rasf_ctx, scrub_enable); + if (ret) { + pr_err("enable patrol scrub for enable fail, enable=%d ret=%d\n", + scrub_enable, ret); + return ret; + } + + return 0; +} + +static int addr_base_read(struct rasf_context *rasf_ctx, u64 *val) +{ + int ret; + struct rasf_scrub_params params; + + ret = rasf_ctx->ops->get_scrub_params(rasf_ctx, ¶ms); + if (ret) { + pr_err("get patrol scrub params fail ret=%d\n", ret); + return ret; + } + *val = params.addr_base; + + return 0; +} + +static int addr_base_write(struct rasf_context *rasf_ctx, u64 val) +{ + int ret; + struct rasf_scrub_params params; + + params.addr_base = val; + ret = rasf_ctx->ops->set_scrub_params(rasf_ctx, ¶ms, RASF_MEM_SCRUB_PARAM_ADDR_BASE); + if (ret) { + pr_err("set patrol scrub params for addr_base fail ret=%d\n", ret); + return ret; + } + + return 0; +} + +static int addr_size_read(struct rasf_context *rasf_ctx, u64 *val) +{ + int ret; + struct rasf_scrub_params params; + + ret = rasf_ctx->ops->get_scrub_params(rasf_ctx, ¶ms); + if (ret) { + pr_err("get patrol scrub params fail ret=%d\n", ret); + return ret; + } + *val = params.addr_size; + + return 0; +} + +static int addr_size_write(struct rasf_context *rasf_ctx, u64 val) +{ + int ret; + struct rasf_scrub_params params; + + params.addr_size = val; + ret = rasf_ctx->ops->set_scrub_params(rasf_ctx, ¶ms, RASF_MEM_SCRUB_PARAM_ADDR_SIZE); + if (ret) { + pr_err("set patrol scrub params for addr_size fail ret=%d\n", ret); + return ret; + } + + return 0; +} + +static int speed_read(struct rasf_context *rasf_ctx, u64 *val) +{ + int ret; + struct rasf_scrub_params params; + + ret = rasf_ctx->ops->get_scrub_params(rasf_ctx, ¶ms); + if (ret) { + pr_err("get patrol scrub params fail ret=%d\n", ret); + return ret; + } + *val = params.speed; + + return 0; +} + +static int speed_write(struct rasf_context *rasf_ctx, long val) +{ + int ret; + struct rasf_scrub_params params; + + params.speed = val; + ret = rasf_ctx->ops->set_scrub_params(rasf_ctx, ¶ms, RASF_MEM_SCRUB_PARAM_SPEED); + if (ret) { + pr_err("set patrol scrub params for speed fail ret=%d\n", ret); + return ret; + } + + return 0; +} + +static int speed_available_read(struct rasf_context *rasf_ctx, char *buf) +{ + int ret; + struct rasf_scrub_params params; + + ret = rasf_ctx->ops->get_scrub_params(rasf_ctx, ¶ms); + if (ret) { + pr_err("get patrol scrub params fail ret=%d\n", ret); + return ret; + } + + sprintf(buf, "%s\n", params.speed_avail); + + return 0; +} + +/** + * rasf_hw_scrub_is_visible() - Callback to return attribute visibility + * @drv_data: Pointer to driver-private data structure passed + * as argument to devm_scrub_device_register(). + * @attr: Scrub attribute + * @region_id: ID of the memory region + * + * Returns: 0 on success, an error otherwise + */ +umode_t rasf_hw_scrub_is_visible(const void *drv_data, u32 attr, int region_id) +{ + switch (attr) { + case scrub_speed_available: + return 0444; + case scrub_enable: + return 0200; + case scrub_addr_base: + case scrub_addr_size: + case scrub_speed: + return 0644; + default: + return 0; + } +} + +/** + * rasf_hw_scrub_read() - Read callback for data attributes + * @device: Pointer to scrub device + * @attr: Scrub attribute + * @region_id: ID of the memory region + * @val: Pointer to the returned data + * + * Returns: 0 on success, an error otherwise + */ +int rasf_hw_scrub_read(struct device *device, u32 attr, int region_id, u64 *val) +{ + struct rasf_context *rasf_ctx; + + rasf_ctx = dev_get_drvdata(device); + + switch (attr) { + case scrub_addr_base: + return addr_base_read(rasf_ctx, val); + case scrub_addr_size: + return addr_size_read(rasf_ctx, val); + case scrub_speed: + return speed_read(rasf_ctx, val); + default: + return -ENOTSUPP; + } +} + +/** + * rasf_hw_scrub_write() - Write callback for data attributes + * @device: Pointer to scrub device + * @attr: Scrub attribute + * @region_id: ID of the memory region + * @val: Value to write + * + * Returns: 0 on success, an error otherwise + */ +int rasf_hw_scrub_write(struct device *device, u32 attr, int region_id, u64 val) +{ + struct rasf_context *rasf_ctx; + + rasf_ctx = dev_get_drvdata(device); + + switch (attr) { + case scrub_addr_base: + return addr_base_write(rasf_ctx, val); + case scrub_addr_size: + return addr_size_write(rasf_ctx, val); + case scrub_enable: + return enable_write(rasf_ctx, val); + case scrub_speed: + return speed_write(rasf_ctx, val); + default: + return -ENOTSUPP; + } +} + +/** + * rasf_hw_scrub_read_strings() - Read callback for string attributes + * @device: Pointer to scrub device + * @attr: Scrub attribute + * @region_id: ID of the memory region + * @buf: Pointer to the buffer for copying returned string + * + * Returns: 0 on success, an error otherwise + */ +int rasf_hw_scrub_read_strings(struct device *device, u32 attr, int region_id, + char *buf) +{ + struct rasf_context *rasf_ctx; + + rasf_ctx = dev_get_drvdata(device); + + switch (attr) { + case scrub_speed_available: + return speed_available_read(rasf_ctx, buf); + default: + return -ENOTSUPP; + } +} diff --git a/include/memory/rasf.h b/include/memory/rasf.h new file mode 100755 index 000000000000..3ec291ddff97 --- /dev/null +++ b/include/memory/rasf.h @@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */ +/* + * Memory RASF driver header file + * + * Copyright (c) 2023 HiSilicon Limited + */ + +#ifndef _RASF_H +#define _RASF_H + +#include + +#define RASF_MAX_NAME_LENGTH 64 +#define RASF_MAX_SPEED_RANGE_LENGTH 64 + +/* + * Data structures RASF + */ + +/** + * struct rasf_scrub_params- RASF scrub parameter data structure. + * @addr_base: [IN] Base address of the address range to be patrol scrubbed. + * [OUT] Base address of the actual address range. + * @addr_size: [IN] Size of the address range to be patrol scrubbed. + * [OUT] Size of the actual address range. + * @flags: [OUT] The platform returns this value in response to + * GET_PATROL_PARAMETERS. + * For RASF and RAS2: + * Bit [0]: Will be set if memory scrubber is already + * running for address range specified in “Actual Address Range”. + * For RASF: + * Bits [3:1]: Current Patrol Speeds, if Bit [0] is set. + * @speed: [IN] Requested patrol Speed. + * [OUT] Current patrol scrub Speed. + * @speed_avail:[OUT] Supported patrol speeds. + */ +struct rasf_scrub_params { + u64 addr_base; + u64 addr_size; + u16 flags; + u32 speed; + char speed_avail[RASF_MAX_SPEED_RANGE_LENGTH]; +}; + +enum { + RASF_MEM_SCRUB_PARAM_ADDR_BASE = 0, + RASF_MEM_SCRUB_PARAM_ADDR_SIZE, + RASF_MEM_SCRUB_PARAM_SPEED, +}; + +/** + * struct rasf_hw_scrub_ops - rasf hw scrub device operations + * @enable_scrub: Function to enable/disable RASF/RAS2 scrubber. Mandatory. + * Parameters are: + * @rasf_ctx: Pointer to RASF/RAS2 context structure. + * @enable: enable/disable RASF scrubber. + * The function returns 0 on success or a negative error number. + * @get_scrub_params: Read scrubber parameters. Mandatory + * Parameters are: + * @rasf_ctx: Pointer to RASF/RAS2 context structure. + * @params: Pointer to scrub params data structure. + * The function returns 0 on success or a negative error number. + * @set_scrub_params: Set scrubber parameters. Mandatory. + * Parameters are: + * @rasf_ctx: Pointer to RASF/RAS2 context structure. + * @params: Pointer to scrub params data structure. + * @param_type: Scrub parameter type to set. + * The function returns 0 on success or a negative error number. + */ +struct rasf_hw_scrub_ops { + int (*enable_scrub)(struct rasf_context *rasf_ctx, bool enable); + int (*get_scrub_params)(struct rasf_context *rasf_ctx, + struct rasf_scrub_params *params); + int (*set_scrub_params)(struct rasf_context *rasf_ctx, + struct rasf_scrub_params *params, u8 param_type); +}; + +umode_t rasf_hw_scrub_is_visible(const void *drv_data, u32 attr, int region_id); +int rasf_hw_scrub_read(struct device *dev, u32 attr, int region_id, u64 *val); +int rasf_hw_scrub_write(struct device *dev, u32 attr, int region_id, u64 val); +int rasf_hw_scrub_read_strings(struct device *dev, u32 attr, int region_id, char *buf); +#endif /* _RASF_H */ From patchwork Fri Sep 15 17:28:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13387309 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27A0BEED61B for ; Fri, 15 Sep 2023 17:29:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 76F8E6B0383; Fri, 15 Sep 2023 13:29:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 720F96B0385; Fri, 15 Sep 2023 13:29:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5996C6B0386; Fri, 15 Sep 2023 13:29:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4759D6B0383 for ; Fri, 15 Sep 2023 13:29:12 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 252221406D2 for ; Fri, 15 Sep 2023 17:29:12 +0000 (UTC) X-FDA: 81239517744.23.E71FCEB Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf08.hostedemail.com (Postfix) with ESMTP id 21B5D160015 for ; Fri, 15 Sep 2023 17:29:09 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf08.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694798950; a=rsa-sha256; cv=none; b=deSFGfS6PVn9hJHO7oGe3pXFZqB/GHqAVQcKYNaJo0fQE/e3f9QudQyTnqR/SSAzAtouiy LKnXM5/jMIvfYH8Rl+BoN2UB4XgqVGvSAou755xoWfaxDqgSl5LAWga0DNzp52dRAYzjxh D3TFOLWR06MZ4qoycFUNpjqhQMZ5Fgc= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf08.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694798950; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IzZm5K2ulhd199kMKUqoL2s0hOvcRcqzGto+EAot46U=; b=5d50CIcLsp/TEWyTZ4WO/dh1QC3+XVkwRRDO6QxPC2ImLyyIxpqRNDyS7rwGEJMM/NUjXh VROFNaYKJjuhax/rR9IcZeRutvvUZc/UWLW4LztuDeDxE801B6Qi+KagG3bJT4vxnchELM IRB19DAheioC8cEpxzsLuG2XQmOplE4= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RnLkg43fGz6K6Pc; Sat, 16 Sep 2023 01:28:27 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 15 Sep 2023 18:29:07 +0100 From: To: , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH 7/9] ACPICA: ACPI 6.5: Add support for RAS2 table Date: Sat, 16 Sep 2023 01:28:16 +0800 Message-ID: <20230915172818.761-8-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20230915172818.761-1-shiju.jose@huawei.com> References: <20230915172818.761-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 21B5D160015 X-Stat-Signature: gfpm813cepmnokwom4s43ipdi95jfsux X-Rspam-User: X-HE-Tag: 1694798949-806391 X-HE-Meta: U2FsdGVkX1+wFTTmi7ov35sVVPapkZwGUgGuj6Fq+UdMokPjkEysrMHMTVScGC6rRuAdfJPon+edOcASfq1lRRYgwb6rm2Rg+g8u7D4xMbExOBM3U7xgnZV8imqwDE/CsFUh48zUfd7gELIYqXC76jc5lliL/f2Bci99vmHUVg0TP0lqReB+0H24mbxN5lF+avCNPnOQG3L0txRn2GHP1Ly8xMjJhnLkMUlWkhmvbWAUsAa6DmKAE7dgkwQRG0OTQCkoSGULZ71QFCJvdHjYB3lI3K/38SokFHDMbpAIH665VJNMi8uh4EhI20Bx+VUA7Qhnx4WsTlLDE+DiJSo60C/1W041/GNb6Wv6LzcDavp6/c/rmpQmzVfNnZoMpW8bntFQ+SMrBAX44seMy+8p03i6KzB6QlcF74COEBul6YNFSuDPUVfAl8a+1/LLKMcyoOlCzRiIIwj3WAzJwgp3qg9jDFdHOjEIlWaYEcP8n2tpN6flPJ1AxxOZfT3UutdsiDTMp2gDtKWR57q+GZ5Q5RMcYAGdWpRSakcPWrWM8pzNjgp6jEVUbQaN6g1S0dV0OJyPLR4WnrIKCLzzFJmsxXyZ9sVevpRXbCk9Q+ERPQ6++5eGdHc7Bkvq0fW1lAbKCX5FWBBa0/nJ4V5jepkrwiS6sSiX4ZxjL93G1IYDOTSNO7bLiBqAcYfzRBmAifvHuGM36u5FtwaAg0al01JBVS5eSTHwLQOooyWzyjaN6/8J7U/3qww1n+Qw5kcZMeQj8E65X+TxLWa8ijGeuU1fwu6X/Ilr5cverQfuUpSShSu1RxAcAmVjbMhdOINwURSy5mboYcdvNK2gULRwcrVQJX7w7t+jxRBb7i1LdC7GEcDhFAq3MVwZR0Ml93hQE/3UsOU7G8/GGQ1SJat4CmB4aLq/ref60tqiM3kJTwMC3BxzdDt7re4qBcRmqp6SyO/RVcyPqJt6leekSIm5uK4 5RFSOyca n3yndHzt4nICr3yJWgBzTecyJ/D4wtCQFCX8xmh0KBGr7qmsmC6RrmmBmMhiPIg+5z79Y8Cn7ZPaQ/3oroIn/u4Poa5GeIp3BmQiytFsHm/GLS6gc0yA7rhhqn7asg4d8BmWHYv59xEAMuNEh1Y1m1a0wZBhX+wdpEewC X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Shiju Jose Add support for ACPI RAS2 feature table(RAS2) defined in the ACPI 6.5 Specification & upwards revision, section 5.2.21. The RAS2 table provides interfaces for platform RAS features. RAS2 offers the same services as RASF, but is more scalable than the latter. RAS2 supports independent RAS controls and capabilities for a given RAS feature for multiple instances of the same component in a given system. The platform can support either RAS2 or RASF but not both. Link: https://github.com/acpica/acpica/pull/892 Signed-off-by: Shiju Jose --- include/acpi/actbl2.h | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/include/acpi/actbl2.h b/include/acpi/actbl2.h index 3751ae69432f..41e77cacc5c6 100644 --- a/include/acpi/actbl2.h +++ b/include/acpi/actbl2.h @@ -47,6 +47,7 @@ #define ACPI_SIG_PPTT "PPTT" /* Processor Properties Topology Table */ #define ACPI_SIG_PRMT "PRMT" /* Platform Runtime Mechanism Table */ #define ACPI_SIG_RASF "RASF" /* RAS Feature table */ +#define ACPI_SIG_RAS2 "RAS2" /* RAS2 Feature table */ #define ACPI_SIG_RGRT "RGRT" /* Regulatory Graphics Resource Table */ #define ACPI_SIG_RHCT "RHCT" /* RISC-V Hart Capabilities Table */ #define ACPI_SIG_SBST "SBST" /* Smart Battery Specification Table */ @@ -2743,6 +2744,60 @@ enum acpi_rasf_status { #define ACPI_RASF_ERROR (1<<2) #define ACPI_RASF_STATUS (0x1F<<3) +/******************************************************************************* + * + * RAS2 - RAS2 Feature Table (ACPI 6.5) + * Version 2 + * + * + ******************************************************************************/ + +struct acpi_table_ras2 { + struct acpi_table_header header; /* Common ACPI table header */ + u16 reserved; + u16 num_pcc_descs; +}; + +/* + * RAS2 Platform Communication Channel Descriptor + */ + +struct acpi_ras2_pcc_desc { + u8 channel_id; + u16 reserved; + u8 feature_type; + u32 instance; +}; + +/* + * RAS2 Platform Communication Channel Shared Memory Region + */ + +struct acpi_ras2_shared_memory { + u32 signature; + u16 command; + u16 status; + u16 version; + u8 features[16]; + u8 set_capabilities[16]; + u16 num_parameter_blocks; + u32 set_capabilities_status; +}; + +/* + * RAS2 Parameter Block Structure for PATROL_SCRUB + */ + +struct acpi_ras2_patrol_scrub_parameter { + struct acpi_rasf_parameter_block header; + u16 patrol_scrub_command; + u64 requested_address_range[2]; + u64 actual_address_range[2]; + u32 flags; + u32 scrub_params_out; + u32 scrub_params_in; +}; + /******************************************************************************* * * RGRT - Regulatory Graphics Resource Table From patchwork Fri Sep 15 17:28:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13387310 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F22BEEED61A for ; Fri, 15 Sep 2023 17:29:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 267B26B0385; Fri, 15 Sep 2023 13:29:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 219726B0386; Fri, 15 Sep 2023 13:29:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B7176B0387; Fri, 15 Sep 2023 13:29:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E557F6B0385 for ; Fri, 15 Sep 2023 13:29:12 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id BEC21401F8 for ; Fri, 15 Sep 2023 17:29:12 +0000 (UTC) X-FDA: 81239517744.15.3FA2042 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf20.hostedemail.com (Postfix) with ESMTP id B5D671C001B for ; Fri, 15 Sep 2023 17:29:10 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694798951; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hc2koxyA2y7kCQqZjxFs7LHGXz3tRf0rfDgr+7mNMm0=; b=UvvTn4MeQzbg7Ze4lAiX3Q7g0Sfimz7okDb/HJHKxrnMnw6l0MC4xhqZ/aQmWmQewpEdSN gL9ZzjCcAa9tKq/Dldure/odJASABIQ/IspTlcTvAprdPg28CdTXYfsdy5iBUadQMBrQ4a 2dOStMmrYiLxjPHpTgQp32GaVzdTxR0= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf20.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694798951; a=rsa-sha256; cv=none; b=qMqI3qtIlGa1kVMR6ujedFTrkI0FT6MRvXVPux7q7kDHeEOqYNra6T//mK3dWSvNEKbn3+ RxTLDaitaI6XkSZUzRlpmS3lrZP34DzHLnq/1L537OXTU3mvKipIPG2Qeur+sT22Dn2Z+4 lRkqKLhNK6feRYZU+mk6AHx44JsY8g8= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RnLjM58zJz6HJ4Y; Sat, 16 Sep 2023 01:27:19 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 15 Sep 2023 18:29:08 +0100 From: To: , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH 8/9] ACPI:RAS2: Add driver for ACPI RAS2 feature table (RAS2) Date: Sat, 16 Sep 2023 01:28:17 +0800 Message-ID: <20230915172818.761-9-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20230915172818.761-1-shiju.jose@huawei.com> References: <20230915172818.761-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B5D671C001B X-Stat-Signature: 47kic6k37fjpriu87actzpnjconousfs X-Rspam-User: X-HE-Tag: 1694798950-512295 X-HE-Meta: U2FsdGVkX1+JIUtZ2pCU2OfWcPQ/GC6LXMEeCWB7w7qVPEHFTjpJOTFMnwVuDnv8qVc33inuwQLo4kEeNb0T/nnYYYoaihJ9bVKqvTn99UjevV4mWG5wLBDmlGKhTORJSEL/EkOjps24EOWM2qssc8o3FRljqZfPeiwFS2YZDwHRqslS3QJjxhc0Qa6Itf4RqF4yGIfch0rGzBb0QwPbY+jOmwc6gGyO5QftyW9vZUWgBohg9ycA+zx6NBC3aQnrGMnPZavINpmMMH3Lyz4P4PjQ8bwMlZVg0gn7wsU2ooDuNORPrlfUyFNpT/xZ1LVmCrNjOqxC3lI5nR3g9+q8lEce7AOFO5X0kRRxP4olTVTVKHrm95VlvYQzUhcsGXj4nQDm/Rp78ow9seVsl8ZY/q2UcMauuUlv2/+eakUDcAy5zXmAcRLHwN/lNr0hh/oTKAQJVsMIRMpR50zBvGlP43WtBv6Uq480L5IAJjZzE5L5TLhSf5R69l1xDLi0TgNznFAYAC9cU/lfSBdix7ZrokZH7FzXrozzCuEhxBwyElsCMRukpWArhzhwzKNCOzR99ZPAx1kFQnjofr5ADg6+sn7Mms5bFgzRTBxwqXBSU5DNZgjqeB1hG+vM0PdLYv/LC3LluA10LbLel+08P5+bt4nPtB6aMjWEmxDpkndC9I3OLqRukUW8e6YIGqvLpqHti5f606S1I1pJuO4IWIph1XFUMqeGbjvjgVgr+F/iE/KnxtZy6RZjJfiEH/3OKjxghtQJlehs0lV9KSldD157Vd2Ddh8eST28TQtyhIuWxmZVaufO116cKmUU1eEplnB4Igs9kjPLj3XX31D+ZF8+7IK1HNbRt576tZW2x+sv/PC0aNkXzfSZ+Uf7f394kuEN73XLl0W4jB5UdDzCIT6p4F7+GN9S7ivShS2ZUB3uYzc5hHhaxdb/N/a2yzJvyMnsM6mYJuwVWtOqe28HigW KTHsbTNI 34NpwUMd6HUHgLCv/rVbdCLgcPqv/E75IaE5be/2CA2PlRYw0qcxw9UKQHH7jexCAH+yCZEEYEKApFwGm/K9JHxdz6RXErlFm+I5g3MaQf3ROCA46Tl2Xq6IJ3x+CjyCmFbVETVn+eLAKCkA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Shiju Jose Add support for ACPI RAS2 feature table (RAS2) defined in the ACPI 6.5 Specification, section 5.2.21. This driver contains RAS2 Init, which extracts the RAS2 table. Driver adds platform device, for each memory feature, which binds to the RAS2 memory driver. Signed-off-by: Shiju Jose --- drivers/acpi/Makefile | 2 +- drivers/acpi/ras2_acpi.c | 97 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100755 drivers/acpi/ras2_acpi.c diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index dd62d936cbe1..4fbe7ea0be27 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -104,7 +104,7 @@ obj-$(CONFIG_ACPI_CUSTOM_METHOD)+= custom_method.o obj-$(CONFIG_ACPI_BGRT) += bgrt.o obj-$(CONFIG_ACPI_CPPC_LIB) += cppc_acpi.o obj-$(CONFIG_ACPI_SPCR_TABLE) += spcr.o -obj-$(CONFIG_ACPI_RASF) += rasf_acpi_common.o rasf_acpi.o +obj-$(CONFIG_ACPI_RASF) += rasf_acpi_common.o rasf_acpi.o ras2_acpi.o obj-$(CONFIG_ACPI_DEBUGGER_USER) += acpi_dbg.o obj-$(CONFIG_ACPI_PPTT) += pptt.o obj-$(CONFIG_ACPI_PFRUT) += pfr_update.o pfr_telemetry.o diff --git a/drivers/acpi/ras2_acpi.c b/drivers/acpi/ras2_acpi.c new file mode 100755 index 000000000000..b8a7740355a8 --- /dev/null +++ b/drivers/acpi/ras2_acpi.c @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ras2_acpi.c - Implementation of ACPI RAS2 feature table processing + * functions. + * + * Copyright (c) 2023 HiSilicon Limited. + * + * Support for + * RAS2 - ACPI 6.5 Specification, section 5.2.21 + * + * Driver contains RAS2 init, which extracts the RAS2 table and + * registers the PCC channel for communicating with the ACPI compliant + * platform that contains RAS2 command support in hardware.Driver adds + * platform device which binds to the RAS2 memory driver. + */ + +#define pr_fmt(fmt) "ACPI RAS2: " fmt + +#include +#include +#include +#include +#include +#include + +#define RAS2_FEATURE_TYPE_MEMORY 0x00 + +int __init ras2_acpi_init(void) +{ + u8 count; + acpi_status status; + acpi_size ras2_size; + int pcc_subspace_idx; + struct platform_device *pdev; + struct acpi_table_ras2 *pRas2Table; + struct acpi_ras2_pcc_desc *pcc_desc_list; + struct platform_device **pdev_list = NULL; + struct acpi_table_header *pAcpiTable = NULL; + + status = acpi_get_table("RAS2", 0, &pAcpiTable); + if (ACPI_FAILURE(status) || !pAcpiTable) { + pr_err("ACPI RAS2 driver failed to initialize, get table failed\n"); + return RASF_FAILURE; + } + + ras2_size = pAcpiTable->length; + if (ras2_size < sizeof(struct acpi_table_ras2)) { + pr_err("ACPI RAS2 table present but broken (too short #1)\n"); + goto free_ras2_table; + } + + pRas2Table = (struct acpi_table_ras2 *)pAcpiTable; + + if (pRas2Table->num_pcc_descs <= 0) { + pr_err("ACPI RAS2 table does not contain PCC descriptors\n"); + goto free_ras2_table; + } + + pdev_list = kzalloc((pRas2Table->num_pcc_descs * sizeof(struct platform_device *)), + GFP_KERNEL); + if (!pdev_list) + goto free_ras2_table; + + pcc_desc_list = (struct acpi_ras2_pcc_desc *) + ((void *)pRas2Table + sizeof(struct acpi_table_ras2)); + count = 0; + while (count < pRas2Table->num_pcc_descs) { + if (pcc_desc_list->feature_type == RAS2_FEATURE_TYPE_MEMORY) { + pcc_subspace_idx = pcc_desc_list->channel_id; + /* Add the platform device and bind ras2 memory driver */ + pdev = rasf_add_platform_device("ras2", &pcc_subspace_idx, + sizeof(pcc_subspace_idx)); + if (!pdev) + goto free_ras2_pdev; + pdev_list[count] = pdev; + } + count++; + pcc_desc_list = pcc_desc_list + sizeof(struct acpi_ras2_pcc_desc); + } + + acpi_put_table(pAcpiTable); + return RASF_SUCCESS; + +free_ras2_pdev: + count = 0; + while (count < pRas2Table->num_pcc_descs) { + if (pcc_desc_list->feature_type == + RAS2_FEATURE_TYPE_MEMORY) + platform_device_put(pdev_list[count++]); + } + kfree(pdev_list); + +free_ras2_table: + acpi_put_table(pAcpiTable); + return RASF_FAILURE; +} +late_initcall(ras2_acpi_init) From patchwork Fri Sep 15 17:28:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiju Jose X-Patchwork-Id: 13387311 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E84D4EED61B for ; Fri, 15 Sep 2023 17:29:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8CE546B0386; Fri, 15 Sep 2023 13:29:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8804B6B0388; Fri, 15 Sep 2023 13:29:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FA106B0387; Fri, 15 Sep 2023 13:29:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 2209E6B0388 for ; Fri, 15 Sep 2023 13:29:13 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EF8F01606F9 for ; Fri, 15 Sep 2023 17:29:12 +0000 (UTC) X-FDA: 81239517744.16.9673019 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by imf12.hostedemail.com (Postfix) with ESMTP id 0212C40003 for ; Fri, 15 Sep 2023 17:29:10 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694798951; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ECvtfO2xiDIKGPqn3Y8VCkd/LwbaCC1OtAlrpDBaHvA=; b=Lwqz5G32SDDAF/t+MYyTxWIGaJ6UkHU1yp2hWtsU0HQDBErEaipQj/20XO82mdj7gjWb/9 559q8cmdoARz/hVaIqFcHuv+UkqCXil7zx5scSQVhFnlT9sIpFGlv6AQ1qWUstR0VTNWTB cK1dCrn49Agpj1RyaQgHyR1i4QuW4Q4= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of shiju.jose@huawei.com designates 185.176.79.56 as permitted sender) smtp.mailfrom=shiju.jose@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694798951; a=rsa-sha256; cv=none; b=dAMOPnDCTWqTqD4N5V0ZjBoPIUFveudcnmKaSZ3HEgAmg2wW5k0YspeB9qOSuvJMoKGnt9 1beBdMBl5iQamJ+yNdolV1iBlyQbjJn7St1Afrcx1QuxDbprigv3v+LoKfK4ginOc6Xpkq 1xnRdcHhZhK51FuFsirDBDxe9v38+/Y= Received: from lhrpeml500006.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4RnLjN0QpMz6HJfL; Sat, 16 Sep 2023 01:27:20 +0800 (CST) Received: from SecurePC30232.china.huawei.com (10.122.247.234) by lhrpeml500006.china.huawei.com (7.191.161.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 15 Sep 2023 18:29:08 +0100 From: To: , , CC: , , , , , , , , , , , , , , , , , , , , , Subject: [RFC PATCH 9/9] memory: RAS2: Add memory RAS2 driver Date: Sat, 16 Sep 2023 01:28:18 +0800 Message-ID: <20230915172818.761-10-shiju.jose@huawei.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20230915172818.761-1-shiju.jose@huawei.com> References: <20230915172818.761-1-shiju.jose@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.122.247.234] X-ClientProxiedBy: lhrpeml500001.china.huawei.com (7.191.163.213) To lhrpeml500006.china.huawei.com (7.191.161.198) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0212C40003 X-Stat-Signature: 7jfazwdob8zapjffbnog95xgbxgwx6cj X-HE-Tag: 1694798950-828234 X-HE-Meta: U2FsdGVkX1/OITON3Z7ZtYn4sAliiSBYn9PYIRo7CFspvNgcs5XUWgzeSqx69r6iloQKkCYVW6VUgjhQ11k5+BfkUtzzxZ3oTIPumXvveJ3sN35/xIm5WCGOXZm+YLr7P0oPdK3ktHe9MZXAFxLYYoTBSYh6B3+aw+OKfPfFKFJJbLQSiyeEO0tQCmGYgDKBfPxGsmpO+tGvR+MsKHgkwqtM59RqiA2erm0XdYQ8XTiDMh6DAM6Bog3q55Rh1XatVEljW+EFGGBiNfez1M75L2MnafaVJHeP59iaMXyMswYclWl3oH1ODtxNtM56gIrHNi+EmnexuuHdAiz+QYtkYu6fiHRG3Ou8gst4dWOiI8QDkxR+EtFLbqfNa/eDhalyIm5nfHtdm9B7ESe5YRGVqpI6vm21Rq+8KI+hYLFG1gcJzkNCUUm0ykP6coQChkz2WtS0/d0PTgLvRlvDZbca4ONS5sqlKvSXc+LW7zYGnjCTrnN+WcTpLFDvDv9OVgkAwfxGaTsKhbCx1T5Tdkg5OL+NpuJFpiOEmTlpapGI+t07SdzWUNwcDegAlAOfn2fLsQ9X4VHQ+cMbhRURjnF/1OPAYRsR49h9jWIz2pW+5R+4FX4y/6DkJ4XjQu7zuBIkefAAjC2Ai0UQ8uAY0W2oDAz+t74pHyzLFKiAjSVkNC5IuGTSbt0gofVjA3wT4cXkGsyHa+FGIs5dSiToXEFfWm0KYFessGEkWVOKOP+rLAQD8qVXbaNGJRZxPLLPdEJf3iGCtBoG0VIqwIfdazTCN1DASNoG2Ci2DrZVE1NuptmOW33NropiJxZIQwyEkLwDMJwLq2J8V6rkg+CK8BAMkJy0JBQiUkQ6HxeUaI9wY6xYPRRZ70ey8gfcfV3+JTc2OguT4Z3xBnvI4j/kBuqbQo/KoU9GVZOhSExBeC12SZWlCJFmE6NmOcZ9ccOe03xabH7kX/RLURWlW2iGHGs 3zfJGkXK Bdq7cBVhnLgs1rTvXFN9j/9dIfwBar0oLxpeo8i07GDPrU78WjGUparUhRGKVHqh9NTPITkciGXltsxoieOjYUl3d6k1z+3ZrME9gToem+1UhPwepyIMPYB1h1yH8xoTZfQjvJhuB2B0ao+M= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Shiju Jose Memory RAS2 driver binds to the platform device add by the ACPI RAS2 driver. Driver registers the PCC channel for communicating with the ACPI compliant platform that contains RAS2 command support in the hardware. Add interface functions to support configuring the parameters of HW patrol scrubber in the system, which exposed to the kernel via the RAS2 and PCC, using the RAS2 commands. Add support for RAS2 platform devices to register with scrub config driver. This enables user to configure the parameters of HW patrol scrubbers, which exposed to the kernel via the RAS2 table, through the scrub sysfs attributes. Signed-off-by: Shiju Jose --- drivers/memory/Makefile | 2 +- drivers/memory/ras2.c | 334 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 335 insertions(+), 1 deletion(-) create mode 100644 drivers/memory/ras2.c diff --git a/drivers/memory/Makefile b/drivers/memory/Makefile index 49340cd100fc..b4b8ff7c6926 100644 --- a/drivers/memory/Makefile +++ b/drivers/memory/Makefile @@ -7,7 +7,7 @@ obj-$(CONFIG_DDR) += jedec_ddr_data.o ifeq ($(CONFIG_DDR),y) obj-$(CONFIG_OF) += of_memory.o endif -obj-$(CONFIG_MEM_RASF) += rasf_common.o rasf.o +obj-$(CONFIG_MEM_RASF) += rasf_common.o rasf.o ras2.o obj-$(CONFIG_ARM_PL172_MPMC) += pl172.o obj-$(CONFIG_ATMEL_EBI) += atmel-ebi.o diff --git a/drivers/memory/ras2.c b/drivers/memory/ras2.c new file mode 100644 index 000000000000..80da996bf12e --- /dev/null +++ b/drivers/memory/ras2.c @@ -0,0 +1,334 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * ras2.c - ACPI RAS2 memory driver + * + * Copyright (c) 2023 HiSilicon Limited. + * + * - Registers the PCC channel for communicating with the + * ACPI compliant platform that contains RAS2 command + * support in the hardware. + * - Provides functions to configure HW patrol scrubber + * in the system. + * - Registers with the scrub configure driver for the + * hw patrol scrubber in the system, which exposed via + * the ACPI RAS2 table and PCC. + */ + +#define pr_fmt(fmt) "MEMORY RAS2: " fmt + +#include +#include +#include +#include + +#include +#include + +/* RAS2 specific definitions. */ +#define RAS2_SCRUB "ras2_scrub" +#define RAS2_ID_FORMAT RAS2_SCRUB "%d" +#define RAS2_SUPPORT_HW_PARTOL_SCRUB BIT(0) +#define RAS2_TYPE_PATROL_SCRUB 0x0000 + +#define RAS2_GET_PATROL_PARAMETERS 0x01 +#define RAS2_START_PATROL_SCRUBBER 0x02 +#define RAS2_STOP_PATROL_SCRUBBER 0x03 + +#define RAS2_PATROL_SCRUB_RATE_VALID BIT(0) +#define RAS2_PATROL_SCRUB_RATE_IN_MASK GENMASK(15, 8) +#define RAS2_PATROL_SCRUB_EN_BACKGROUND BIT(0) +#define RAS2_PATROL_SCRUB_RATE_OUT_MASK GENMASK(7, 0) +#define RAS2_PATROL_SCRUB_MIN_RATE_OUT_MASK GENMASK(15, 8) +#define RAS2_PATROL_SCRUB_MAX_RATE_OUT_MASK GENMASK(23, 16) + +/* The default number of regions for RAS2 */ +#define RAS2_NUM_REGIONS 1 + +static void ras2_tx_done(struct mbox_client *cl, void *msg, int ret) +{ + if (ret) { + dev_dbg(cl->dev, "TX did not complete: CMD sent:%x, ret:%d\n", + *(u16 *)msg, ret); + } else { + dev_dbg(cl->dev, "TX completed. CMD sent:%x, ret:%d\n", + *(u16 *)msg, ret); + } +} + +/* + * The below functions are exposed to OSPM, to query, configure and + * initiate memory patrol scrubber. + */ +static int ras2_is_patrol_scrub_support(struct rasf_context *ras2_ctx) +{ + int ret; + struct acpi_ras2_shared_memory __iomem *generic_comm_base; + + if (!ras2_ctx || !ras2_ctx->pcc_comm_addr) + return -EFAULT; + + generic_comm_base = ras2_ctx->pcc_comm_addr; + guard(spinlock_irqsave)(&ras2_ctx->spinlock); + generic_comm_base->set_capabilities[0] = 0; + + /* send command for reading RAS2 capabilities */ + ret = rasf_send_pcc_cmd(ras2_ctx, RASF_PCC_CMD_EXEC); + if (ret) { + pr_err("%s: rasf_send_pcc_cmd failed\n", __func__); + return ret; + } + + return generic_comm_base->features[0] & RAS2_SUPPORT_HW_PARTOL_SCRUB; +} + +static int ras2_get_patrol_scrub_params(struct rasf_context *ras2_ctx, + struct rasf_scrub_params *params) +{ + int ret = 0; + u8 min_supp_scrub_rate, max_supp_scrub_rate; + struct acpi_ras2_shared_memory __iomem *generic_comm_base; + struct acpi_ras2_patrol_scrub_parameter __iomem *patrol_scrub_params; + + if (!ras2_ctx || !ras2_ctx->pcc_comm_addr) + return -EFAULT; + + generic_comm_base = ras2_ctx->pcc_comm_addr; + patrol_scrub_params = ras2_ctx->pcc_comm_addr + sizeof(*generic_comm_base); + + guard(spinlock_irqsave)(&ras2_ctx->spinlock); + generic_comm_base->set_capabilities[0] = RAS2_SUPPORT_HW_PARTOL_SCRUB; + /* send command for reading RASF capabilities */ + ret = rasf_send_pcc_cmd(ras2_ctx, RASF_PCC_CMD_EXEC); + if (ret) { + pr_err("%s: rasf_send_pcc_cmd failed\n", __func__); + return ret; + } + + if (!(generic_comm_base->features[0] & RAS2_SUPPORT_HW_PARTOL_SCRUB) || + !(generic_comm_base->num_parameter_blocks)) { + pr_err("%s: Platform does not support HW Patrol Scrubber\n", __func__); + return -ENOTSUPP; + } + + if (!patrol_scrub_params->requested_address_range[1]) { + pr_err("%s: Invalid requested address range, \ + requested_address_range[0]=0x%llx \ + requested_address_range[1]=0x%llx\n", + __func__, + patrol_scrub_params->requested_address_range[0], + patrol_scrub_params->requested_address_range[1]); + return -ENOTSUPP; + } + + generic_comm_base->set_capabilities[0] = RAS2_SUPPORT_HW_PARTOL_SCRUB; + patrol_scrub_params->header.type = RAS2_TYPE_PATROL_SCRUB; + patrol_scrub_params->patrol_scrub_command = RAS2_GET_PATROL_PARAMETERS; + + /* send command for reading the HW patrol scrub parameters */ + ret = rasf_send_pcc_cmd(ras2_ctx, RASF_PCC_CMD_EXEC); + if (ret) { + pr_err("%s: failed to read HW patrol scrub parameters\n", __func__); + return ret; + } + + /* copy output scrub parameters */ + params->addr_base = patrol_scrub_params->actual_address_range[0]; + params->addr_size = patrol_scrub_params->actual_address_range[1]; + params->flags = patrol_scrub_params->flags; + if (patrol_scrub_params->flags & RAS2_PATROL_SCRUB_RATE_VALID) { + params->speed = FIELD_GET(RAS2_PATROL_SCRUB_RATE_OUT_MASK, + patrol_scrub_params->scrub_params_out); + min_supp_scrub_rate = FIELD_GET(RAS2_PATROL_SCRUB_MIN_RATE_OUT_MASK, + patrol_scrub_params->scrub_params_out); + max_supp_scrub_rate = FIELD_GET(RAS2_PATROL_SCRUB_MAX_RATE_OUT_MASK, + patrol_scrub_params->scrub_params_out); + snprintf(params->speed_avail, RASF_MAX_SPEED_RANGE_LENGTH, + "%d-%d", min_supp_scrub_rate, max_supp_scrub_rate); + } else { + params->speed = 0; + snprintf(params->speed_avail, RASF_MAX_SPEED_RANGE_LENGTH, + "%s", "Unavailable"); + } + + return 0; +} + +static int ras2_enable_patrol_scrub(struct rasf_context *ras2_ctx, bool enable) +{ + int ret = 0; + struct rasf_scrub_params params; + struct acpi_ras2_shared_memory __iomem *generic_comm_base; + u8 scrub_rate_to_set, min_supp_scrub_rate, max_supp_scrub_rate; + struct acpi_ras2_patrol_scrub_parameter __iomem *patrol_scrub_params; + + if (!ras2_ctx || !ras2_ctx->pcc_comm_addr) + return -EFAULT; + + generic_comm_base = ras2_ctx->pcc_comm_addr; + patrol_scrub_params = ras2_ctx->pcc_comm_addr + sizeof(*generic_comm_base); + + if (enable) { + ret = ras2_get_patrol_scrub_params(ras2_ctx, ¶ms); + if (ret) + return ret; + } + + guard(spinlock_irqsave)(&ras2_ctx->spinlock); + generic_comm_base->set_capabilities[0] = RAS2_SUPPORT_HW_PARTOL_SCRUB; + patrol_scrub_params->header.type = RAS2_TYPE_PATROL_SCRUB; + + if (enable) { + patrol_scrub_params->patrol_scrub_command = RAS2_START_PATROL_SCRUBBER; + patrol_scrub_params->requested_address_range[0] = params.addr_base; + patrol_scrub_params->requested_address_range[1] = params.addr_size; + + if (patrol_scrub_params->flags & RAS2_PATROL_SCRUB_RATE_VALID) { + scrub_rate_to_set = FIELD_GET(RAS2_PATROL_SCRUB_RATE_IN_MASK, + patrol_scrub_params->scrub_params_in); + min_supp_scrub_rate = FIELD_GET(RAS2_PATROL_SCRUB_MIN_RATE_OUT_MASK, + patrol_scrub_params->scrub_params_out); + max_supp_scrub_rate = FIELD_GET(RAS2_PATROL_SCRUB_MAX_RATE_OUT_MASK, + patrol_scrub_params->scrub_params_out); + if (scrub_rate_to_set < min_supp_scrub_rate || + scrub_rate_to_set > max_supp_scrub_rate) { + pr_warn("patrol scrub rate to set is out of the supported range\n"); + pr_warn("min_supp_scrub_rate=%d max_supp_scrub_rate=%d\n", + min_supp_scrub_rate, max_supp_scrub_rate); + return -EINVAL; + } + } + } else + patrol_scrub_params->patrol_scrub_command = RAS2_STOP_PATROL_SCRUBBER; + + /* send command for enable/disable HW patrol scrub */ + ret = rasf_send_pcc_cmd(ras2_ctx, RASF_PCC_CMD_EXEC); + if (ret) { + pr_err("%s: failed to enable/disable the HW patrol scrub\n", __func__); + return ret; + } + + return 0; +} + +static int ras2_set_patrol_scrub_params(struct rasf_context *ras2_ctx, + struct rasf_scrub_params *params, u8 param_type) +{ + struct acpi_ras2_shared_memory __iomem *generic_comm_base; + struct acpi_ras2_patrol_scrub_parameter __iomem *patrol_scrub_params; + + if (!ras2_ctx || !ras2_ctx->pcc_comm_addr) + return -EFAULT; + + generic_comm_base = ras2_ctx->pcc_comm_addr; + patrol_scrub_params = ras2_ctx->pcc_comm_addr + sizeof(*generic_comm_base); + + guard(spinlock_irqsave)(&ras2_ctx->spinlock); + patrol_scrub_params->header.type = RAS2_TYPE_PATROL_SCRUB; + if (param_type == RASF_MEM_SCRUB_PARAM_ADDR_BASE && params->addr_base) { + patrol_scrub_params->requested_address_range[0] = params->addr_base; + } else if (param_type == RASF_MEM_SCRUB_PARAM_ADDR_SIZE && params->addr_size) { + patrol_scrub_params->requested_address_range[1] = params->addr_size; + } else if (param_type == RASF_MEM_SCRUB_PARAM_SPEED) { + patrol_scrub_params->scrub_params_in &= ~RAS2_PATROL_SCRUB_RATE_IN_MASK; + patrol_scrub_params->scrub_params_in |= FIELD_PREP(RAS2_PATROL_SCRUB_RATE_IN_MASK, + params->speed); + } else { + pr_err("Invalid patrol scrub parameter to set\n"); + return -EINVAL; + } + + return 0; +} + +static const struct rasf_hw_scrub_ops ras2_hw_ops = { + .enable_scrub = ras2_enable_patrol_scrub, + .get_scrub_params = ras2_get_patrol_scrub_params, + .set_scrub_params = ras2_set_patrol_scrub_params, +}; + +static const struct scrub_ops ras2_scrub_ops = { + .is_visible = rasf_hw_scrub_is_visible, + .read = rasf_hw_scrub_read, + .write = rasf_hw_scrub_write, + .read_string = rasf_hw_scrub_read_strings, +}; + +static DEFINE_IDA(ras2_ida); + +static void devm_ras2_release(void *ctx) +{ + struct rasf_context *ras2_ctx = ctx; + + ida_free(&ras2_ida, ras2_ctx->id); + rasf_unregister_pcc_channel(ras2_ctx); +} + +static int ras2_probe(struct platform_device *pdev) +{ + int ret, id; + struct mbox_client *cl; + struct device *hw_scrub_dev; + struct rasf_context *ras2_ctx; + char scrub_name[RASF_MAX_NAME_LENGTH]; + + ras2_ctx = devm_kzalloc(&pdev->dev, sizeof(*ras2_ctx), GFP_KERNEL); + if (!ras2_ctx) + return -ENOMEM; + + ras2_ctx->dev = &pdev->dev; + ras2_ctx->ops = &ras2_hw_ops; + spin_lock_init(&ras2_ctx->spinlock); + platform_set_drvdata(pdev, ras2_ctx); + + cl = &ras2_ctx->mbox_client; + /* Request mailbox channel */ + cl->dev = &pdev->dev; + cl->tx_done = ras2_tx_done; + cl->knows_txdone = true; + ras2_ctx->pcc_subspace_idx = *((int *)pdev->dev.platform_data); + dev_dbg(&pdev->dev, "pcc-subspace-id=%d\n", ras2_ctx->pcc_subspace_idx); + ret = rasf_register_pcc_channel(ras2_ctx); + if (ret < 0) + return ret; + + ret = devm_add_action_or_reset(&pdev->dev, devm_ras2_release, ras2_ctx); + if (ret < 0) + return ret; + + if (ras2_is_patrol_scrub_support(ras2_ctx)) { + id = ida_alloc(&ras2_ida, GFP_KERNEL); + if (id < 0) + return id; + ras2_ctx->id = id; + ras2_ctx->n_regions = RAS2_NUM_REGIONS; + snprintf(scrub_name, sizeof(scrub_name), "%s%d", RAS2_SCRUB, id); + dev_set_name(&pdev->dev, RAS2_ID_FORMAT, id); + hw_scrub_dev = devm_scrub_device_register(&pdev->dev, scrub_name, + ras2_ctx, &ras2_scrub_ops, + ras2_ctx->n_regions); + if (PTR_ERR_OR_ZERO(hw_scrub_dev)) + return PTR_ERR_OR_ZERO(hw_scrub_dev); + } + ras2_ctx->scrub_dev = hw_scrub_dev; + + return 0; +} + +static const struct platform_device_id ras2_id_table[] = { + { .name = "ras2", }, + { } +}; +MODULE_DEVICE_TABLE(platform, ras2_id_table); + +static struct platform_driver ras2_driver = { + .probe = ras2_probe, + .driver = { + .name = "ras2", + .suppress_bind_attrs = true, + }, + .id_table = ras2_id_table, +}; +module_driver(ras2_driver, platform_driver_register, platform_driver_unregister); + +MODULE_DESCRIPTION("ras2 memory driver"); +MODULE_LICENSE("GPL");