From patchwork Fri Jan 4 22:38:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bjorn Helgaas X-Patchwork-Id: 1935111 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 591863FF0F for ; Fri, 4 Jan 2013 22:38:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754749Ab3ADWiM (ORCPT ); Fri, 4 Jan 2013 17:38:12 -0500 Received: from mail-ye0-f202.google.com ([209.85.213.202]:48209 "EHLO mail-ye0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754618Ab3ADWiM (ORCPT ); Fri, 4 Jan 2013 17:38:12 -0500 Received: by mail-ye0-f202.google.com with SMTP id r9so963380yen.3 for ; Fri, 04 Jan 2013 14:38:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:subject:to:from:cc:date:message-id:user-agent :mime-version:content-type:content-transfer-encoding; bh=qgIi6YLkonOBcUxJXCXIGA6lEqAGxCqG1naQ/nMH+38=; b=KrxP65M54FCbo44t49vWI1vDyGEV5G65LCCX9viVc3l3FWXsw5324Xi+brvgYMskUL hlbBoXZjMVT2NNa0uM+YQf8N7COLA/GR/9cVR45UhxV7+xXGnvRwnLkwr7ShZS7UHjc8 TiE8BUtY9U3tJOiAWgGr4ZCT+CV3TB6Sr15LiJh2+78Bqejyb1hFRQ2I40qWa1MCWzcF 931X32kCYOCpQBVhaOasqv1CHq+MBzhSH2C80kVE2Rcftg0h/C7R9eCfzS5+/YACvKFB jBJoGHV2fZYwjoqYq7S4qtPwRqJzc1aoFz9eDMK2cObn79wP3QiK3Aj4wYZ3NLo7uSvE mi5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:subject:to:from:cc:date:message-id:user-agent :mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=qgIi6YLkonOBcUxJXCXIGA6lEqAGxCqG1naQ/nMH+38=; b=Fu/DDkcbN7lLqQRgD3HIMcDA7DLcGV80GX5veUG87BKlI6HaGl53+8dfoFsjgxHENq efCpNlZmuTqK/Gb1AlnQD69DYkgN7tB8+oVsARj9Hg47VmoNM+86vtYG/wFufJdSVB1w e5aNaxINF8ugypsXJcn9oCRQu8yTQ5H5KdcVTrx3M5o3EDnLLmghWYr/fNHeqoV6BA7Q uCMhOp5T4MveqEcQgalZhVBdyj/iCHNdU3/UBBIUUBsW2Iwu4koqD63D2jQNx3eL0otH IZe3C4K5x7rINKiwHf5mB6BjeNW8BwbHi/976ZT4olVd87mINeeE92VSKuItoofBvrJ1 GC3g== X-Received: by 10.236.173.130 with SMTP id v2mr26488334yhl.41.1357339091508; Fri, 04 Jan 2013 14:38:11 -0800 (PST) Received: from wpzn4.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id i27si4485325yhe.4.2013.01.04.14.38.11 (version=TLSv1/SSLv3 cipher=AES128-SHA); Fri, 04 Jan 2013 14:38:11 -0800 (PST) Received: from bhelgaas.mtv.corp.google.com (bhelgaas.mtv.corp.google.com [172.17.131.112]) by wpzn4.hot.corp.google.com (Postfix) with ESMTP id 45C3082004A; Fri, 4 Jan 2013 14:38:11 -0800 (PST) Received: from bhelgaas.mtv.corp.google.com (unknown [IPv6:::1]) by bhelgaas.mtv.corp.google.com (Postfix) with ESMTP id E67FC18016C; Fri, 4 Jan 2013 14:38:10 -0800 (PST) Subject: [PATCH] PNPACPI: Use _CRS buffer directly as _SRS template To: "Rafael J. Wysocki" , Len Brown From: Bjorn Helgaas Cc: linux-acpi@vger.kernel.org Date: Fri, 04 Jan 2013 15:38:10 -0700 Message-ID: <20130104223810.4806.72475.stgit@bhelgaas.mtv.corp.google.com> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQmheGPkPEpLNObt0deM9VTSXaTgxrdgUYl1s2e5OFckLdD8EO50VBPaK8SqyKOGsvBMshVdHtcWrcpWPrvu7P1dH4PHw0I2DqD7c7DLpw5SR0B2ex8+hOJmmrTjs4xRUnohkrUQI3l/eM7al103jfmyk6/sgbMkh2TQR5c3wALYjfpnjlpUivUVNbsH2Z6p2ukms8t8MeXfb15V+mLYAwkYb1OXAg== Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Previously we went to a lot of trouble to count the supported descriptors in _CRS, allocate a new buffer, copy the descriptor types to the new buffer, and encode resources into the new buffer. This will fail if _CRS contains a descriptor type we don't support, even if we don't need to change that descriptor. I think it's simpler and more correct to just use the buffer returned from _CRS directly, as suggested by the ACPI spec rev 5.0, sec 6.2.15. Signed-off-by: Bjorn Helgaas --- drivers/pnp/pnpacpi/core.c | 10 +++-- drivers/pnp/pnpacpi/rsparser.c | 85 ---------------------------------------- 2 files changed, 6 insertions(+), 89 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c index 72e822e..701e00e 100644 --- a/drivers/pnp/pnpacpi/core.c +++ b/drivers/pnp/pnpacpi/core.c @@ -84,7 +84,8 @@ static int pnpacpi_set_resources(struct pnp_dev *dev) { struct acpi_device *acpi_dev; acpi_handle handle; - struct acpi_buffer buffer; + struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; + acpi_status status; int ret; pnp_dbg(&dev->dev, "set resources\n"); @@ -98,9 +99,10 @@ static int pnpacpi_set_resources(struct pnp_dev *dev) if (WARN_ON_ONCE(acpi_dev != dev->data)) dev->data = acpi_dev; - ret = pnpacpi_build_resource_template(dev, &buffer); - if (ret) - return ret; + status = acpi_evaluate_object(handle, METHOD_NAME__CRS, NULL, &buffer); + if (ACPI_FAILURE(status)) + return -EINVAL; + ret = pnpacpi_encode_resources(dev, &buffer); if (ret) { kfree(buffer.pointer); diff --git a/drivers/pnp/pnpacpi/rsparser.c b/drivers/pnp/pnpacpi/rsparser.c index b8f4ea7..629710a 100644 --- a/drivers/pnp/pnpacpi/rsparser.c +++ b/drivers/pnp/pnpacpi/rsparser.c @@ -553,91 +553,6 @@ int __init pnpacpi_parse_resource_option_data(struct pnp_dev *dev) return 0; } -static int pnpacpi_supported_resource(struct acpi_resource *res) -{ - switch (res->type) { - case ACPI_RESOURCE_TYPE_IRQ: - case ACPI_RESOURCE_TYPE_DMA: - case ACPI_RESOURCE_TYPE_IO: - case ACPI_RESOURCE_TYPE_FIXED_IO: - case ACPI_RESOURCE_TYPE_MEMORY24: - case ACPI_RESOURCE_TYPE_MEMORY32: - case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: - case ACPI_RESOURCE_TYPE_ADDRESS16: - case ACPI_RESOURCE_TYPE_ADDRESS32: - case ACPI_RESOURCE_TYPE_ADDRESS64: - case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64: - case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: - return 1; - } - return 0; -} - -/* - * Set resource - */ -static acpi_status pnpacpi_count_resources(struct acpi_resource *res, - void *data) -{ - int *res_cnt = data; - - if (pnpacpi_supported_resource(res)) - (*res_cnt)++; - return AE_OK; -} - -static acpi_status pnpacpi_type_resources(struct acpi_resource *res, void *data) -{ - struct acpi_resource **resource = data; - - if (pnpacpi_supported_resource(res)) { - (*resource)->type = res->type; - (*resource)->length = sizeof(struct acpi_resource); - if (res->type == ACPI_RESOURCE_TYPE_IRQ) - (*resource)->data.irq.descriptor_length = - res->data.irq.descriptor_length; - (*resource)++; - } - - return AE_OK; -} - -int pnpacpi_build_resource_template(struct pnp_dev *dev, - struct acpi_buffer *buffer) -{ - struct acpi_device *acpi_dev = dev->data; - acpi_handle handle = acpi_dev->handle; - struct acpi_resource *resource; - int res_cnt = 0; - acpi_status status; - - status = acpi_walk_resources(handle, METHOD_NAME__CRS, - pnpacpi_count_resources, &res_cnt); - if (ACPI_FAILURE(status)) { - dev_err(&dev->dev, "can't evaluate _CRS: %d\n", status); - return -EINVAL; - } - if (!res_cnt) - return -EINVAL; - buffer->length = sizeof(struct acpi_resource) * (res_cnt + 1) + 1; - buffer->pointer = kzalloc(buffer->length - 1, GFP_KERNEL); - if (!buffer->pointer) - return -ENOMEM; - - resource = (struct acpi_resource *)buffer->pointer; - status = acpi_walk_resources(handle, METHOD_NAME__CRS, - pnpacpi_type_resources, &resource); - if (ACPI_FAILURE(status)) { - kfree(buffer->pointer); - dev_err(&dev->dev, "can't evaluate _CRS: %d\n", status); - return -EINVAL; - } - /* resource will pointer the end resource now */ - resource->type = ACPI_RESOURCE_TYPE_END_TAG; - - return 0; -} - static void pnpacpi_encode_irq(struct pnp_dev *dev, struct acpi_resource *resource, struct resource *p)