Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp5023817ybb; Tue, 24 Mar 2020 09:32:12 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvqGnqei3oQkshAp77Rwqoe6V330hl5amm5+L0aj7NPx9YdQqhUU9a1LAaSwJrOnAvtZvzF X-Received: by 2002:aca:3b82:: with SMTP id i124mr3019630oia.61.1585067531984; Tue, 24 Mar 2020 09:32:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585067531; cv=none; d=google.com; s=arc-20160816; b=t4KMdKSjz50iZVI6Fhqh4bI+oM1Bqt5F1Tmyi0UjXac6bffQdgIEj7QRz0hVn0vSLs n4GjeQbuXkMfzSQtymXcHu8AyI+P2RMMeMxSw9BOidxktP+xUIJwozvkVOFw1hF9p4/j 4MEKNqdvKM3gnu7vAZNNeQiCU+6DFO7Sgr5ww3VKY2W+AqJVLKSXvq0R9B+mg8MweG4T g3Spxh5bREcgiRLLpglepWMkfJHPP5mG0ZVL7224yT8tns1g8Hgyt35ldgALJJOaAVh3 Ob4VqUqzDbJcVVi9naTP3kvIczS6nAiUy2PQrUFGHuTfh4aP0sSfW6svZrsjG6lL3RH/ R9kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=rgCsvYUi5hieaT2GOS4e0RuO+YGJX6nXyFpJN8x642c=; b=FL4mpURmndSpcOm9KJuJ0nntiUj5XCeTCUVRsActcGt5CdzgKxFCrrte6Mflku07yK 6Teb5DXrI+5Nzcz29s3fg12gx2qhFcXvdrXNvZ31aiHWeBU9pHyI+TqihVelUllm/ueC 1lWim4gukfH0RTzNqw0uz5hN8SMG7Vu4jEcYvhfJW9mfF466ozH+VbHnSG+1UBvnUFqz Hd48HyNhEgrsYL4c3jQA5MGu71k8N08wXYVjszWtPIlHLouHLEPKT8mTWYiSKCNIlcs9 20p1LmYuXJNc/sg3BTV2EhRqi4+UBHqtQLbVmnn7C4Ri1iweB21gAf78ZxjdYm2M71uS anCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14si6259286ota.96.2020.03.24.09.31.58; Tue, 24 Mar 2020 09:32:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728071AbgCXQbS (ORCPT + 99 others); Tue, 24 Mar 2020 12:31:18 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:51726 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727693AbgCXQbR (ORCPT ); Tue, 24 Mar 2020 12:31:17 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 1E5862969FD Subject: Re: [PATCH v2] platform: x86: Add ACPI driver for ChromeOS To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, vbendeb@chromium.org, groeck@chromium.org, bleung@chromium.org, dtor@chromium.org, gwendal@chromium.org, andy@infradead.org, Collabora Kernel ML , Ayman Bagabas , Darren Hart , Dmitry Torokhov , Jeremy Soller , Mattias Jacobsson <2pi@mok.nu>, Mauro Carvalho Chehab , Rajat Jain , Srinivas Pandruvada , Yauhen Kharuzhy , platform-driver-x86@vger.kernel.org References: <20200322094334.1872663-1-enric.balletbo@collabora.com> <20200322111022.GA72939@kroah.com> From: Enric Balletbo i Serra Message-ID: Date: Tue, 24 Mar 2020 17:31:10 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200322111022.GA72939@kroah.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Greg, Many thanks for your quick answer, some comments below. On 22/3/20 12:10, Greg Kroah-Hartman wrote: > On Sun, Mar 22, 2020 at 10:43:34AM +0100, Enric Balletbo i Serra wrote: >> This driver attaches to the ChromeOS ACPI device and then exports the values >> reported by the ACPI in a sysfs directory. The ACPI values are presented in >> the string form (numbers as decimal values) or binary blobs, and can be >> accessed as the contents of the appropriate read only files in the sysfs >> directory tree originating in /sys/devices/platform/chromeos_acpi. >> >> Signed-off-by: Enric Balletbo i Serra > > What is wrong with the "default" ACPI sysfs access? Why do you need a > special driver just for this specific ACPI firmware? > Please correct me if I am wrong, as I'm not an ACPI expert and I probably have some ACPI leaks and misunderstandings. What is exporting this driver is the attributes for the non-default Chromebook specific MLST ACPI method. Hence, I assumed we needed a special driver to expose these values that can't be done using "default" ACPI sysfs. Note that these attributes are dynamically created and are different between Chromebooks so need some parsing. I didn't find a "standard" way to expose these attributes to userspace, so, please kindly point me to one if there is one. > Also, you forgot to add Documentation/ABI/ entries for your new files :( > Right, my bad. Not all Chromebooks have the same values. I can document the ones that are created on the devices I have but I'll probably miss some of them. I'll do some firmware research regarding this. >> +config ACPI_CHROMEOS >> + tristate "ChromeOS specific ACPI extensions" >> + depends on ACPI >> + depends on CHROME_PLATFORMS > > No BUILD_TEST? > Will add in the next version. > >> +static void >> +chromeos_acpi_remove_attribs(struct chromeos_acpi_attribute_group *aag) >> +{ >> + struct chromeos_acpi_attribute *attr, *tmp_attr; >> + >> + list_for_each_entry_safe(attr, tmp_attr, &aag->attribs, list) { >> + sysfs_remove_bin_file(aag->kobj, &attr->bin_attr); > > Attribute groups are your friend, do not do this "by hand". > I thought that the code is more readable doing it attribute by attribute, and the reason is that apart from remove the bin file I should also free the name, the data and the specific struct to store the attribute itself as all are dynamically allocated. Using attribute groups I should do two steps: sysfs_remove_group() list_for_each_entry_safe(attr, tmp_attr, &aag->attribs, list) { kfree(attr->name); kfree(attr->data); kfree(attr); } Ok, will do that in next version. >> + kfree(attr->name); >> + kfree(attr->data); >> + kfree(attr); >> + } >> +} >> + >> +/** >> + * chromeos_acpi_add_group() - Create a sysfs group including attributes >> + * representing a nested ACPI package. >> + * >> + * @obj: Package contents as returned by ACPI. >> + * @name: Name of the group. >> + * @num_attrs: Number of attributes of this package. >> + * @index: Index number of this particular group. >> + * >> + * The created group is called @name in case there is a single instance, or >> + * @name.@index otherwise. >> + * >> + * All group and attribute storage allocations are included in the lists for >> + * tracking of allocated memory. >> + * >> + * Return: 0 on success, negative errno on failure. >> + */ >> +static int chromeos_acpi_add_group(union acpi_object *obj, char *name, >> + int num_attrs, int index) >> +{ >> + struct device *dev = &chromeos_acpi.pdev->dev; >> + struct chromeos_acpi_attribute_group *aag; >> + union acpi_object *element; >> + int i, count, ret; >> + >> + aag = kzalloc(sizeof(*aag), GFP_KERNEL); >> + if (!aag) >> + return -ENOMEM; >> + >> + aag->name = chromeos_acpi_alloc_name(name, num_attrs, index); >> + if (!aag->name) { >> + ret = -ENOMEM; >> + goto free_group; >> + } >> + >> + aag->kobj = kobject_create_and_add(aag->name, &dev->kobj); > > By using "raw" kobjects, you just now prevented any userspace tool from > seeing these attributes (like udev). Not nice :( > > Why, if you really really have to do this, are you not just using > "normal" struct device attributes instead? > Ok. >> +static int __init chromeos_acpi_init(void) >> +{ >> + int ret; >> + >> + chromeos_acpi.pdev = platform_device_register_simple("chromeos_acpi", >> + PLATFORM_DEVID_NONE, NULL, 0); >> + if (IS_ERR(chromeos_acpi.pdev)) { >> + pr_err("unable to register chromeos_acpi platform device\n"); >> + return PTR_ERR(chromeos_acpi.pdev); >> + } > > Only use platform devices and drivers for things that are actually > platform devices and drivers. That's not what this is, it is an ACPI > device and driver. Don't abuse the platform interface please. > Ok. The purpose was to not break ChromeOS userspace since is looking for the attributes inside /sys/devices/platform/chromeos_acpi. Not a good reason, I know, and I assume we will need to change userspace instead, and convert this to a ACPI device and driver only, right? I'll investigate the different places in userspace where this is used and see how difficult it is to do the changes. Thanks, ~Enric > thanks, > > greg k-h >