From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1946941AbcHRK41 (ORCPT ); Thu, 18 Aug 2016 06:56:27 -0400 Received: from eu-smtp-delivery-143.mimecast.com ([207.82.80.143]:56616 "EHLO eu-smtp-delivery-143.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751505AbcHRK4X (ORCPT ); Thu, 18 Aug 2016 06:56:23 -0400 Date: Thu, 18 Aug 2016 18:55:50 +0800 From: Dennis Chen To: Tomasz Nowicki CC: , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH V8 1/8] ACPI: I/O Remapping Table (IORT) initial support Message-ID: <20160818105549.GB20404@arm.com> References: <1470909998-16710-1-git-send-email-tn@semihalf.com> <1470909998-16710-2-git-send-email-tn@semihalf.com> MIME-Version: 1.0 In-Reply-To: <1470909998-16710-2-git-send-email-tn@semihalf.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:217.140.96.140;IPV:CAL;SCL:-1;CTRY:GB;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(7916002)(2980300002)(448002)(189002)(24454002)(199003)(8936002)(26826002)(50466002)(8676002)(50986999)(626004)(31430400001)(23726003)(33656002)(110136002)(1076002)(76176999)(7416002)(54356999)(7846002)(189998001)(7696003)(46406003)(86362001)(2950100001)(77096005)(47776003)(305945005)(15975445007)(92566002)(87936001)(11100500001)(4326007)(83506001)(246002)(2906002)(104016004)(586003)(106466001)(97756001)(19580395003)(4001350100001)(19580405001)(356003)(36756003)(85326001)(18370500001)(2004002);DIR:OUT;SFP:1101;SCL:1;SRVR:HE1PR0801MB1801;H:nebula.arm.com;FPR:;SPF:PermError;PTR:fw-tnat.cambridge.arm.com;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;AM1FFO11FD026;1:XakbrUblMx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microsoft-Exchange-Diagnostics: 1;HE1PR0801MB1801;31:FkFGIH66+FoM38IXRnRuoFATXCJN2/LR4wlYOQ6OXC+uw/czADm7PHfprlNsVAfchD7gnL/wiq76YP2y8XaD7n2E2ol7nh0seyw7cjeDmMUmuGUsJuYt78NAyuorFLppqPOcEXHxelkDuNO0A804DS7JCTYCf5QDR77nmTDmBdJWv3zu03cN7g37WUwe05vRh3NZaqmhw0C/dy4a18e0c3kUMHuomv8sq7XAWqawlIQ=;20:1dRsUbG1jXXrCSdhHRhJGdSnS9Qu6P2OsRf6FuHUyESMtZo1P6UQakB4I3439GTKhAYAsPt+OGvUTWLoSlhrWeVvHP6UtkpLwRjI86/y6SHfKyosTMAo2WH1//is7W/EMngk64mzyGY3irfU5v8xHNnUF0x8GNzcxIX+m4CRU5WFXhDb1nPP7IqvCMBu3v4NtJaBfyrV4ZmJInxaFosC/PMWv22k+XWz0E88dYvCgiQAjGx9DFIFa2dHaUhcruLN NoDisclaimer: True X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(9452136761055); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(13020025)(13023025)(13024025)(13013025)(8121501046)(5005006)(10201501046)(3002001)(6055026);SRVR:HE1PR0801MB1801;BCL:0;PCL:0;RULEID:;SRVR:HE1PR0801MB1801; X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB1801;4:R7+L+mtLXewJ0NWlf5eSTjh3nM6fiYnVBpkL8bG1JGPuXVY+CYKpZpaVdP+J9SxSHd3Iqc0pRuEF8RQGZ06CFUZURFsWqxLuGlNbXIa0UJ6y+pZox0boaLZ1C5HoS25l5E9wieMZtQix69OxBr+UQxhB2sxHHucODljSZ5K5Vjt72iRE1gi6xYWfOBuXLitl9AHkB8ASyvRcL01MLxNoQgL8pmM5Dw6WkhYx1Pi5VI1lhxWFoMkCxLwnYA6OIjyQjE80mWgkNFwrWC3dqBNuUh1nwk5oyyKXus+9r5XvLj9EB1GVbDCFGorCUw/xbd0X2uhK52OYRroWmxNOPJcewqk8cEEQYnC2Ju2HWYvIlDDjYNZOkzxlny0ZS4w/ckz8mezVj9HPZW9L03grYGM/e6nrevIxWsOoYSC3ap9B062D7ZcGiPwF3XkDdW68lgE5wdOnlIfILlJRXWO+mnm4J1bLaptKGFY8GtvnZhB2KTMWZjhgVHCcKLyda68TJa4tBKBkQuiOVlsbhAmDRdE2gdwYjQGUVsiVfAzytS3s49Fc88F3oIMhy7V/eE6Mtcvs X-Forefront-PRVS: 0038DE95A2 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;HE1PR0801MB1801;23:j/Pbjq6211KxQY52Z9XZkoJlmMSEFaWsLt8TnRT?= =?us-ascii?Q?ixbL3UYkphri6qQKy06RDC51n6Orwx9ogyrfMmVAKl27X62zq6tGhA8PzXtl?= =?us-ascii?Q?KD1VREZ0Z8rIfGxhazEBg2J/tC1grnaWP1JS/fQK1SJIFfd/uwPkEw/zn4+q?= =?us-ascii?Q?jDL4j5GRFEb4+G41i9vxyFMno9Z44tPotttX7Qtz9uYkj56wD+0Jwny6xYHT?= =?us-ascii?Q?OTlr94VNmji6/d5v7lf49tYzNUIyAARrIVlFotMThifQ+Crw2hSsrxxu12pR?= =?us-ascii?Q?y93wkibyDv0w7Eu1fBxJDsz9OnwUiDk9LhF8OcrOsKd6plZybfsvDL8luPnU?= =?us-ascii?Q?2mQl1nDiNW46z/WFfYaEoJZrdcV9vnG2gdTremFSCNnC3V4hiumyQtuiOjDp?= =?us-ascii?Q?F5p+HR6PuWhd2aatq5kCSJljWPsHMfpuF9XiDNHXluLjnTbqlgveDHD3SWS7?= =?us-ascii?Q?UELHfjd6ILPoJrqWnsQuHkn8TiD8zUHSOguoyHpevWrzLN7ARs5A74eJhXm1?= =?us-ascii?Q?y7tPwqOczp2Vtgq7/MfZfGttVLURNbjHWesv8DgTyAOs1WfO/rlfHbBCPIAI?= =?us-ascii?Q?/Vpsqro1fsob3WyvsQa6/atnoXQMH6F/drmWaMFSs0ktVS7SvMEvW01Ewrn8?= =?us-ascii?Q?rcasffxWN1ewU/Gm5+8Cw0rNz+21d8FogVJfsMfK6oNkYol5xpF0jzPqINOQ?= =?us-ascii?Q?+iKUsermjAoGhSdo3oC88vaFXRIiDlAEh/q/dovbq6nc0N26mUpgxZHI9Ybr?= =?us-ascii?Q?Bo0TTWUZVgUovQWdvCU6VsLqfkgdFdSFDNgO5K+cu5uT2lGNFAd0LtiOyBsR?= =?us-ascii?Q?/XINa0C7ABCLjutlR3vWI7ylf7YqPrAcFMkmZs6PR5Tc96BCw+9L0qTAR7Vk?= =?us-ascii?Q?HeKScfn/mmcWfIPLzknF/HPCTswh+QwQEyIJiH+oNx17uzFGguHUMjweby6q?= =?us-ascii?Q?BIEj9WJL6wTPrZWyep4og/uuPArCShs2O1POCnF6ABBGqPNxkr73gOO1GOxX?= =?us-ascii?Q?O5dIS16/2RXdJY4Sr2WTz2YthO+ptd3aNYeT2bstpLyoJ83K+uHePJqTMHi4?= =?us-ascii?Q?fCdLTliT/V2PDyoUUzf+LWL6wGRgcaEE4/MTtRWzE2KGILvd5VZoH6OFPjYG?= =?us-ascii?Q?Ac/3zR52MgL/55UFrvEm8HwMVguHarX/mPuyyyowj7JC42mFNFpofWWugY/p?= =?us-ascii?Q?+/gbupLXqypU+J5DyIIyntxqmEk9dyhAcTGUxJoRSZLvGGSH2hkc4ZeFZAw?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB1801;6:+1wxiB/cesHjonr934rNo89WqKPX/bneJdn00NkTzjD1A4PTi29jVZLHN/pBunblFfc8uB1Pdv7sHoOVa63Fn/SiC/ML1MtmCAbWQbYBJGnNxjxXs5bI51j8pn05aE8Cd4xkjkE3XyV00Yz7wYlG2dBPWGIut75wMFpvfcx2bWoaLZfdZmdWPF9f4LrXobs2j3IPtWC4erDf5X4kBoiz4PZKR/vaMbzsEvBXuMUfZV+TeuTGFXhqVFwuc09eksfquEvGEO6grROIkKPQytxRGtD5k+mx5zQb8/HDMnV6hcnRUn0xTXJio2sRCBhjCKGmLMM82zUwatteeRLALdQvvw==;5:WnmP866QaOlmFk9JGkRWnuIac7FGfzMpOzYcyQuEKJ1w7aGeQ+2a3huhebJefNz/i53ZwKhckQcDESkZd2kkNL+rDDd8AShFlFIGrn3JTGwbP7i3/I4RQBvCJd4Y68gY2vKo3mu4T2f2bZAxPHjqtw==;24:krGTPYBa3fRUk5xNtFtZ0JQoNuc4M4n/5MrIDsYDC9vZXtLbNkq8ZPqPLdebrY4dTHBbg5+22PCboQBKNj1OTKPVM7Gd86UAXL2TDMTrQQo=;7:+Uy7Ye8IV5A7nqbuCC/9WtTY2fv/6+oOffIzehOKDkI/xMwZCh2zoUJsrG9ZOiw1RLfen0x+zZOHTRVjvebPGtJYinqYtSvtMTX33aAv+s6Iillc6SqWlZNHQ4OOVIJAyGyURrsuI6VMIXZ4Rb3ddxcuFTXPINyjW1EjQxc+lBa3kGiQh1IeKVHAhNIjZyeT7UNqUync2Az09VeHVUXvwruVbrls8ZVefdgxj9RZZqWz+FCA4/HQon8giqJZnDtD SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB1801;20:2BmiIojhpWRVNnrhlksyn3kW5FIrtzLiXUDjlGso0uBEbI+zUkztcht10p9yo8G9IxZcfmBgjOA1ElfKd1IiKgSBmC56AIkc5Ygdh8sqa23s+ihCFPrasVcl0Duik4okjMQSa2O6YAxoDTSTqiAhNXnKUr1U8F8Aw1+p0vU4Smk= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Aug 2016 10:56:01.7239 (UTC) X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[217.140.96.140];Helo=[nebula.arm.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB1801 X-MC-Unique: YUtvhLPbPcqpQFodUnruLA-1 Content-Type: text/plain; charset=WINDOWS-1252 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id u7IAueOw022509 Hi Tomasz, On Thu, Aug 11, 2016 at 12:06:31PM +0200, Tomasz Nowicki wrote: > IORT shows representation of IO topology for ARM based systems. > It describes how various components are connected together on > parent-child basis e.g. PCI RC -> SMMU -> ITS. Also see IORT spec. > http://infocenter.arm.com/help/topic/com.arm.doc.den0049b/DEN0049B_IO_Remapping_Table.pdf > > Initial support allows to detect IORT table presence and save its > root pointer obtained through acpi_get_table(). The pointer validity > depends on acpi_gbl_permanent_mmap because if acpi_gbl_permanent_mmap > is not set while using IORT nodes we would dereference unmapped pointers. > > For the aforementioned reason call iort_table_detect() from acpi_init() > which guarantees acpi_gbl_permanent_mmap to be set at that point. > > Add generic helpers which are helpful for scanning and retrieving > information from IORT table content. List of the most important helpers: > - iort_find_dev_node() finds IORT node for a given device > - iort_node_map_rid() maps device RID and returns IORT node which provides > final translation > > IORT support is placed under drivers/acpi/arm64/ new directory due to its > ARM64 specific nature. The code there is considered only for ARM64. > The long term plan is to keep all ARM64 specific tables support > in this place e.g. GTDT table. > > Signed-off-by: Tomasz Nowicki > Reviewed-by: Hanjun Guo > --- > drivers/acpi/Kconfig | 5 + > drivers/acpi/Makefile | 2 + > drivers/acpi/arm64/Kconfig | 6 ++ > drivers/acpi/arm64/Makefile | 1 + > drivers/acpi/arm64/iort.c | 218 ++++++++++++++++++++++++++++++++++++++++++++ > drivers/acpi/bus.c | 2 + > include/linux/iort.h | 30 ++++++ > 7 files changed, 264 insertions(+) > create mode 100644 drivers/acpi/arm64/Kconfig > create mode 100644 drivers/acpi/arm64/Makefile > create mode 100644 drivers/acpi/arm64/iort.c > create mode 100644 include/linux/iort.h > > diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig > index 445ce28..6cef2d1 100644 > --- a/drivers/acpi/Kconfig > +++ b/drivers/acpi/Kconfig > @@ -521,4 +521,9 @@ config ACPI_CONFIGFS > userspace. The configurable ACPI groups will be visible under > /config/acpi, assuming configfs is mounted under /config. > > +if ARM64 > +source "drivers/acpi/arm64/Kconfig" > + > +endif > + > endif # ACPI > diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile > index 5ae9d85..e5ada78 100644 > --- a/drivers/acpi/Makefile > +++ b/drivers/acpi/Makefile > @@ -105,3 +105,5 @@ obj-$(CONFIG_ACPI_CONFIGFS) += acpi_configfs.o > > video-objs += acpi_video.o video_detect.o > obj-y += dptf/ > + > +obj-$(CONFIG_ARM64) += arm64/ > diff --git a/drivers/acpi/arm64/Kconfig b/drivers/acpi/arm64/Kconfig > new file mode 100644 > index 0000000..fc818dc > --- /dev/null > +++ b/drivers/acpi/arm64/Kconfig > @@ -0,0 +1,6 @@ > +# > +# ACPI Configuration for ARM64 > +# > + > +config IORT_TABLE > + bool > diff --git a/drivers/acpi/arm64/Makefile b/drivers/acpi/arm64/Makefile > new file mode 100644 > index 0000000..d01be6f > --- /dev/null > +++ b/drivers/acpi/arm64/Makefile > @@ -0,0 +1 @@ > +obj-$(CONFIG_IORT_TABLE) += iort.o > diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c > new file mode 100644 > index 0000000..f89056e > --- /dev/null > +++ b/drivers/acpi/arm64/iort.c > @@ -0,0 +1,218 @@ > +/* > + * Copyright (C) 2016, Semihalf > + * Author: Tomasz Nowicki > + * > + * This program is free software; you can redistribute it and/or modify it > + * under the terms and conditions of the GNU General Public License, > + * version 2, as published by the Free Software Foundation. > + * > + * This program is distributed in the hope it will be useful, but WITHOUT > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for > + * more details. > + * > + * This file implements early detection/parsing of I/O mapping > + * reported to OS through firmware via I/O Remapping Table (IORT) > + * IORT document number: ARM DEN 0049A > + */ > + > +#define pr_fmt(fmt) "ACPI: IORT: " fmt > + > +#include > +#include > +#include > + > +typedef acpi_status (*iort_find_node_callback) > + (struct acpi_iort_node *node, void *context); > + > +/* Root pointer to the mapped IORT table */ > +static struct acpi_table_header *iort_table; > + > +static struct acpi_iort_node * > +iort_scan_node(enum acpi_iort_node_type type, > + iort_find_node_callback callback, void *context) > +{ > + struct acpi_iort_node *iort_node, *iort_end; > + struct acpi_table_iort *iort; > + int i; > + > + /* Get the first IORT node */ > + iort = (struct acpi_table_iort *)iort_table; > Here, the same as I comments on Lorenzo's patch. If IORT is missed in the firmware, then iort_table will be NULL, result in kernel panic in the codes followed. Thanks, Dennis > + iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort, > + iort->node_offset); > + iort_end = ACPI_ADD_PTR(struct acpi_iort_node, iort_table, > + iort_table->length); > + > + for (i = 0; i < iort->node_count; i++) { > + if (WARN_TAINT(iort_node >= iort_end, TAINT_FIRMWARE_WORKAROUND, > + "IORT node pointer overflows, bad table!\n")) > + return NULL; > + > + if (iort_node->type == type) { > + if (ACPI_SUCCESS(callback(iort_node, context))) > + return iort_node; > + } > + > + iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort_node, > + iort_node->length); > + } > + > + return NULL; > +} > + > +static acpi_status > +iort_match_node_callback(struct acpi_iort_node *node, void *context) > +{ > + struct device *dev = context; > + > + switch (node->type) { > + case ACPI_IORT_NODE_NAMED_COMPONENT: { > + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; > + struct acpi_device *adev = to_acpi_device_node(dev->fwnode); > + struct acpi_iort_named_component *ncomp; > + > + if (!adev) > + break; > + > + ncomp = (struct acpi_iort_named_component *)node->node_data; > + > + if (ACPI_FAILURE(acpi_get_name(adev->handle, > + ACPI_FULL_PATHNAME, &buffer))) { > + dev_warn(dev, "Can't get device full path name\n"); > + } else { > + int match; > + > + match = !strcmp(ncomp->device_name, buffer.pointer); > + acpi_os_free(buffer.pointer); > + > + if (match) > + return AE_OK; > + } > + > + break; > + } > + case ACPI_IORT_NODE_PCI_ROOT_COMPLEX: { > + struct acpi_iort_root_complex *pci_rc; > + struct pci_bus *bus; > + > + bus = to_pci_bus(dev); > + pci_rc = (struct acpi_iort_root_complex *)node->node_data; > + > + /* > + * It is assumed that PCI segment numbers maps one-to-one > + * with root complexes. Each segment number can represent only > + * one root complex. > + */ > + if (pci_rc->pci_segment_number == pci_domain_nr(bus)) > + return AE_OK; > + > + break; > + } > + } > + > + return AE_NOT_FOUND; > +} > + > +static int > +iort_id_map(struct acpi_iort_id_mapping *map, u8 type, u32 rid_in, u32 *rid_out) > +{ > + /* Single mapping does not care for input id */ > + if (map->flags & ACPI_IORT_ID_SINGLE_MAPPING) { > + if (type == ACPI_IORT_NODE_NAMED_COMPONENT || > + type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) { > + *rid_out = map->output_base; > + return 0; > + } > + > + pr_warn(FW_BUG "[map %p] SINGLE MAPPING flag not allowed for node type %d, skipping ID map\n", > + map, type); > + return -ENXIO; > + } > + > + if (rid_in < map->input_base || > + (rid_in >= map->input_base + map->id_count)) > + return -ENXIO; > + > + *rid_out = map->output_base + (rid_in - map->input_base); > + return 0; > +} > + > +static struct acpi_iort_node * > +iort_node_map_rid(struct acpi_iort_node *node, u32 rid_in, > + u32 *rid_out, u8 type) > +{ > + u32 rid = rid_in; > + > + /* Parse the ID mapping tree to find specified node type */ > + while (node) { > + struct acpi_iort_id_mapping *map; > + int i; > + > + if (node->type == type) { > + if (rid_out) > + *rid_out = rid; > + return node; > + } > + > + if (!node->mapping_offset || !node->mapping_count) > + goto fail_map; > + > + map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, node, > + node->mapping_offset); > + > + /* Firmware bug! */ > + if (!map->output_reference) { > + pr_err(FW_BUG "[node %p type %d] ID map has NULL parent reference\n", > + node, node->type); > + goto fail_map; > + } > + > + /* Do the RID translation */ > + for (i = 0; i < node->mapping_count; i++, map++) { > + if (!iort_id_map(map, node->type, rid, &rid)) > + break; > + } > + > + if (i == node->mapping_count) > + goto fail_map; > + > + node = ACPI_ADD_PTR(struct acpi_iort_node, iort_table, > + map->output_reference); > + } > + > +fail_map: > + /* Map input RID to output RID unchanged on mapping failure*/ > + if (rid_out) > + *rid_out = rid_in; > + > + return NULL; > +} > + > +static struct acpi_iort_node * > +iort_find_dev_node(struct device *dev) > +{ > + struct pci_bus *pbus; > + > + if (!dev_is_pci(dev)) > + return iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT, > + iort_match_node_callback, dev); > + > + /* Find a PCI root bus */ > + pbus = to_pci_dev(dev)->bus; > + while (!pci_is_root_bus(pbus)) > + pbus = pbus->parent; > + > + return iort_scan_node(ACPI_IORT_NODE_PCI_ROOT_COMPLEX, > + iort_match_node_callback, &pbus->dev); > +} > + > +void __init iort_table_detect(void) > +{ > + acpi_status status; > + > + status = acpi_get_table(ACPI_SIG_IORT, 0, &iort_table); > + if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { > + const char *msg = acpi_format_exception(status); > + pr_err("Failed to get table, %s\n", msg); > + } > +} > diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c > index 85b7d07..55a84da 100644 > --- a/drivers/acpi/bus.c > +++ b/drivers/acpi/bus.c > @@ -36,6 +36,7 @@ > #ifdef CONFIG_X86 > #include > #endif > +#include > #include > #include > #include > @@ -1186,6 +1187,7 @@ static int __init acpi_init(void) > } > > pci_mmcfg_late_init(); > + iort_table_detect(); > acpi_scan_init(); > acpi_ec_init(); > acpi_debugfs_init(); > diff --git a/include/linux/iort.h b/include/linux/iort.h > new file mode 100644 > index 0000000..cde6809 > --- /dev/null > +++ b/include/linux/iort.h > @@ -0,0 +1,30 @@ > +/* > + * Copyright (C) 2016, Semihalf > + * Author: Tomasz Nowicki > + * > + * This program is free software; you can redistribute it and/or modify it > + * under the terms and conditions of the GNU General Public License, > + * version 2, as published by the Free Software Foundation. > + * > + * This program is distributed in the hope it will be useful, but WITHOUT > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for > + * more details. > + * > + * You should have received a copy of the GNU General Public License along with > + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple > + * Place - Suite 330, Boston, MA 02111-1307 USA. > + */ > + > +#ifndef __IORT_H__ > +#define __IORT_H__ > + > +#include > + > +#ifdef CONFIG_IORT_TABLE > +void iort_table_detect(void); > +#else > +static inline void iort_table_detect(void) { } > +#endif > + > +#endif /* __IORT_H__ */ > -- > 1.9.1 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-pci" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >