From patchwork Tue Sep 9 21:41:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salter X-Patchwork-Id: 37154 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B2B1020491 for ; Tue, 9 Sep 2014 21:41:55 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id x3sf50852087qcv.6 for ; Tue, 09 Sep 2014 14:41:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:subject:from:to:cc:date :in-reply-to:references:organization:mime-version:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe :content-type:content-transfer-encoding; bh=VYLjrE4Leghh+PrL62/v6V3t0gXB/TP8HUjvnkI8ap4=; b=F4VYSuNuNmwtnh8by/wYkiSWMiUmh0cFyhYrV/29Zs0DKuIN41ucHv39qY+yoPnC15 yFd0qqq8a7B0XYO71W1hev/wfKeF0tmT2GDflXlpKl+a5pJORDkWL8Wun4P/6XVnRULd n3dnNmqq/7FZ3uOps3tHfa8yl31H34xd9e27OckqVok3EvnKgjkUOyBfyuj4CHF8HWWT +0mJHrnYviqfLxHEimhBLRe+fsXwyhN797AszmXqQYyIT7WMQP7W55JUnNPmreMpmgMJ jNlb02I7NdH+7o9nkh6fAnLs3kHg+cgK6hv5feh1HF1N4Wj1tt0FPlQuJ44d6DW7bzgF 07jw== X-Gm-Message-State: ALoCoQlEkTCEvu5KELG0xNBTLqIEWWhOtQu0Z5x1lh2MyQAPMJ9ils0AbJN3LMT3WTJ2ahUdHMle X-Received: by 10.52.116.241 with SMTP id jz17mr9379274vdb.9.1410298915550; Tue, 09 Sep 2014 14:41:55 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.46.100 with SMTP id j91ls2341677qga.44.gmail; Tue, 09 Sep 2014 14:41:55 -0700 (PDT) X-Received: by 10.52.28.198 with SMTP id d6mr2587150vdh.68.1410298915474; Tue, 09 Sep 2014 14:41:55 -0700 (PDT) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id g5si5686654vcz.7.2014.09.09.14.41.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 09 Sep 2014 14:41:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) client-ip=209.85.220.171; Received: by mail-vc0-f171.google.com with SMTP id id10so17822407vcb.16 for ; Tue, 09 Sep 2014 14:41:55 -0700 (PDT) X-Received: by 10.52.128.104 with SMTP id nn8mr6322327vdb.50.1410298915390; Tue, 09 Sep 2014 14:41:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp346528vcb; Tue, 9 Sep 2014 14:41:54 -0700 (PDT) X-Received: by 10.68.131.134 with SMTP id om6mr32933615pbb.41.1410298914322; Tue, 09 Sep 2014 14:41:54 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id hb5si24937384pbb.186.2014.09.09.14.41.53 for ; Tue, 09 Sep 2014 14:41:54 -0700 (PDT) Received-SPF: none (google.com: linux-acpi-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751943AbaIIVlw (ORCPT + 7 others); Tue, 9 Sep 2014 17:41:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1131 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751896AbaIIVlw (ORCPT ); Tue, 9 Sep 2014 17:41:52 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s89LflG0021096 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 9 Sep 2014 17:41:47 -0400 Received: from [10.3.113.116] (ovpn-113-116.phx2.redhat.com [10.3.113.116]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s89Lfk4t017387; Tue, 9 Sep 2014 17:41:47 -0400 Message-ID: <1410298906.27715.62.camel@deneb.redhat.com> Subject: Re: [PATCH] acpi: add utility to test for device dma coherency From: Mark Salter To: "Rafael J. Wysocki" Cc: Lv Zheng , linux-acpi@vger.kernel.org Date: Tue, 09 Sep 2014 17:41:46 -0400 In-Reply-To: <2333063.oAgzS6NIuV@vostro.rjw.lan> References: <1410296278-1244-1-git-send-email-msalter@redhat.com> <2333063.oAgzS6NIuV@vostro.rjw.lan> Organization: Red Hat, Inc Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: linux-acpi-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: msalter@redhat.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On Tue, 2014-09-09 at 23:49 +0200, Rafael J. Wysocki wrote: > On Tuesday, September 09, 2014 04:57:58 PM Mark Salter wrote: > > ACPI 5.1 adds a _CCA object to indicate memory coherency > > of a bus master device. It is an integer with zero meaning > > non-coherent and one meaning coherent. This attribute may > > be inherited from a parent device. It may also be missing > > entirely, in which case, an architecture-specific default > > is assumed. > > > > This patch adds a utility function to parse a device handle > > (and its parents) for a _CCA object and return the coherency > > attribute if found. > > > > Signed-off-by: Mark Salter > > --- > > drivers/acpi/utils.c | 26 ++++++++++++++++++++++++++ > > include/acpi/acpi_bus.h | 2 ++ > > 2 files changed, 28 insertions(+) > > > > diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c > > index 07c8c5a..aec9656 100644 > > --- a/drivers/acpi/utils.c > > +++ b/drivers/acpi/utils.c > > @@ -698,3 +698,29 @@ bool acpi_check_dsm(acpi_handle handle, const u8 *uuid, int rev, u64 funcs) > > return false; > > } > > EXPORT_SYMBOL(acpi_check_dsm); > > + > > +/** > > + * acpi_check_coherency - check for memory coherency of a device > > + * @handle: ACPI device handle > > + * @val: Pointer to returned value > > + * > > + * Search a device and its parents for a _CCA method and return > > + * its value. > > + */ > > +acpi_status acpi_check_coherency(acpi_handle handle, int *val) > > +{ > > + unsigned long long data; > > + acpi_status status; > > + > > + do { > > + status = acpi_evaluate_integer(handle, "_CCA", NULL, &data); > > + if (!ACPI_FAILURE(status)) { > > We have an ACPI_SUCCESS() macro for that. ah, okay > > > + *val = data; > > + break; > > + } > > + status = acpi_get_parent(handle, &handle); > > + } while (!ACPI_FAILURE(status)); > > + > > And here. > > Anyway, how do you think this routine will be used? Do you have any > particular use cases in mind? > An arm64 kernel defaults to non-coherent dma ops. There is a platform and amba bus notifier in arm64/mm/dma-mapping.c which looks for a device-tree dma-coherent property. If found, the device is switched to using coherent dma ops. I'm thinking of doing something similar for ACPI in that same bus notifier: --- 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/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 4164c5a..f26dd78 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -319,6 +320,21 @@ static int dma_bus_notifier(struct notifier_block *nb, if (of_property_read_bool(dev->of_node, "dma-coherent")) set_dma_ops(dev, &coherent_swiotlb_dma_ops); +#ifdef CONFIG_ACPI + if (ACPI_HANDLE(dev)) { + acpi_status status; + int coherent; + + /* + * Kernel defaults to noncoherent ops but ACPI 5.1 spec says arm64 + * defaults to coherent. Set coherent ops if _CCA not found or _CCA + * found and non-zero. + */ + status = acpi_check_coherency(ACPI_HANDLE(dev), &coherent); + if (ACPI_FAILURE(status) || coherent) + set_dma_ops(dev, &coherent_swiotlb_dma_ops); + } +#endif return NOTIFY_OK; }