From patchwork Tue Jan 2 09:27:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Jaggi X-Patchwork-Id: 123095 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8754938qgn; Tue, 2 Jan 2018 01:31:00 -0800 (PST) X-Google-Smtp-Source: ACJfBos4jXRscKYlRJazagi/zFD8RcoXLbGX/5z2MxVo1+CdF/e/22Ju+hahTJKC02Wyjpbs9IBh X-Received: by 10.107.89.5 with SMTP id n5mr14760355iob.139.1514885460595; Tue, 02 Jan 2018 01:31:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514885460; cv=none; d=google.com; s=arc-20160816; b=D8s3Jl8S1Y2t0NGujGkbs4hmKNCbSG6fQYCETFi3MOCRVaIwelKmGiNCSlOn90luU0 qbdINI9XVm8OJvLl1hRBGXyJq9+4lCdw3qACxIehbkYZSFhLC6UgyURtnGzE8TOwGHeR /p2Wvh5f2sXm7TyZFoOoBMgcpFjp4yOemooZajHLaMlb7wLr5hYF6Gozp1jyBljcJ4UN jffjagoOlEKD4mOjNFVgxmY4DaeWgt7gKlwhwD1X54fv7J/CukcqXIvUn0JHMC/twYmv 0LEaFKU+SbfNwJ4zsNcZbh1R8cqQTU0gm0V8qyIhBgMyNI9SclPB/jxiRx39LJTCsjsO McMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=I+rzasS98ZrdYwBSNLjJ4tSDtxYjh6bPCsVN7jJhu2c=; b=dhDtd1JX6D/UHJKTD2vnL2hDIzX8VLnM9cNb6icNWeV0cqcnaaKsjLv0ek0LMJpFAE 4wERwugNzktJhqE5vwN4Cq4CObSa1k4yhk9HOJk8W8Fo9C9AFDeV2/P+l+e411rmSLOm Y2FnyPcDHRyuVttqEk/+95IxR/3Iu8BiCKYUnpKbI1wkToGvxTG7ylJk6WyzZTUhSgxU R+1kKbAQnsCbOLmdxMCI/XazV/LXwxKGvb06fuq5Mq6fAaL2jGgqiYJBQeccl3tfAFcX wvDbmLHxyguxKVXsDMFO0J9p/iXPDVdc7CWzz5CHFssvnbQZnbnexhg3GxBJOvrBoXaX sdEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fHbd3hY4; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id j20si25122963ioi.205.2018.01.02.01.31.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:31:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fHbd3hY4; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIs8-0002Pl-5X; Tue, 02 Jan 2018 09:28:36 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIs6-0002Pc-M1 for xen-devel@lists.xenproject.org; Tue, 02 Jan 2018 09:28:34 +0000 X-Inumbo-ID: 24dbe241-ef9f-11e7-b4a6-bc764e045a96 Received: from mail-pf0-x242.google.com (unknown [2607:f8b0:400e:c00::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 24dbe241-ef9f-11e7-b4a6-bc764e045a96; Tue, 02 Jan 2018 10:27:25 +0100 (CET) Received: by mail-pf0-x242.google.com with SMTP id l24so25461210pfj.6 for ; Tue, 02 Jan 2018 01:28:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Q07Spk87AY4GPwwwG6xSzFNuSQdLW6HF8PmtdOk36aQ=; b=fHbd3hY4yaFS5RrU5jZXLeKVDKEyazaX9ch96TfMlLPwD/QYSRC+Cp0tJCuli7qn+r ni9WS5FuLvXabpGXq3heVfWy8EXSC2Vu/12gBh4NGns+t1OTomI9FOhutUtyqBbuFkVB +Ooqr40f2z6/yMXEE8b2t+1BxEoa52CUKk/4k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Q07Spk87AY4GPwwwG6xSzFNuSQdLW6HF8PmtdOk36aQ=; b=X57PSl0dfeHVvbPVSlnluHdCD0EvU9o04WcBJA5oxvA+NyMRa9MKsVSoHvePw9ZEBi 1ZY0YjrNnVbJIzlQQyf/Lw5bSJ+I7MfgikFuyarCQ4+lPg6Ay/CkPaDaq0Kx6O6OutjL TCmE5sKS2777OqXkvgO+cD7w6KmWpjm9hIKCJ4SIQaI5/6k/KrVl8qAAsUkZEC18RHDC VZm8Fqp07UGMp8nME5gqO2wueIOOk4mimIrPBMp9T/oppkJSsQ9QFkT/ZqdPqlyzw5oQ fzazBnvcsOqtEDk9I5BBZYN9JeKvDXFR8FdDFmFxxrAYcXDRCCj5xF6E1NlEmS6YI87r HXzQ== X-Gm-Message-State: AKGB3mK1sGyK0wzgP9joRRRjmrYMdm4YthnDZnUsxmo84twJ3nvSLZ/w lVtPx11p18GCY7J8WtPbDJYH+Zk2VNs= X-Received: by 10.99.138.68 with SMTP id y65mr38583183pgd.160.1514885310905; Tue, 02 Jan 2018 01:28:30 -0800 (PST) Received: from thunder-dev-box.domain.name ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id e8sm22065207pgs.44.2018.01.02.01.28.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:28:30 -0800 (PST) From: manish.jaggi@linaro.org To: xen-devel@lists.xenproject.org, julien.grall@linaro.org, sameer.goel@linaro.org, andre.przywara@linaro.org Date: Tue, 2 Jan 2018 14:57:59 +0530 Message-Id: <20180102092809.1841-2-manish.jaggi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180102092809.1841-1-manish.jaggi@linaro.org> References: <20180102092809.1841-1-manish.jaggi@linaro.org> Cc: Manish Jaggi , manish.jaggi@cavium.com Subject: [Xen-devel] [RFC 01/11] acpi: arm: Public API for populating and query based on requesterid X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Manish Jaggi Public API to populate and query map between requester id and streamId/DeviceID. IORT is parsed one time (outside this patch) and two lists are created one for mapping between reuesterId and streamid and another between requesterID and deviceID. These lists eliminate the need to reparse IORT for querying streamid or deviceid using requesterid. Signed-off-by: Manish Jaggi --- xen/drivers/acpi/Makefile | 1 + xen/drivers/acpi/arm/Makefile | 1 + xen/drivers/acpi/arm/ridmap.c | 124 ++++++++++++++++++++++++++++++++++++++++++ xen/include/acpi/ridmap.h | 77 ++++++++++++++++++++++++++ 4 files changed, 203 insertions(+) diff --git a/xen/drivers/acpi/Makefile b/xen/drivers/acpi/Makefile index 444b11d583..80a074e007 100644 --- a/xen/drivers/acpi/Makefile +++ b/xen/drivers/acpi/Makefile @@ -1,6 +1,7 @@ subdir-y += tables subdir-y += utilities subdir-$(CONFIG_X86) += apei +subdir-$(CONFIG_ARM) += arm obj-bin-y += tables.init.o obj-$(CONFIG_NUMA) += numa.o diff --git a/xen/drivers/acpi/arm/Makefile b/xen/drivers/acpi/arm/Makefile new file mode 100644 index 0000000000..046fad5e3d --- /dev/null +++ b/xen/drivers/acpi/arm/Makefile @@ -0,0 +1 @@ +obj-y = ridmap.o diff --git a/xen/drivers/acpi/arm/ridmap.c b/xen/drivers/acpi/arm/ridmap.c new file mode 100644 index 0000000000..2c3a8876ea --- /dev/null +++ b/xen/drivers/acpi/arm/ridmap.c @@ -0,0 +1,124 @@ +/* + * xen/drivers/acpi/arm/ridmap.c + * + * Public API to populate and query map between requester id and + * streamId/DeviceID + * + * Manish Jaggi + * Copyright (c) 2018 Linaro. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that 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. + */ + +#include +#include +#include +#include +#include + +struct list_head rid_streamid_map_list; +struct list_head rid_deviceid_map_list; + +void init_ridmaps(void) +{ + INIT_LIST_HEAD(&rid_deviceid_map_list); + INIT_LIST_HEAD(&rid_streamid_map_list); +} + +int add_rid_streamid_map(struct acpi_iort_node *pcirc_node, + struct acpi_iort_node *smmu_node, + u32 input_base, u32 output_base, u32 id_count) +{ + struct rid_streamid_map *rid_map; + rid_map = xzalloc(struct rid_streamid_map); + + if (!rid_map) + return -ENOMEM; + + rid_map->idmap.input_base = input_base; + rid_map->idmap.output_base = output_base; + rid_map->idmap.id_count = id_count; + rid_map->pcirc_node = pcirc_node; + rid_map->smmu_node = smmu_node; + + list_add_tail(&rid_map->entry, &rid_streamid_map_list); + return 0; +} + +int add_rid_deviceid_map(struct acpi_iort_node *pcirc_node, + struct acpi_iort_node *its_node, + u32 input_base, u32 output_base, u32 id_count) +{ + struct rid_deviceid_map *rid_map; + rid_map = xzalloc(struct rid_deviceid_map); + + if (!rid_map) + return -ENOMEM; + + rid_map->idmap.input_base = input_base; + rid_map->idmap.output_base = output_base; + rid_map->idmap.id_count = id_count; + rid_map->pcirc_node = pcirc_node; + rid_map->its_node = its_node; + + list_add_tail(&rid_map->entry, &rid_deviceid_map_list); + return 0; +} + +void query_streamid(struct acpi_iort_node *pcirc_node, u16 rid, u32 *streamid, + struct acpi_iort_node **smmu_node) +{ + struct rid_streamid_map *rmap; + + list_for_each_entry(rmap, &rid_streamid_map_list, entry) + { + if (rmap->pcirc_node == pcirc_node) + { + if ( (rid >= rmap->idmap.input_base) && + (rid < rmap->idmap.input_base + rmap->idmap.id_count) ) + { + *streamid = rid - rmap->idmap.input_base + + rmap->idmap.output_base; + *smmu_node = rmap->smmu_node; + break; + } + } + } + +} + +void query_deviceid(struct acpi_iort_node *pcirc_node, u16 rid, u32 *deviceid) +{ + struct rid_deviceid_map *rmap; + + list_for_each_entry(rmap, &rid_deviceid_map_list, entry) + { + if (rmap->pcirc_node == pcirc_node) + { + if ( (rid >= rmap->idmap.input_base) && + (rid < rmap->idmap.input_base + rmap->idmap.id_count) ) + { + *deviceid = rid - rmap->idmap.input_base + + rmap->idmap.output_base; + break; + } + } + } +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/acpi/ridmap.h b/xen/include/acpi/ridmap.h new file mode 100644 index 0000000000..806f401d89 --- /dev/null +++ b/xen/include/acpi/ridmap.h @@ -0,0 +1,77 @@ +/* + * xen/include/acpi/ridmap.h + * + * Mapping structures to hold map between requester id and streamId/DeviceID + * after paring the IORT table. + * + * Manish Jaggi + * Copyright (c) 2018 Linaro. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that 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. + */ + +#ifndef RID_MAP_H +#define RID_MAP_H + +#include + +struct id_map_struct +{ + u16 input_base; + u32 output_base; + u16 id_count; +}; + +struct rid_streamid_map +{ + struct acpi_iort_node *pcirc_node; + struct id_map_struct idmap; + struct list_head entry; + struct acpi_iort_node *smmu_node; +}; + +struct rid_deviceid_map +{ + struct acpi_iort_node *pcirc_node; + struct acpi_iort_node *its_node; + struct id_map_struct idmap; + struct list_head entry; +}; + +extern struct list_head rid_streamid_map_list; +extern struct list_head rid_deviceid_map_list; + +int add_rid_streamid_map(struct acpi_iort_node *pcirc_node, + struct acpi_iort_node *smmu_node, + u32 input_base, u32 output_base, u32 id_count); + +int add_rid_deviceid_map(struct acpi_iort_node *pcirc_node, + struct acpi_iort_node *its_node, + u32 input_base, u32 output_base, u32 id_count); + +void query_streamid(struct acpi_iort_node *pcirc_node, u16 rid, u32 *streamid, + struct acpi_iort_node **smmu_node); + +void query_deviceid(struct acpi_iort_node *pcirc_node, + u16 rid, u32 *deviceid); + +void init_ridmaps(void); + +#endif + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ From patchwork Tue Jan 2 09:28:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Jaggi X-Patchwork-Id: 123099 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8755009qgn; Tue, 2 Jan 2018 01:31:05 -0800 (PST) X-Google-Smtp-Source: ACJfBouEBz4Yli00irMOClKp986VK1WwqX1tDTE2Qg/ZtcHMG80NnCu94C8bX1iQjF/X4ndWWd/0 X-Received: by 10.36.43.207 with SMTP id h198mr61814770ita.23.1514885465796; Tue, 02 Jan 2018 01:31:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514885465; cv=none; d=google.com; s=arc-20160816; b=kvFyMrE0akvwVi9mNJ3SVW7ThZeNbdIeaEtKj5FZSDoeNpU6yilDE+hiRzcb9nJh0B vUFMg17vXS1s+ArRtCeBTBs9iuR9yY0Te+Dp/rtwd7pcIQDWkFjtZTkSFwHN7UX//cNb RhZpMJWy13H7PUhJfGsNv8kW6k9ILL86CYraj6XkI+VTT+GXKIiuQwlKFAPyUOItDVW/ vuKnU/PEfeQSFvZex778JC1T4XXkktnVbWszEHprIE7krzOGfnpEfN7E07Mcftw8O9lv ZgVZ4/7W6fTMJ/8DC9MRl9Zv8nyWIZOiZ7i1hj7hXEn7HkpJesgftHtL5Y/aFy5Do8Y/ 7F7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=qwa8sYKw7NgwnBIVHEY7sc3CpDCkOkXw08WKkcxIt98=; b=P2vrNsCySq3uRO4W/L65LK1LfyxihmMEbqDDmeAaN3uVILZfcZAZ6gs1FwCJSPTZY1 fCUS55AFPvHviYZMUZoTwkg0W1SNlMXrz25xj7JMp7yRRHPAme/PW1yoai1w4uROFLO4 ko11GZx2Rgp6G20g/qHT6Xdm+zRIIcJA3JrmgE8mgW8Q8FWI4vxWn2P6bseFG5D8rnVb IW2RqfmNfTYG5RneXFg9/sEyXMIvOp52aWAd1d6NgTyQhsLaicheqnh4cktkBqhe6fvs stP1QdIQOSfSVztKGrT2ooxfHE6Z5f3yng7HsQ5YubZ83GTEUMOYBMG2MfL27fbGuI7J EkeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=GLilOdsA; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id p62si133097ioe.153.2018.01.02.01.31.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:31:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=GLilOdsA; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsA-0002Qs-Fi; Tue, 02 Jan 2018 09:28:38 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsA-0002QN-0e for xen-devel@lists.xenproject.org; Tue, 02 Jan 2018 09:28:38 +0000 X-Inumbo-ID: 270d1b16-ef9f-11e7-b4a6-bc764e045a96 Received: from mail-pl0-x242.google.com (unknown [2607:f8b0:400e:c01::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 270d1b16-ef9f-11e7-b4a6-bc764e045a96; Tue, 02 Jan 2018 10:27:29 +0100 (CET) Received: by mail-pl0-x242.google.com with SMTP id bi12so28336780plb.6 for ; Tue, 02 Jan 2018 01:28:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lf3xxboQn1wcqeeunjFpaeVaR/cB51zeMLtt9bdpb24=; b=GLilOdsAib/+mlxIKkXbG18Y6AOOFjgQyYsZykOOgRvdDUPlYFyksQ0itG1yma4iWU OWFd/ZQjHWcJLDHTPloUck3qivhJoSas1e1MRFoK0AQmTpPQzQvgNvod4ZxyvONn1zz7 CymJ+WtvVtARKe+PRxdr/JtGsasDXO3lM/5wo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lf3xxboQn1wcqeeunjFpaeVaR/cB51zeMLtt9bdpb24=; b=eXrtSoVeC/Tkw14MtAt/8H3kYtZL2+7KEHBRqui4GzDYUHoMAuXSM9D5hsoW/N58/z 31f5h7/ldGVuaX16bsvyqxxi+S4PUnZRGWMeGFtfEbjI38NsLy/GcAhm4aPh15i43WiC ZmHOySIi9QZ0lq8+b0qOp08rY7iRYKq5QvVRVdVHFe31gMauMQI4qyuEPsjPvXnGyFud WyiwFhxmAbivIbxGNUC3pni7iAz0CzhpAQDWBCN7wbbbcqaDFdI3BJbVeagRvcb6CiRZ g4vOty+ml82M6Lyp7bA9LxzK86ayXDWLEF52vNuOMpGNhbetvb1U62n2uDxwZfryvgMU qQgw== X-Gm-Message-State: AKGB3mLkIuhxAXU08ZWBf5tL71clnbXo0ZfOIEXVZeu2RUqwfUcEyn6D rXeoA/wbrUzhLZYkZot3XwMbvczn9ws= X-Received: by 10.84.171.193 with SMTP id l59mr43894231plb.163.1514885314710; Tue, 02 Jan 2018 01:28:34 -0800 (PST) Received: from thunder-dev-box.domain.name ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id e8sm22065207pgs.44.2018.01.02.01.28.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:28:34 -0800 (PST) From: manish.jaggi@linaro.org To: xen-devel@lists.xenproject.org, julien.grall@linaro.org, sameer.goel@linaro.org, andre.przywara@linaro.org Date: Tue, 2 Jan 2018 14:58:00 +0530 Message-Id: <20180102092809.1841-3-manish.jaggi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180102092809.1841-1-manish.jaggi@linaro.org> References: <20180102092809.1841-1-manish.jaggi@linaro.org> Cc: Manish Jaggi , manish.jaggi@cavium.com Subject: [Xen-devel] [RFC 02/11] acpi: arm: API to query estimated size of hardware domain's IORT X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Manish Jaggi Code to query estimated IORT size for hardware domain. IORT for hardware domain is generated using the requesterId and deviceId map. Signed-off-by: Manish Jaggi --- xen/arch/arm/domain_build.c | 12 ++++- xen/drivers/acpi/arm/Makefile | 1 + xen/drivers/acpi/arm/gen-iort.c | 101 ++++++++++++++++++++++++++++++++++++++++ xen/include/acpi/gen-iort.h | 6 +++ 4 files changed, 119 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index c74f4dd69d..f5d5e3d271 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -1799,7 +1800,7 @@ static int acpi_create_fadt(struct domain *d, struct membank tbl_add[]) static int estimate_acpi_efi_size(struct domain *d, struct kernel_info *kinfo) { - size_t efi_size, acpi_size, madt_size; + size_t efi_size, acpi_size, madt_size, iort_size; u64 addr; struct acpi_table_rsdp *rsdp_tbl; struct acpi_table_header *table; @@ -1840,6 +1841,15 @@ static int estimate_acpi_efi_size(struct domain *d, struct kernel_info *kinfo) acpi_os_unmap_memory(table, sizeof(struct acpi_table_header)); acpi_size += ROUNDUP(sizeof(struct acpi_table_rsdp), 8); + + if( estimate_iort_size(&iort_size) ) + { + printk("Unable to get hwdom iort size\n"); + return -EINVAL; + } + + acpi_size += ROUNDUP(iort_size, 8); + d->arch.efi_acpi_len = PAGE_ALIGN(ROUNDUP(efi_size, 8) + ROUNDUP(acpi_size, 8)); diff --git a/xen/drivers/acpi/arm/Makefile b/xen/drivers/acpi/arm/Makefile index 046fad5e3d..13f1a9159f 100644 --- a/xen/drivers/acpi/arm/Makefile +++ b/xen/drivers/acpi/arm/Makefile @@ -1 +1,2 @@ obj-y = ridmap.o +obj-y += gen-iort.o diff --git a/xen/drivers/acpi/arm/gen-iort.c b/xen/drivers/acpi/arm/gen-iort.c new file mode 100644 index 0000000000..3fc32959c6 --- /dev/null +++ b/xen/drivers/acpi/arm/gen-iort.c @@ -0,0 +1,101 @@ +/* + * xen/drivers/acpi/arm/gen-iort.c + * + * Code to generate IORT for hardware domain using the requesterId + * and deviceId map. + * + * Manish Jaggi + * Copyright (c) 2018 Linaro. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that 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. + */ + +#include +#include + +/* + * Size of hardware domains iort is calulcated based on the number of + * mappings in the requesterId - deviceId mapping list. + */ +int estimate_iort_size(size_t *iort_size) +{ + int count = 0; + int pcirc_count = 0; + int itsg_count = 0; + uint64_t *pcirc_array; + uint64_t *itsg_array; + struct rid_deviceid_map *rmap; + + list_for_each_entry(rmap, &rid_deviceid_map_list, entry) + count++; + + pcirc_array = xzalloc_bytes(sizeof(uint64_t)*count); + if ( !pcirc_array ) + return -ENOMEM; + + itsg_array = xzalloc_bytes(sizeof(uint64_t)*count); + if ( !itsg_array ) + return -ENOMEM; + + list_for_each_entry(rmap, &rid_deviceid_map_list, entry) + { + int i = 0; + + for (i=0; i <= pcirc_count; i++) + { + if ( pcirc_array[i] == (uint64_t)rmap->pcirc_node ) + break; + if ( i == pcirc_count ) + { + pcirc_array[i] = (uint64_t)rmap->pcirc_node; + pcirc_count++; + break; + } + } + + for ( i=0; i <= itsg_count; i++ ) + { + if ( itsg_array[i] == (uint64_t) rmap->its_node ) + break; + if ( i == itsg_count ) + { + itsg_array[i] = (uint64_t)rmap->its_node; + itsg_count++; + break; + } + } + } + + /* Size of IORT + * = Size of IORT Table Header + Size of PCIRC Header Nodes + + * Size of PCIRC nodes + Size of ITS Header nodes + Size of ITS Nodes + * + Size of Idmap nodes + */ + *iort_size = sizeof(struct acpi_table_iort) + + pcirc_count*( (sizeof(struct acpi_iort_node) -1) + + sizeof(struct acpi_iort_root_complex) ) + + itsg_count*( (sizeof(struct acpi_iort_node) -1) + + sizeof(struct acpi_iort_its_group) ) + + count*( sizeof(struct acpi_iort_id_mapping) ); + + xfree(itsg_array); + xfree(pcirc_array); + + return 0; +} +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/acpi/gen-iort.h b/xen/include/acpi/gen-iort.h new file mode 100644 index 0000000000..68e666fdce --- /dev/null +++ b/xen/include/acpi/gen-iort.h @@ -0,0 +1,6 @@ +#ifndef _GEN_IORT_H +#define _GEN_IORT_H + +int estimate_iort_size(size_t *iort_size); + +#endif From patchwork Tue Jan 2 09:28:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Jaggi X-Patchwork-Id: 123097 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8754982qgn; Tue, 2 Jan 2018 01:31:02 -0800 (PST) X-Google-Smtp-Source: ACJfBotcBiuJlPFISaQsI0FXqIsv73vJCJ7594qLYraxnoO4dG0ALR0oBKQ7oeZLUXHAPc/vXlHi X-Received: by 10.36.44.19 with SMTP id i19mr57352135iti.143.1514885462704; Tue, 02 Jan 2018 01:31:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514885462; cv=none; d=google.com; s=arc-20160816; b=ODS0xPgm5+VlH4/uLvAwC6ktN0bW5ahQ2bBRj8NwyXIxMjC7RlodvPnj6c1UEBE8wR NGjqFvWSXn0SuSYGMsRzDgs1ReXYR729D6M2ITyZzLfMVqh3v+jPl3HkOW7cbZbRmBE0 UEEG9Xkn358XHRJ3hw8etj82PerTys1DH7B/NxcQD2f7I9F5rZdSPURsxUqbzyKlp9Md nCJIS3RJMhXD83mhfNFiLUdR1ETv4VQaejIqCb3t4/CrPGeWlNfRvET7wKOtkr/XClBF cdq1jSQTiCa8ouhvoOt2UnzXGCFB5ivYBWZFNNDRaQe414dfNFHGyscHO0stAQAaVZ+/ eqzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=1W5buUkC2xlZxgMl63SRWl6pLpKpvekTAZbqum53hIk=; b=ogaO3UJjLQDa/iAau+Cmo2vxgKuszh/2UTCXNb40qRA2PEWqspobRCz5pgjpPJxPne ntZyRmA2HK6RYwj3JmY+Gew10ZNlF4qNLMrCyWy7r80WTfP4bC8Yb/kaDV51t6GWAEtk jfX4Pil9K1142HWkSDfjJJJ8TccfT7GRShLss/+LHrZfzHURr62YbnfPbwdS92c4QaEe OhJntSj8GI6HlRz/88ZQrHA9Be8xdhks4dRqc2ul+/Wfslf3W4O/mGN/FB7miFexr59p Or44+wRRZwM6/7pr85ZD69qGzvSAWaYQnmWeb8pi1XbkoHg008a/vjUTlrdS4BQn5GXW dqCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Wu5XIcc1; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id n13si12767962ioc.62.2018.01.02.01.31.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:31:02 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Wu5XIcc1; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsD-0002SA-Mi; Tue, 02 Jan 2018 09:28:41 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsC-0002Rl-VQ for xen-devel@lists.xenproject.org; Tue, 02 Jan 2018 09:28:41 +0000 X-Inumbo-ID: 296ead3a-ef9f-11e7-b4a6-bc764e045a96 Received: from mail-pf0-x242.google.com (unknown [2607:f8b0:400e:c00::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 296ead3a-ef9f-11e7-b4a6-bc764e045a96; Tue, 02 Jan 2018 10:27:33 +0100 (CET) Received: by mail-pf0-x242.google.com with SMTP id c204so25455901pfc.13 for ; Tue, 02 Jan 2018 01:28:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4KznkXKP3t2gdgLtkOpjefulVYHUYBh6Eys/vxpazQk=; b=Wu5XIcc1H05YFUAU3wIHJLDrIKHCfHif9jnkZDqJXVkSEKKD20rV5bwxfbTXNv6WpZ E24iIi9x+EJdTqJ2Oxn7x6ATVbGmZwtbDiOeb5CQievLgixFAxdFeQ6MwuxjjVgnM166 ykKRxSbNI18wgwA2wZdGyF9tyoY01yjrhZVSI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4KznkXKP3t2gdgLtkOpjefulVYHUYBh6Eys/vxpazQk=; b=oX0KaGCFiF/jz42ITytC4mOA3aGqc33QWRDYAlWWkpqJZWPesS7ZgikgZnG67A/JGA 4PtT7Wvm9pa/gOl1GJafvY+ZyOqnJrVzBFaY+ZVWIggAAjWTFVsntfb+WfAxUgUjOZ8Q hZQRMnW8UCdQQOp4AMVl82Sap+bh9G3e4133mkO+bVVDwFV08F0lwV2ISNy9JPhXnhCx 1HZ+Uwxx13Py7VUNpg1TWVOLscZyUqsgmp4S56gPg5oqVnRcpdqK9n9hlxP35fyPCnSs n+MZTKMFmUlMkx4tSN0hC+xmcvP3G/oJdo1V/Ag53+jXHzVRx9I/d7W3Ot/3rFrgjqjb qJLw== X-Gm-Message-State: AKGB3mIVgRnovFHWZ/rOTORjui8ogaml2iS1zv8lFowigA4CjQQkaZvO +vBrxI6yOjioUXXUlp6X79IyV5JbGEQ= X-Received: by 10.98.144.141 with SMTP id q13mr45269583pfk.140.1514885318704; Tue, 02 Jan 2018 01:28:38 -0800 (PST) Received: from thunder-dev-box.domain.name ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id e8sm22065207pgs.44.2018.01.02.01.28.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:28:38 -0800 (PST) From: manish.jaggi@linaro.org To: xen-devel@lists.xenproject.org, julien.grall@linaro.org, sameer.goel@linaro.org, andre.przywara@linaro.org Date: Tue, 2 Jan 2018 14:58:01 +0530 Message-Id: <20180102092809.1841-4-manish.jaggi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180102092809.1841-1-manish.jaggi@linaro.org> References: <20180102092809.1841-1-manish.jaggi@linaro.org> Cc: Manish Jaggi , manish.jaggi@cavium.com Subject: [Xen-devel] [RFC 03/11] acpi: arm: Code to generate Hardware Domains IORT X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Manish Jaggi Singed-off-by: Manish Jaggi --- xen/arch/arm/domain_build.c | 28 +++++ xen/drivers/acpi/arm/gen-iort.c | 253 +++++++++++++++++++++++++++++++++++++++- xen/include/acpi/gen-iort.h | 1 + xen/include/asm-arm/acpi.h | 1 + 4 files changed, 282 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index f5d5e3d271..9831943147 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1654,6 +1654,8 @@ static int acpi_create_xsdt(struct domain *d, struct membank tbl_add[]) ACPI_SIG_FADT, tbl_add[TBL_FADT].start); acpi_xsdt_modify_entry(xsdt->table_offset_entry, entry_count, ACPI_SIG_MADT, tbl_add[TBL_MADT].start); + acpi_xsdt_modify_entry(xsdt->table_offset_entry, entry_count, + ACPI_SIG_IORT, tbl_add[TBL_IORT].start); xsdt->table_offset_entry[entry_count] = tbl_add[TBL_STAO].start; xsdt->header.length = table_size; @@ -1704,6 +1706,28 @@ static int acpi_create_stao(struct domain *d, struct membank tbl_add[]) return 0; } +static int acpi_create_iort(struct domain *d, struct membank tbl_add[]) +{ + struct acpi_table_iort *hwdom_table; + unsigned int size = 0; + + tbl_add[TBL_IORT].start = d->arch.efi_acpi_gpa + + acpi_get_table_offset(tbl_add, TBL_IORT); + hwdom_table = d->arch.efi_acpi_table + + acpi_get_table_offset(tbl_add, TBL_IORT); + + if ( prepare_iort(hwdom_table, &size) ) + { + printk("Failed to write IORT table\n"); + return -EINVAL; + } + printk("%s %d %d \r\n", __func__, __LINE__, size); + + tbl_add[TBL_IORT].size = size; + printk("%s %d %d \r\n", __func__, __LINE__, size); + return 0; +} + static int acpi_create_madt(struct domain *d, struct membank tbl_add[]) { struct acpi_table_header *table = NULL; @@ -1899,6 +1923,10 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo) if ( rc != 0 ) return rc; + rc = acpi_create_iort(d, tbl_add); + if ( rc != 0 ) + return rc; + rc = acpi_create_xsdt(d, tbl_add); if ( rc != 0 ) return rc; diff --git a/xen/drivers/acpi/arm/gen-iort.c b/xen/drivers/acpi/arm/gen-iort.c index 3fc32959c6..f368000753 100644 --- a/xen/drivers/acpi/arm/gen-iort.c +++ b/xen/drivers/acpi/arm/gen-iort.c @@ -21,6 +21,257 @@ #include #include +/* + * Structure of Hardware domain's IORT + * ----------------------------------- + * + * Below is the structure of the IORT which this code generates. + * + * [IORT Header] + * [ITS Group 1 ] + * [ITS Group N ] + * [PCIRC Node 1] + * [PCIRC IDMAP entry 1] + * [PCIRC IDMAP entry N] + * [PCIRC Node N] + * + * requesterId- deviceId mapping list poplated by parsing IORT is used + * to create nodes and idmaps. + * We have one small problem, how to resolve the its grooup node offset from + * the firmware iort to the ones in hardware domains IORT. + * + * Since the ITS group node pointer stored with the rid-devid map is used + * to populate the ITS Group nodes in the hardware domains' IORT. + * We create another map to save the offset of the ITS group node written + * in the hardware domain IORT with the ITS node pointer in the firmware IORT. + * + * This offset is later used when writing pcirc idmaps output_reference. + */ +struct its_node_offset_map +{ + struct acpi_iort_node *its_node; + unsigned int offset; + struct list_head entry; +}; +struct list_head its_map_list; + +int set_its_node_offset(struct acpi_iort_node *its_node, unsigned int offset) +{ + struct its_node_offset_map *its_map; + list_for_each_entry(its_map, &its_map_list, entry) + { + if ( its_map->its_node == its_node ) + return 0; + } + + its_map = xzalloc(struct its_node_offset_map); + if ( !its_map ) + return -ENOMEM; + + its_map->its_node = its_node; + its_map->offset = offset; + list_add_tail(&its_map->entry, &its_map_list); + + return 0; +} +/* + * This method would be used in write_pcirc_nodes when writing idmaps + */ +unsigned int get_its_node_offset(struct acpi_iort_node *its_node) +{ + struct its_node_offset_map *its_map; + list_for_each_entry(its_map, &its_map_list, entry) + { + if ( its_map->its_node == its_node ) + return its_map->offset; + } + + return 0; +} + +void free_its_node_offset_list(void) +{ + + struct its_node_offset_map *its_map; + list_for_each_entry(its_map, &its_map_list, entry) + xfree(its_map); + + list_del(&its_map_list); +} + +void write_its_group(u8 *iort, unsigned int *offset, unsigned int *num_nodes) +{ + struct rid_deviceid_map *rmap; + unsigned int of = *offset; + int n=0; + INIT_LIST_HEAD(&its_map_list); + /* + * rid_deviceid_map_list is iterated to get unique its group nodes + * Each unique ITS group node is written in hardware domains IORT + * by using some values from the firmware ITS group node. + */ + list_for_each_entry(rmap, &rid_deviceid_map_list, entry) + { + struct acpi_iort_node *node; + struct acpi_iort_its_group *grp; + struct acpi_iort_its_group *fw_grp; + + /* save its_node_offset_map in a list uniquely */ + if ( !set_its_node_offset(rmap->its_node, of) ) + { + node = (struct acpi_iort_node *) &iort[of]; + grp = (struct acpi_iort_its_group *)(&node->node_data); + + node->type = ACPI_IORT_NODE_ITS_GROUP; + node->length = sizeof(struct acpi_iort_node) + + sizeof(struct acpi_iort_its_group) - + sizeof(node->node_data); + + node->revision = rmap->its_node->revision; + node->reserved = 0; + node->mapping_count = 0; + node->mapping_offset= 0; + + fw_grp = (struct acpi_iort_its_group *)(&rmap->its_node->node_data); + + grp->its_count = fw_grp->its_count; + grp->identifiers[0] = fw_grp->identifiers[0]; + + of += node->length; + n++; + } + } + *offset = of; + *num_nodes = n; +} + +/* It is assumed that rid_map_devid is sorted by pcirc_nodes */ +void write_pcirc_nodes(u8 *iort, unsigned int *pos, unsigned int *num_nodes) +{ + struct acpi_iort_node *opcirc_node, *pcirc_node; + struct acpi_iort_node *hwdom_pcirc_node = NULL; + struct rid_deviceid_map *rmap; + struct acpi_iort_id_mapping *idmap; + int num_idmap = 0, n = 0; + unsigned int old_pos = *pos; + + opcirc_node = NULL; + /* Iterate rid_map_devid list */ + list_for_each_entry(rmap, &rid_deviceid_map_list, entry) + { + struct acpi_iort_root_complex *rc; + struct acpi_iort_root_complex *rc_fw; + int add_node = 0; + pcirc_node = rmap->pcirc_node; + + if ( opcirc_node == NULL ) /* First entry */ + { + add_node = 1; + } + else if ( opcirc_node != pcirc_node ) /* another pci_rc_node found*/ + { + /* All the idmaps of a pcirc are written, now update node info*/ + hwdom_pcirc_node->length = num_idmap * + sizeof(struct acpi_iort_id_mapping) + + sizeof(struct acpi_iort_node) + + sizeof(struct acpi_iort_root_complex) - + sizeof(pcirc_node->node_data); + + hwdom_pcirc_node->mapping_count = num_idmap; + hwdom_pcirc_node->mapping_offset = sizeof(struct acpi_iort_node) + + sizeof(struct acpi_iort_root_complex) - + sizeof(pcirc_node->node_data); + old_pos += hwdom_pcirc_node->length; + add_node = 1; + } + + if ( add_node ) /* create the pcirc node */ + { + opcirc_node = pcirc_node; + hwdom_pcirc_node = (struct acpi_iort_node *)&iort[old_pos]; + hwdom_pcirc_node->type = ACPI_IORT_NODE_PCI_ROOT_COMPLEX; + hwdom_pcirc_node->mapping_offset = sizeof(struct acpi_iort_node) + + sizeof(struct acpi_iort_root_complex) - + sizeof(hwdom_pcirc_node->node_data); + + rc = (struct acpi_iort_root_complex *) + &hwdom_pcirc_node->node_data; + + rc_fw = (struct acpi_iort_root_complex *) + &pcirc_node->node_data; + + rc->pci_segment_number = rc_fw->pci_segment_number; + rc->ats_attribute = rc_fw->ats_attribute; + rc->memory_properties = rc_fw->memory_properties; + + idmap = ACPI_ADD_PTR(struct acpi_iort_id_mapping, + hwdom_pcirc_node, + hwdom_pcirc_node->mapping_offset); + n++; + num_idmap = 0; + } + + idmap->input_base = rmap->idmap.input_base; + idmap->id_count = rmap->idmap.id_count; + idmap->output_base = rmap->idmap.output_base; + idmap->output_reference = get_its_node_offset(rmap->its_node); + idmap->flags = 0; + + idmap++; + num_idmap++; + } + + if ( hwdom_pcirc_node ) /* if no further PCIRC nodes found */ + { + /* All the idmaps of a pcirc are written, now update node info*/ + hwdom_pcirc_node->length = num_idmap * + sizeof(struct acpi_iort_id_mapping) + + sizeof(struct acpi_iort_node) + + sizeof(struct acpi_iort_root_complex) -1; + + hwdom_pcirc_node->mapping_count = num_idmap; + old_pos += hwdom_pcirc_node->length; + } + + *pos = old_pos; + *num_nodes = n; +} + +int prepare_iort(struct acpi_table_iort *hwdom_iort, unsigned int *iort_size) +{ + struct acpi_table_iort *fw_iort; + unsigned int num_nodes = 0; + unsigned int pos; + + pos = sizeof(struct acpi_table_iort); + + if ( acpi_get_table(ACPI_SIG_IORT, 0, + (struct acpi_table_header **)&fw_iort) ) + { + printk("Failed to get IORT table\n"); + return -ENODEV; + } + + /* Write IORT header */ + ACPI_MEMCPY(hwdom_iort, fw_iort, sizeof(struct acpi_table_iort)); + hwdom_iort->node_offset = pos; + hwdom_iort->node_count = 0; + + /* Write its group nodes */ + write_its_group((u8*)hwdom_iort, &pos, &num_nodes); + hwdom_iort->node_count = num_nodes; + /* Write pcirc_nodes*/ + write_pcirc_nodes((u8*)hwdom_iort, &pos, &num_nodes); + /* Update IORT Size in IORT header */ + hwdom_iort->node_count += num_nodes; + hwdom_iort->header.length = pos; + hwdom_iort->header.checksum = 0; /* TODO */ + + *iort_size = hwdom_iort->header.length; + + return 0; +} + /* * Size of hardware domains iort is calulcated based on the number of * mappings in the requesterId - deviceId mapping list. @@ -49,7 +300,7 @@ int estimate_iort_size(size_t *iort_size) { int i = 0; - for (i=0; i <= pcirc_count; i++) + for ( i=0; i <= pcirc_count; i++ ) { if ( pcirc_array[i] == (uint64_t)rmap->pcirc_node ) break; diff --git a/xen/include/acpi/gen-iort.h b/xen/include/acpi/gen-iort.h index 68e666fdce..4de31b7b9f 100644 --- a/xen/include/acpi/gen-iort.h +++ b/xen/include/acpi/gen-iort.h @@ -2,5 +2,6 @@ #define _GEN_IORT_H int estimate_iort_size(size_t *iort_size); +int prepare_iort(struct acpi_table_iort *hwdom_iort, unsigned int *iort_size); #endif diff --git a/xen/include/asm-arm/acpi.h b/xen/include/asm-arm/acpi.h index c183b6bb6e..f8b5254621 100644 --- a/xen/include/asm-arm/acpi.h +++ b/xen/include/asm-arm/acpi.h @@ -36,6 +36,7 @@ typedef enum { TBL_FADT, TBL_MADT, TBL_STAO, + TBL_IORT, TBL_XSDT, TBL_RSDP, TBL_EFIT, From patchwork Tue Jan 2 09:28:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Jaggi X-Patchwork-Id: 123104 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8755119qgn; Tue, 2 Jan 2018 01:31:14 -0800 (PST) X-Google-Smtp-Source: ACJfBosqKQXUVGnjfO9pKYOfgw8VCsRw94F3RFKWJ9kf4iKaDtHH0guaNXpOQ+tWqpLQcCEOGRY7 X-Received: by 10.36.225.143 with SMTP id n137mr59567520ith.34.1514885474673; Tue, 02 Jan 2018 01:31:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514885474; cv=none; d=google.com; s=arc-20160816; b=lDROTooA6GYJs9rS3ORfMG5oEQaQff+6Zj97Dp+8nOjl9uRHv9A0CTuJrK61oqxTup G+lzAI4GwhArDIvn9kRy5aFAm7kX+YL5ZOJHaLplGGzj7w7Eautm57aSf+YHZBQ+HuKF mxKpWbjD0csDn6VAjgsJpNPvCpFfUo1VS3UpMI4BxKOgwU9pJkpmrVnswvo3Ko/S10BP f8pJvnKKFA9p16hLIN37CmThnxOjOgrTxUNuCC1TxDd8TDeVLsDTHaFgvwpBQZsXdqdZ 2QoPz7QnOHMuDO3nupKWsOGiMN3Z24tcBvopMm8Uv26fkS8FBFLEe9yv+s7B/ms5tSwZ n4uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=PAI9bq78MzkD0VPh/qn6tXJ/qx7sOsw52/seAlT+PXg=; b=qdUJGDeV019azLwPgDue6zotkBw5J7PM4gmOILyVJhu5Az4PJT9a7LE1wz3g0NTfoU r7rMYrZgSPqo3BX9wehY7v1WoLXu7Pykxn1EcHz9zIODy38wDo5deWJ58JAQ+x6B54V6 knOyx+j6wo5htorDVlu8SITjRxJ6bORfEWld+KSMH/vJBftbvMAqWMMxeq27YpTEFQ+D Jt8phRggcqfeOowftpyvE4Std2jvzwkFaRA9lxocMoDBq9P1zdc04B7h2M3pfuwgwnJC eGIczYgf+ONVsakZC37/GnKr2GI4/ScIzJAMOQCmUELH3EpSqfAp9GSz904tlw4eBeaj btuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AV6gV0E9; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id v6si8342196iov.15.2018.01.02.01.31.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:31:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AV6gV0E9; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsL-0002VE-Tq; Tue, 02 Jan 2018 09:28:49 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsK-0002Us-Vw for xen-devel@lists.xenproject.org; Tue, 02 Jan 2018 09:28:49 +0000 X-Inumbo-ID: 2d69e40b-ef9f-11e7-b4a6-bc764e045a96 Received: from mail-pf0-x244.google.com (unknown [2607:f8b0:400e:c00::244]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2d69e40b-ef9f-11e7-b4a6-bc764e045a96; Tue, 02 Jan 2018 10:27:40 +0100 (CET) Received: by mail-pf0-x244.google.com with SMTP id e3so25451506pfi.10 for ; Tue, 02 Jan 2018 01:28:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/WGjXp5xYy+K/ID94EXO7dTLfdDskRKKDUG7O7H6mNU=; b=AV6gV0E9KveXY9mfD65k579HDmDG0EknuK7aTp2QRnOwWBCU7yncKtdjsv8goNoY+B 2xNDx1pIeut50raTCU1s8p/tUkA6s3OdeZXknsxTegMBgLlW5GKFdXr4OmJOILizYg5h rXAVZe8bZl3vUJTee1IiOaFyDFEYli5sRY8sI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/WGjXp5xYy+K/ID94EXO7dTLfdDskRKKDUG7O7H6mNU=; b=Wpz6aHi+tU7Bh/Z7vEfdzNxwAjuDAg/f82cav2AG/cWPSuw4BSidkeyRiO3AAXw7LK Q48+6YHRW/aK0yUxaBqr9/caZn9GiemWr8sVnj8wSr1M1RMI3MR4wdm7j92z8BEqaF+i Kba+6mW8G8l170a+nVKdv2jCZytnTI8AUdMkgpO5Dac16CSDLz0ap56+wPPvV1ChOi7a zFvl5Ciw1zw/mv1BcxE+ndXDlsRJd6jImBgKtkKKfSJgJbleq1bTRJMjZa+qaXoXlRom w2KVuaH2t/kt8PMh9fT0GVvtEGMp8hi/EV7PXkaXZhY14NagCFROrCL/0SRXZIfL8Dbu gtGA== X-Gm-Message-State: AKGB3mK511CaRT9ymOXN2qgSPRNq+f5+mkhJQckUtu/gxq8z1q6u7ykX HM2ptZu1RXf43oIwyK1Er5Z6CIJ9maU= X-Received: by 10.99.176.3 with SMTP id h3mr39867502pgf.207.1514885324766; Tue, 02 Jan 2018 01:28:44 -0800 (PST) Received: from thunder-dev-box.domain.name ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id e8sm22065207pgs.44.2018.01.02.01.28.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:28:44 -0800 (PST) From: manish.jaggi@linaro.org To: xen-devel@lists.xenproject.org, julien.grall@linaro.org, sameer.goel@linaro.org, andre.przywara@linaro.org Date: Tue, 2 Jan 2018 14:58:02 +0530 Message-Id: <20180102092809.1841-5-manish.jaggi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180102092809.1841-1-manish.jaggi@linaro.org> References: <20180102092809.1841-1-manish.jaggi@linaro.org> Cc: Manish Jaggi , manish.jaggi@cavium.com Subject: [Xen-devel] [RFC 04/11] Import iort.c and acpi_iort.h X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Manish Jaggi Import iort.c and acpi_iort.h from linux kernel tag v4.14 Signed-off-by: Manish Jaggi --- xen/drivers/acpi/arm/iort.c | 1279 ++++++++++++++++++++++++++++++++++++++++++ xen/include/acpi/acpi_iort.h | 57 ++ 2 files changed, 1336 insertions(+) diff --git a/xen/drivers/acpi/arm/iort.c b/xen/drivers/acpi/arm/iort.c new file mode 100644 index 0000000000..de56394dd1 --- /dev/null +++ b/xen/drivers/acpi/arm/iort.c @@ -0,0 +1,1279 @@ +/* + * 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 +#include +#include +#include +#include + +#define IORT_TYPE_MASK(type) (1 << (type)) +#define IORT_MSI_TYPE (1 << ACPI_IORT_NODE_ITS_GROUP) +#define IORT_IOMMU_TYPE ((1 << ACPI_IORT_NODE_SMMU) | \ + (1 << ACPI_IORT_NODE_SMMU_V3)) + +/* Until ACPICA headers cover IORT rev. C */ +#ifndef ACPI_IORT_SMMU_V3_CAVIUM_CN99XX +#define ACPI_IORT_SMMU_V3_CAVIUM_CN99XX 0x2 +#endif + +struct iort_its_msi_chip { + struct list_head list; + struct fwnode_handle *fw_node; + u32 translation_id; +}; + +struct iort_fwnode { + struct list_head list; + struct acpi_iort_node *iort_node; + struct fwnode_handle *fwnode; +}; +static LIST_HEAD(iort_fwnode_list); +static DEFINE_SPINLOCK(iort_fwnode_lock); + +/** + * iort_set_fwnode() - Create iort_fwnode and use it to register + * iommu data in the iort_fwnode_list + * + * @node: IORT table node associated with the IOMMU + * @fwnode: fwnode associated with the IORT node + * + * Returns: 0 on success + * <0 on failure + */ +static inline int iort_set_fwnode(struct acpi_iort_node *iort_node, + struct fwnode_handle *fwnode) +{ + struct iort_fwnode *np; + + np = kzalloc(sizeof(struct iort_fwnode), GFP_ATOMIC); + + if (WARN_ON(!np)) + return -ENOMEM; + + INIT_LIST_HEAD(&np->list); + np->iort_node = iort_node; + np->fwnode = fwnode; + + spin_lock(&iort_fwnode_lock); + list_add_tail(&np->list, &iort_fwnode_list); + spin_unlock(&iort_fwnode_lock); + + return 0; +} + +/** + * iort_get_fwnode() - Retrieve fwnode associated with an IORT node + * + * @node: IORT table node to be looked-up + * + * Returns: fwnode_handle pointer on success, NULL on failure + */ +static inline +struct fwnode_handle *iort_get_fwnode(struct acpi_iort_node *node) +{ + struct iort_fwnode *curr; + struct fwnode_handle *fwnode = NULL; + + spin_lock(&iort_fwnode_lock); + list_for_each_entry(curr, &iort_fwnode_list, list) { + if (curr->iort_node == node) { + fwnode = curr->fwnode; + break; + } + } + spin_unlock(&iort_fwnode_lock); + + return fwnode; +} + +/** + * iort_delete_fwnode() - Delete fwnode associated with an IORT node + * + * @node: IORT table node associated with fwnode to delete + */ +static inline void iort_delete_fwnode(struct acpi_iort_node *node) +{ + struct iort_fwnode *curr, *tmp; + + spin_lock(&iort_fwnode_lock); + list_for_each_entry_safe(curr, tmp, &iort_fwnode_list, list) { + if (curr->iort_node == node) { + list_del(&curr->list); + kfree(curr); + break; + } + } + spin_unlock(&iort_fwnode_lock); +} + +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 LIST_HEAD(iort_msi_chip_list); +static DEFINE_SPINLOCK(iort_msi_chip_lock); + +/** + * iort_register_domain_token() - register domain token and related ITS ID + * to the list from where we can get it back later on. + * @trans_id: ITS ID. + * @fw_node: Domain token. + * + * Returns: 0 on success, -ENOMEM if no memory when allocating list element + */ +int iort_register_domain_token(int trans_id, struct fwnode_handle *fw_node) +{ + struct iort_its_msi_chip *its_msi_chip; + + its_msi_chip = kzalloc(sizeof(*its_msi_chip), GFP_KERNEL); + if (!its_msi_chip) + return -ENOMEM; + + its_msi_chip->fw_node = fw_node; + its_msi_chip->translation_id = trans_id; + + spin_lock(&iort_msi_chip_lock); + list_add(&its_msi_chip->list, &iort_msi_chip_list); + spin_unlock(&iort_msi_chip_lock); + + return 0; +} + +/** + * iort_deregister_domain_token() - Deregister domain token based on ITS ID + * @trans_id: ITS ID. + * + * Returns: none. + */ +void iort_deregister_domain_token(int trans_id) +{ + struct iort_its_msi_chip *its_msi_chip, *t; + + spin_lock(&iort_msi_chip_lock); + list_for_each_entry_safe(its_msi_chip, t, &iort_msi_chip_list, list) { + if (its_msi_chip->translation_id == trans_id) { + list_del(&its_msi_chip->list); + kfree(its_msi_chip); + break; + } + } + spin_unlock(&iort_msi_chip_lock); +} + +/** + * iort_find_domain_token() - Find domain token based on given ITS ID + * @trans_id: ITS ID. + * + * Returns: domain token when find on the list, NULL otherwise + */ +struct fwnode_handle *iort_find_domain_token(int trans_id) +{ + struct fwnode_handle *fw_node = NULL; + struct iort_its_msi_chip *its_msi_chip; + + spin_lock(&iort_msi_chip_lock); + list_for_each_entry(its_msi_chip, &iort_msi_chip_list, list) { + if (its_msi_chip->translation_id == trans_id) { + fw_node = its_msi_chip->fw_node; + break; + } + } + spin_unlock(&iort_msi_chip_lock); + + return fw_node; +} + +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; + + if (!iort_table) + return NULL; + + /* Get the first IORT node */ + iort = (struct acpi_table_iort *)iort_table; + 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 && + 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; + acpi_status status = AE_NOT_FOUND; + + if (node->type == ACPI_IORT_NODE_NAMED_COMPONENT) { + struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_device *adev = to_acpi_device_node(dev->fwnode); + struct acpi_iort_named_component *ncomp; + + if (!adev) + goto out; + + status = acpi_get_name(adev->handle, ACPI_FULL_PATHNAME, &buf); + if (ACPI_FAILURE(status)) { + dev_warn(dev, "Can't get device full path name\n"); + goto out; + } + + ncomp = (struct acpi_iort_named_component *)node->node_data; + status = !strcmp(ncomp->device_name, buf.pointer) ? + AE_OK : AE_NOT_FOUND; + acpi_os_free(buf.pointer); + } else if (node->type == 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. + */ + status = pci_rc->pci_segment_number == pci_domain_nr(bus) ? + AE_OK : AE_NOT_FOUND; + } +out: + return status; +} + +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_get_id(struct acpi_iort_node *node, + u32 *id_out, int index) +{ + struct acpi_iort_node *parent; + struct acpi_iort_id_mapping *map; + + if (!node->mapping_offset || !node->mapping_count || + index >= node->mapping_count) + return NULL; + + map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, node, + node->mapping_offset + index * sizeof(*map)); + + /* Firmware bug! */ + if (!map->output_reference) { + pr_err(FW_BUG "[node %p type %d] ID map has NULL parent reference\n", + node, node->type); + return NULL; + } + + parent = ACPI_ADD_PTR(struct acpi_iort_node, iort_table, + map->output_reference); + + if (map->flags & ACPI_IORT_ID_SINGLE_MAPPING) { + if (node->type == ACPI_IORT_NODE_NAMED_COMPONENT || + node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) { + *id_out = map->output_base; + return parent; + } + } + + return NULL; +} + +static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node, + u32 id_in, u32 *id_out, + u8 type_mask) +{ + u32 id = id_in; + + /* Parse the ID mapping tree to find specified node type */ + while (node) { + struct acpi_iort_id_mapping *map; + int i; + + if (IORT_TYPE_MASK(node->type) & type_mask) { + if (id_out) + *id_out = id; + 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 ID translation */ + for (i = 0; i < node->mapping_count; i++, map++) { + if (!iort_id_map(map, node->type, id, &id)) + 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 ID to output ID unchanged on mapping failure */ + if (id_out) + *id_out = id_in; + + return NULL; +} + +static +struct acpi_iort_node *iort_node_map_platform_id(struct acpi_iort_node *node, + u32 *id_out, u8 type_mask, + int index) +{ + struct acpi_iort_node *parent; + u32 id; + + /* step 1: retrieve the initial dev id */ + parent = iort_node_get_id(node, &id, index); + if (!parent) + return NULL; + + /* + * optional step 2: map the initial dev id if its parent is not + * the target type we want, map it again for the use cases such + * as NC (named component) -> SMMU -> ITS. If the type is matched, + * return the initial dev id and its parent pointer directly. + */ + if (!(IORT_TYPE_MASK(parent->type) & type_mask)) + parent = iort_node_map_id(parent, id, id_out, type_mask); + else + if (id_out) + *id_out = id; + + return parent; +} + +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); +} + +/** + * iort_msi_map_rid() - Map a MSI requester ID for a device + * @dev: The device for which the mapping is to be done. + * @req_id: The device requester ID. + * + * Returns: mapped MSI RID on success, input requester ID otherwise + */ +u32 iort_msi_map_rid(struct device *dev, u32 req_id) +{ + struct acpi_iort_node *node; + u32 dev_id; + + node = iort_find_dev_node(dev); + if (!node) + return req_id; + + iort_node_map_id(node, req_id, &dev_id, IORT_MSI_TYPE); + return dev_id; +} + +/** + * iort_pmsi_get_dev_id() - Get the device id for a device + * @dev: The device for which the mapping is to be done. + * @dev_id: The device ID found. + * + * Returns: 0 for successful find a dev id, -ENODEV on error + */ +int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id) +{ + int i; + struct acpi_iort_node *node; + + node = iort_find_dev_node(dev); + if (!node) + return -ENODEV; + + for (i = 0; i < node->mapping_count; i++) { + if (iort_node_map_platform_id(node, dev_id, IORT_MSI_TYPE, i)) + return 0; + } + + return -ENODEV; +} + +/** + * iort_dev_find_its_id() - Find the ITS identifier for a device + * @dev: The device. + * @req_id: Device's requester ID + * @idx: Index of the ITS identifier list. + * @its_id: ITS identifier. + * + * Returns: 0 on success, appropriate error value otherwise + */ +static int iort_dev_find_its_id(struct device *dev, u32 req_id, + unsigned int idx, int *its_id) +{ + struct acpi_iort_its_group *its; + struct acpi_iort_node *node; + + node = iort_find_dev_node(dev); + if (!node) + return -ENXIO; + + node = iort_node_map_id(node, req_id, NULL, IORT_MSI_TYPE); + if (!node) + return -ENXIO; + + /* Move to ITS specific data */ + its = (struct acpi_iort_its_group *)node->node_data; + if (idx > its->its_count) { + dev_err(dev, "requested ITS ID index [%d] is greater than available [%d]\n", + idx, its->its_count); + return -ENXIO; + } + + *its_id = its->identifiers[idx]; + return 0; +} + +/** + * iort_get_device_domain() - Find MSI domain related to a device + * @dev: The device. + * @req_id: Requester ID for the device. + * + * Returns: the MSI domain for this device, NULL otherwise + */ +struct irq_domain *iort_get_device_domain(struct device *dev, u32 req_id) +{ + struct fwnode_handle *handle; + int its_id; + + if (iort_dev_find_its_id(dev, req_id, 0, &its_id)) + return NULL; + + handle = iort_find_domain_token(its_id); + if (!handle) + return NULL; + + return irq_find_matching_fwnode(handle, DOMAIN_BUS_PCI_MSI); +} + +/** + * iort_get_platform_device_domain() - Find MSI domain related to a + * platform device + * @dev: the dev pointer associated with the platform device + * + * Returns: the MSI domain for this device, NULL otherwise + */ +static struct irq_domain *iort_get_platform_device_domain(struct device *dev) +{ + struct acpi_iort_node *node, *msi_parent; + struct fwnode_handle *iort_fwnode; + struct acpi_iort_its_group *its; + int i; + + /* find its associated iort node */ + node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT, + iort_match_node_callback, dev); + if (!node) + return NULL; + + /* then find its msi parent node */ + for (i = 0; i < node->mapping_count; i++) { + msi_parent = iort_node_map_platform_id(node, NULL, + IORT_MSI_TYPE, i); + if (msi_parent) + break; + } + + if (!msi_parent) + return NULL; + + /* Move to ITS specific data */ + its = (struct acpi_iort_its_group *)msi_parent->node_data; + + iort_fwnode = iort_find_domain_token(its->identifiers[0]); + if (!iort_fwnode) + return NULL; + + return irq_find_matching_fwnode(iort_fwnode, DOMAIN_BUS_PLATFORM_MSI); +} + +void acpi_configure_pmsi_domain(struct device *dev) +{ + struct irq_domain *msi_domain; + + msi_domain = iort_get_platform_device_domain(dev); + if (msi_domain) + dev_set_msi_domain(dev, msi_domain); +} + +static int __maybe_unused __get_pci_rid(struct pci_dev *pdev, u16 alias, + void *data) +{ + u32 *rid = data; + + *rid = alias; + return 0; +} + +static int arm_smmu_iort_xlate(struct device *dev, u32 streamid, + struct fwnode_handle *fwnode, + const struct iommu_ops *ops) +{ + int ret = iommu_fwspec_init(dev, fwnode, ops); + + if (!ret) + ret = iommu_fwspec_add_ids(dev, &streamid, 1); + + return ret; +} + +static inline bool iort_iommu_driver_enabled(u8 type) +{ + switch (type) { + case ACPI_IORT_NODE_SMMU_V3: + return IS_BUILTIN(CONFIG_ARM_SMMU_V3); + case ACPI_IORT_NODE_SMMU: + return IS_BUILTIN(CONFIG_ARM_SMMU); + default: + pr_warn("IORT node type %u does not describe an SMMU\n", type); + return false; + } +} + +#ifdef CONFIG_IOMMU_API +static inline +const struct iommu_ops *iort_fwspec_iommu_ops(struct iommu_fwspec *fwspec) +{ + return (fwspec && fwspec->ops) ? fwspec->ops : NULL; +} + +static inline +int iort_add_device_replay(const struct iommu_ops *ops, struct device *dev) +{ + int err = 0; + + if (ops->add_device && dev->bus && !dev->iommu_group) + err = ops->add_device(dev); + + return err; +} +#else +static inline +const struct iommu_ops *iort_fwspec_iommu_ops(struct iommu_fwspec *fwspec) +{ return NULL; } +static inline +int iort_add_device_replay(const struct iommu_ops *ops, struct device *dev) +{ return 0; } +#endif + +static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node, + u32 streamid) +{ + const struct iommu_ops *ops; + struct fwnode_handle *iort_fwnode; + + if (!node) + return -ENODEV; + + iort_fwnode = iort_get_fwnode(node); + if (!iort_fwnode) + return -ENODEV; + + /* + * If the ops look-up fails, this means that either + * the SMMU drivers have not been probed yet or that + * the SMMU drivers are not built in the kernel; + * Depending on whether the SMMU drivers are built-in + * in the kernel or not, defer the IOMMU configuration + * or just abort it. + */ + ops = iommu_ops_from_fwnode(iort_fwnode); + if (!ops) + return iort_iommu_driver_enabled(node->type) ? + -EPROBE_DEFER : -ENODEV; + + return arm_smmu_iort_xlate(dev, streamid, iort_fwnode, ops); +} + +struct iort_pci_alias_info { + struct device *dev; + struct acpi_iort_node *node; +}; + +static int iort_pci_iommu_init(struct pci_dev *pdev, u16 alias, void *data) +{ + struct iort_pci_alias_info *info = data; + struct acpi_iort_node *parent; + u32 streamid; + + parent = iort_node_map_id(info->node, alias, &streamid, + IORT_IOMMU_TYPE); + return iort_iommu_xlate(info->dev, parent, streamid); +} + +static int nc_dma_get_range(struct device *dev, u64 *size) +{ + struct acpi_iort_node *node; + struct acpi_iort_named_component *ncomp; + + node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT, + iort_match_node_callback, dev); + if (!node) + return -ENODEV; + + ncomp = (struct acpi_iort_named_component *)node->node_data; + + *size = ncomp->memory_address_limit >= 64 ? U64_MAX : + 1ULL<memory_address_limit; + + return 0; +} + +/** + * iort_dma_setup() - Set-up device DMA parameters. + * + * @dev: device to configure + * @dma_addr: device DMA address result pointer + * @size: DMA range size result pointer + */ +void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) +{ + u64 mask, dmaaddr = 0, size = 0, offset = 0; + int ret, msb; + + /* + * Set default coherent_dma_mask to 32 bit. Drivers are expected to + * setup the correct supported mask. + */ + if (!dev->coherent_dma_mask) + dev->coherent_dma_mask = DMA_BIT_MASK(32); + + /* + * Set it to coherent_dma_mask by default if the architecture + * code has not set it. + */ + if (!dev->dma_mask) + dev->dma_mask = &dev->coherent_dma_mask; + + size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1); + + if (dev_is_pci(dev)) + ret = acpi_dma_get_range(dev, &dmaaddr, &offset, &size); + else + ret = nc_dma_get_range(dev, &size); + + if (!ret) { + msb = fls64(dmaaddr + size - 1); + /* + * Round-up to the power-of-two mask or set + * the mask to the whole 64-bit address space + * in case the DMA region covers the full + * memory window. + */ + mask = msb == 64 ? U64_MAX : (1ULL << msb) - 1; + /* + * Limit coherent and dma mask based on size + * retrieved from firmware. + */ + dev->coherent_dma_mask = mask; + *dev->dma_mask = mask; + } + + *dma_addr = dmaaddr; + *dma_size = size; + + dev->dma_pfn_offset = PFN_DOWN(offset); + dev_dbg(dev, "dma_pfn_offset(%#08llx)\n", offset); +} + +/** + * iort_iommu_configure - Set-up IOMMU configuration for a device. + * + * @dev: device to configure + * + * Returns: iommu_ops pointer on configuration success + * NULL on configuration failure + */ +const struct iommu_ops *iort_iommu_configure(struct device *dev) +{ + struct acpi_iort_node *node, *parent; + const struct iommu_ops *ops; + u32 streamid = 0; + int err = -ENODEV; + + /* + * If we already translated the fwspec there + * is nothing left to do, return the iommu_ops. + */ + ops = iort_fwspec_iommu_ops(dev->iommu_fwspec); + if (ops) + return ops; + + if (dev_is_pci(dev)) { + struct pci_bus *bus = to_pci_dev(dev)->bus; + struct iort_pci_alias_info info = { .dev = dev }; + + node = iort_scan_node(ACPI_IORT_NODE_PCI_ROOT_COMPLEX, + iort_match_node_callback, &bus->dev); + if (!node) + return NULL; + + info.node = node; + err = pci_for_each_dma_alias(to_pci_dev(dev), + iort_pci_iommu_init, &info); + } else { + int i = 0; + + node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT, + iort_match_node_callback, dev); + if (!node) + return NULL; + + do { + parent = iort_node_map_platform_id(node, &streamid, + IORT_IOMMU_TYPE, + i++); + + if (parent) + err = iort_iommu_xlate(dev, parent, streamid); + } while (parent && !err); + } + + /* + * If we have reason to believe the IOMMU driver missed the initial + * add_device callback for dev, replay it to get things in order. + */ + if (!err) { + ops = iort_fwspec_iommu_ops(dev->iommu_fwspec); + err = iort_add_device_replay(ops, dev); + } + + /* Ignore all other errors apart from EPROBE_DEFER */ + if (err == -EPROBE_DEFER) { + ops = ERR_PTR(err); + } else if (err) { + dev_dbg(dev, "Adding to IOMMU failed: %d\n", err); + ops = NULL; + } + + return ops; +} + +static void __init acpi_iort_register_irq(int hwirq, const char *name, + int trigger, + struct resource *res) +{ + int irq = acpi_register_gsi(NULL, hwirq, trigger, + ACPI_ACTIVE_HIGH); + + if (irq <= 0) { + pr_err("could not register gsi hwirq %d name [%s]\n", hwirq, + name); + return; + } + + res->start = irq; + res->end = irq; + res->flags = IORESOURCE_IRQ; + res->name = name; +} + +static int __init arm_smmu_v3_count_resources(struct acpi_iort_node *node) +{ + struct acpi_iort_smmu_v3 *smmu; + /* Always present mem resource */ + int num_res = 1; + + /* Retrieve SMMUv3 specific data */ + smmu = (struct acpi_iort_smmu_v3 *)node->node_data; + + if (smmu->event_gsiv) + num_res++; + + if (smmu->pri_gsiv) + num_res++; + + if (smmu->gerr_gsiv) + num_res++; + + if (smmu->sync_gsiv) + num_res++; + + return num_res; +} + +static bool arm_smmu_v3_is_combined_irq(struct acpi_iort_smmu_v3 *smmu) +{ + /* + * Cavium ThunderX2 implementation doesn't not support unique + * irq line. Use single irq line for all the SMMUv3 interrupts. + */ + if (smmu->model != ACPI_IORT_SMMU_V3_CAVIUM_CN99XX) + return false; + + /* + * ThunderX2 doesn't support MSIs from the SMMU, so we're checking + * SPI numbers here. + */ + return smmu->event_gsiv == smmu->pri_gsiv && + smmu->event_gsiv == smmu->gerr_gsiv && + smmu->event_gsiv == smmu->sync_gsiv; +} + +static unsigned long arm_smmu_v3_resource_size(struct acpi_iort_smmu_v3 *smmu) +{ + /* + * Override the size, for Cavium ThunderX2 implementation + * which doesn't support the page 1 SMMU register space. + */ + if (smmu->model == ACPI_IORT_SMMU_V3_CAVIUM_CN99XX) + return SZ_64K; + + return SZ_128K; +} + +static void __init arm_smmu_v3_init_resources(struct resource *res, + struct acpi_iort_node *node) +{ + struct acpi_iort_smmu_v3 *smmu; + int num_res = 0; + + /* Retrieve SMMUv3 specific data */ + smmu = (struct acpi_iort_smmu_v3 *)node->node_data; + + res[num_res].start = smmu->base_address; + res[num_res].end = smmu->base_address + + arm_smmu_v3_resource_size(smmu) - 1; + res[num_res].flags = IORESOURCE_MEM; + + num_res++; + if (arm_smmu_v3_is_combined_irq(smmu)) { + if (smmu->event_gsiv) + acpi_iort_register_irq(smmu->event_gsiv, "combined", + ACPI_EDGE_SENSITIVE, + &res[num_res++]); + } else { + + if (smmu->event_gsiv) + acpi_iort_register_irq(smmu->event_gsiv, "eventq", + ACPI_EDGE_SENSITIVE, + &res[num_res++]); + + if (smmu->pri_gsiv) + acpi_iort_register_irq(smmu->pri_gsiv, "priq", + ACPI_EDGE_SENSITIVE, + &res[num_res++]); + + if (smmu->gerr_gsiv) + acpi_iort_register_irq(smmu->gerr_gsiv, "gerror", + ACPI_EDGE_SENSITIVE, + &res[num_res++]); + + if (smmu->sync_gsiv) + acpi_iort_register_irq(smmu->sync_gsiv, "cmdq-sync", + ACPI_EDGE_SENSITIVE, + &res[num_res++]); + } +} + +static bool __init arm_smmu_v3_is_coherent(struct acpi_iort_node *node) +{ + struct acpi_iort_smmu_v3 *smmu; + + /* Retrieve SMMUv3 specific data */ + smmu = (struct acpi_iort_smmu_v3 *)node->node_data; + + return smmu->flags & ACPI_IORT_SMMU_V3_COHACC_OVERRIDE; +} + +#if defined(CONFIG_ACPI_NUMA) && defined(ACPI_IORT_SMMU_V3_PXM_VALID) +/* + * set numa proximity domain for smmuv3 device + */ +static void __init arm_smmu_v3_set_proximity(struct device *dev, + struct acpi_iort_node *node) +{ + struct acpi_iort_smmu_v3 *smmu; + + smmu = (struct acpi_iort_smmu_v3 *)node->node_data; + if (smmu->flags & ACPI_IORT_SMMU_V3_PXM_VALID) { + set_dev_node(dev, acpi_map_pxm_to_node(smmu->pxm)); + pr_info("SMMU-v3[%llx] Mapped to Proximity domain %d\n", + smmu->base_address, + smmu->pxm); + } +} +#else +#define arm_smmu_v3_set_proximity NULL +#endif + +static int __init arm_smmu_count_resources(struct acpi_iort_node *node) +{ + struct acpi_iort_smmu *smmu; + + /* Retrieve SMMU specific data */ + smmu = (struct acpi_iort_smmu *)node->node_data; + + /* + * Only consider the global fault interrupt and ignore the + * configuration access interrupt. + * + * MMIO address and global fault interrupt resources are always + * present so add them to the context interrupt count as a static + * value. + */ + return smmu->context_interrupt_count + 2; +} + +static void __init arm_smmu_init_resources(struct resource *res, + struct acpi_iort_node *node) +{ + struct acpi_iort_smmu *smmu; + int i, hw_irq, trigger, num_res = 0; + u64 *ctx_irq, *glb_irq; + + /* Retrieve SMMU specific data */ + smmu = (struct acpi_iort_smmu *)node->node_data; + + res[num_res].start = smmu->base_address; + res[num_res].end = smmu->base_address + smmu->span - 1; + res[num_res].flags = IORESOURCE_MEM; + num_res++; + + glb_irq = ACPI_ADD_PTR(u64, node, smmu->global_interrupt_offset); + /* Global IRQs */ + hw_irq = IORT_IRQ_MASK(glb_irq[0]); + trigger = IORT_IRQ_TRIGGER_MASK(glb_irq[0]); + + acpi_iort_register_irq(hw_irq, "arm-smmu-global", trigger, + &res[num_res++]); + + /* Context IRQs */ + ctx_irq = ACPI_ADD_PTR(u64, node, smmu->context_interrupt_offset); + for (i = 0; i < smmu->context_interrupt_count; i++) { + hw_irq = IORT_IRQ_MASK(ctx_irq[i]); + trigger = IORT_IRQ_TRIGGER_MASK(ctx_irq[i]); + + acpi_iort_register_irq(hw_irq, "arm-smmu-context", trigger, + &res[num_res++]); + } +} + +static bool __init arm_smmu_is_coherent(struct acpi_iort_node *node) +{ + struct acpi_iort_smmu *smmu; + + /* Retrieve SMMU specific data */ + smmu = (struct acpi_iort_smmu *)node->node_data; + + return smmu->flags & ACPI_IORT_SMMU_COHERENT_WALK; +} + +struct iort_iommu_config { + const char *name; + int (*iommu_init)(struct acpi_iort_node *node); + bool (*iommu_is_coherent)(struct acpi_iort_node *node); + int (*iommu_count_resources)(struct acpi_iort_node *node); + void (*iommu_init_resources)(struct resource *res, + struct acpi_iort_node *node); + void (*iommu_set_proximity)(struct device *dev, + struct acpi_iort_node *node); +}; + +static const struct iort_iommu_config iort_arm_smmu_v3_cfg __initconst = { + .name = "arm-smmu-v3", + .iommu_is_coherent = arm_smmu_v3_is_coherent, + .iommu_count_resources = arm_smmu_v3_count_resources, + .iommu_init_resources = arm_smmu_v3_init_resources, + .iommu_set_proximity = arm_smmu_v3_set_proximity, +}; + +static const struct iort_iommu_config iort_arm_smmu_cfg __initconst = { + .name = "arm-smmu", + .iommu_is_coherent = arm_smmu_is_coherent, + .iommu_count_resources = arm_smmu_count_resources, + .iommu_init_resources = arm_smmu_init_resources +}; + +static __init +const struct iort_iommu_config *iort_get_iommu_cfg(struct acpi_iort_node *node) +{ + switch (node->type) { + case ACPI_IORT_NODE_SMMU_V3: + return &iort_arm_smmu_v3_cfg; + case ACPI_IORT_NODE_SMMU: + return &iort_arm_smmu_cfg; + default: + return NULL; + } +} + +/** + * iort_add_smmu_platform_device() - Allocate a platform device for SMMU + * @node: Pointer to SMMU ACPI IORT node + * + * Returns: 0 on success, <0 failure + */ +static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node) +{ + struct fwnode_handle *fwnode; + struct platform_device *pdev; + struct resource *r; + enum dev_dma_attr attr; + int ret, count; + const struct iort_iommu_config *ops = iort_get_iommu_cfg(node); + + if (!ops) + return -ENODEV; + + pdev = platform_device_alloc(ops->name, PLATFORM_DEVID_AUTO); + if (!pdev) + return -ENOMEM; + + if (ops->iommu_set_proximity) + ops->iommu_set_proximity(&pdev->dev, node); + + count = ops->iommu_count_resources(node); + + r = kcalloc(count, sizeof(*r), GFP_KERNEL); + if (!r) { + ret = -ENOMEM; + goto dev_put; + } + + ops->iommu_init_resources(r, node); + + ret = platform_device_add_resources(pdev, r, count); + /* + * Resources are duplicated in platform_device_add_resources, + * free their allocated memory + */ + kfree(r); + + if (ret) + goto dev_put; + + /* + * Add a copy of IORT node pointer to platform_data to + * be used to retrieve IORT data information. + */ + ret = platform_device_add_data(pdev, &node, sizeof(node)); + if (ret) + goto dev_put; + + /* + * We expect the dma masks to be equivalent for + * all SMMUs set-ups + */ + pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; + + fwnode = iort_get_fwnode(node); + + if (!fwnode) { + ret = -ENODEV; + goto dev_put; + } + + pdev->dev.fwnode = fwnode; + + attr = ops->iommu_is_coherent(node) ? + DEV_DMA_COHERENT : DEV_DMA_NON_COHERENT; + + /* Configure DMA for the page table walker */ + acpi_dma_configure(&pdev->dev, attr); + + ret = platform_device_add(pdev); + if (ret) + goto dma_deconfigure; + + return 0; + +dma_deconfigure: + acpi_dma_deconfigure(&pdev->dev); +dev_put: + platform_device_put(pdev); + + return ret; +} + +static bool __init iort_enable_acs(struct acpi_iort_node *iort_node) +{ + if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) { + struct acpi_iort_node *parent; + struct acpi_iort_id_mapping *map; + int i; + + map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node, + iort_node->mapping_offset); + + for (i = 0; i < iort_node->mapping_count; i++, map++) { + if (!map->output_reference) + continue; + + parent = ACPI_ADD_PTR(struct acpi_iort_node, + iort_table, map->output_reference); + /* + * If we detect a RC->SMMU mapping, make sure + * we enable ACS on the system. + */ + if ((parent->type == ACPI_IORT_NODE_SMMU) || + (parent->type == ACPI_IORT_NODE_SMMU_V3)) { + pci_request_acs(); + return true; + } + } + } + + return false; +} + +static void __init iort_init_platform_devices(void) +{ + struct acpi_iort_node *iort_node, *iort_end; + struct acpi_table_iort *iort; + struct fwnode_handle *fwnode; + int i, ret; + bool acs_enabled = false; + + /* + * iort_table and iort both point to the start of IORT table, but + * have different struct types + */ + iort = (struct acpi_table_iort *)iort_table; + + /* Get the first IORT node */ + iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort, + iort->node_offset); + iort_end = ACPI_ADD_PTR(struct acpi_iort_node, iort, + iort_table->length); + + for (i = 0; i < iort->node_count; i++) { + if (iort_node >= iort_end) { + pr_err("iort node pointer overflows, bad table\n"); + return; + } + + if (!acs_enabled) + acs_enabled = iort_enable_acs(iort_node); + + if ((iort_node->type == ACPI_IORT_NODE_SMMU) || + (iort_node->type == ACPI_IORT_NODE_SMMU_V3)) { + + fwnode = acpi_alloc_fwnode_static(); + if (!fwnode) + return; + + iort_set_fwnode(iort_node, fwnode); + + ret = iort_add_smmu_platform_device(iort_node); + if (ret) { + iort_delete_fwnode(iort_node); + acpi_free_fwnode_static(fwnode); + return; + } + } + + iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort_node, + iort_node->length); + } +} + +void __init acpi_iort_init(void) +{ + acpi_status status; + + status = acpi_get_table(ACPI_SIG_IORT, 0, &iort_table); + if (ACPI_FAILURE(status)) { + if (status != AE_NOT_FOUND) { + const char *msg = acpi_format_exception(status); + + pr_err("Failed to get table, %s\n", msg); + } + + return; + } + + iort_init_platform_devices(); +} diff --git a/xen/include/acpi/acpi_iort.h b/xen/include/acpi/acpi_iort.h new file mode 100644 index 0000000000..8d3f0bf803 --- /dev/null +++ b/xen/include/acpi/acpi_iort.h @@ -0,0 +1,57 @@ +/* + * 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 __ACPI_IORT_H__ +#define __ACPI_IORT_H__ + +#include +#include +#include + +#define IORT_IRQ_MASK(irq) (irq & 0xffffffffULL) +#define IORT_IRQ_TRIGGER_MASK(irq) ((irq >> 32) & 0xffffffffULL) + +int iort_register_domain_token(int trans_id, struct fwnode_handle *fw_node); +void iort_deregister_domain_token(int trans_id); +struct fwnode_handle *iort_find_domain_token(int trans_id); +#ifdef CONFIG_ACPI_IORT +void acpi_iort_init(void); +u32 iort_msi_map_rid(struct device *dev, u32 req_id); +struct irq_domain *iort_get_device_domain(struct device *dev, u32 req_id); +void acpi_configure_pmsi_domain(struct device *dev); +int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id); +/* IOMMU interface */ +void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *size); +const struct iommu_ops *iort_iommu_configure(struct device *dev); +#else +static inline void acpi_iort_init(void) { } +static inline u32 iort_msi_map_rid(struct device *dev, u32 req_id) +{ return req_id; } +static inline struct irq_domain *iort_get_device_domain(struct device *dev, + u32 req_id) +{ return NULL; } +static inline void acpi_configure_pmsi_domain(struct device *dev) { } +/* IOMMU interface */ +static inline void iort_dma_setup(struct device *dev, u64 *dma_addr, + u64 *size) { } +static inline +const struct iommu_ops *iort_iommu_configure(struct device *dev) +{ return NULL; } +#endif + +#endif /* __ACPI_IORT_H__ */ From patchwork Tue Jan 2 09:28:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Jaggi X-Patchwork-Id: 123100 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8755034qgn; Tue, 2 Jan 2018 01:31:07 -0800 (PST) X-Google-Smtp-Source: ACJfBotWYsjJnhM3+5Xd30ZzghErlI9/GEgQNKxa2Mqs3uQHby2M6c7seZxzMc8iFp8o98aVP63i X-Received: by 10.107.30.71 with SMTP id e68mr2610973ioe.289.1514885467070; Tue, 02 Jan 2018 01:31:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514885467; cv=none; d=google.com; s=arc-20160816; b=GMaAXhnR8BdgVe3ty+6tzcWzej/J/nq1rj5eGoCgl2lPCQzu0gKathYr9iZFfIJ/VK nuDO8DA+f/eQDnEuiLZ1LlartxUIb3ME1y9qDjl0NVpFA9XH3ulUyb1ultNLVekGQ0lj w086uVlLFCPrR6PaxwUuyjECOWPhGXB4Zec+vqaAcAGKzoTYzSNHao55LfFTUmAQO5a0 bmznwZR8IhFR24mu7IK+ET3jWddPguNg1GW+dcKo3l591b0gPCKmQtK8u7Z0XoXwGUQT IYrjihPM86bIqTq4kAoko8cAT/cJTtD/543/cHGVubnkYvpejBphIuHC8rrj57boAj/h JbNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=aHK5IU92NSbUdvBunRgAQyppMjuwnm/tPVq5rF36Idc=; b=LKBDVsx2c4+MSy26Un8HC5R+W9qWzguSy0HqSj/qJn5wSoYdh2vCn5J5j4JyLT9iM0 tbj+iFbNR53lzEw+7ezGavLEh0UY6bEErz0wK4XHZ5n/t5tcJaJOZ6oMhyUmrCMQxSfR F09c9OEH5hl+t7xjL2suXRjXJspk0ej7rbP896jxdBGq2XSbKIaZVmE7V3NMC+V1Qn6/ qpRwrEtO2ZxBI05w1hbi6ypOHaP7nmVshIi+bQSoMb7jCAXk46/o0zIlyDdiAqp/giKK RGpJPg+Hr/DaZrt5hOMgZDsVvA1vlt4MuGCDsoxzeLQjHDKK0Hxn8AUt62jqdd7hqRbt olSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FamnA6su; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id h71si27759513ioi.177.2018.01.02.01.31.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:31:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FamnA6su; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsN-0002Wf-Ae; Tue, 02 Jan 2018 09:28:51 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsM-0002Vc-9R for xen-devel@lists.xenproject.org; Tue, 02 Jan 2018 09:28:50 +0000 X-Inumbo-ID: 2f334a1f-ef9f-11e7-b4a6-bc764e045a96 Received: from mail-pl0-x242.google.com (unknown [2607:f8b0:400e:c01::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2f334a1f-ef9f-11e7-b4a6-bc764e045a96; Tue, 02 Jan 2018 10:27:43 +0100 (CET) Received: by mail-pl0-x242.google.com with SMTP id n13so28332709plp.11 for ; Tue, 02 Jan 2018 01:28:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mz2B3yZ1mrabHer7L0f+I0SN726208c7ofzCW0c5FqE=; b=FamnA6suEVyYgl23KTv7fwyIyiUUfz5RJ94ViU+L16WvdU90THUt3jMCBVPN/ic0go IG8THSNLR/l3ymzHDs7DmloMn7Cn5pdhepEIuEcSiaucXzQbcwaArdRbKPi5UgxgarBo OyBabE6mzn6KybK16tCVbIJ0nImVm3zZfDBq8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mz2B3yZ1mrabHer7L0f+I0SN726208c7ofzCW0c5FqE=; b=DBjzxMn507FioOVd3kXdh52GNx4XpNp8yCwKArFygaaxahxdp4yWHkDtmtFpLGERu/ 15BCXzJX7Vrino0IpP99YybZECTGC5pwcFz80XuXVXjnWvJnqHXwUVNweHB1+LrzA9tZ Hahln1LXvFgc6/9LZxIM/YJWvXcH6MkgF/Tq+VtAay6YLNY1PHpI0Kg37hrv442tchUn uQRUSmSfdynrE4j8NPlQWM+WqJaXxZmcY6Oj2d3vFNhhswnPipjEMQA47o92HimoJNp8 MglwNqeOc6VzCbUqMogBWt04hcBHrCdS/I50cxhznJrGhCLgnXpe08JZevekYlHjAXJy 8JHw== X-Gm-Message-State: AKGB3mJWlO83gHoKY3bnqRfkRXE/E4DLq/M7UMf+tN7hXmi8n+LUHXYk IOn8PkCiPpzZRqtKGyUZyiYKXX6kh/U= X-Received: by 10.159.218.72 with SMTP id x8mr45678518plv.148.1514885328436; Tue, 02 Jan 2018 01:28:48 -0800 (PST) Received: from thunder-dev-box.domain.name ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id e8sm22065207pgs.44.2018.01.02.01.28.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:28:47 -0800 (PST) From: manish.jaggi@linaro.org To: xen-devel@lists.xenproject.org, julien.grall@linaro.org, sameer.goel@linaro.org, andre.przywara@linaro.org Date: Tue, 2 Jan 2018 14:58:03 +0530 Message-Id: <20180102092809.1841-6-manish.jaggi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180102092809.1841-1-manish.jaggi@linaro.org> References: <20180102092809.1841-1-manish.jaggi@linaro.org> Cc: Manish Jaggi , manish.jaggi@cavium.com Subject: [Xen-devel] [RFC 05/11] Import fwnode.h from linux X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Manish Jaggi Import fwnode.h from linux kernel tag v4.14 Signed-off-by: Manish Jaggi --- xen/include/xen/fwnode.h | 125 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/xen/include/xen/fwnode.h b/xen/include/xen/fwnode.h new file mode 100644 index 0000000000..af186a9dc6 --- /dev/null +++ b/xen/include/xen/fwnode.h @@ -0,0 +1,125 @@ +/* + * fwnode.h - Firmware device node object handle type definition. + * + * Copyright (C) 2015, Intel Corporation + * Author: Rafael J. Wysocki + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef _LINUX_FWNODE_H_ +#define _LINUX_FWNODE_H_ + +#include + +struct fwnode_operations; + +struct fwnode_handle { + struct fwnode_handle *secondary; + const struct fwnode_operations *ops; +}; + +/** + * struct fwnode_endpoint - Fwnode graph endpoint + * @port: Port number + * @id: Endpoint id + * @local_fwnode: reference to the related fwnode + */ +struct fwnode_endpoint { + unsigned int port; + unsigned int id; + const struct fwnode_handle *local_fwnode; +}; + +#define NR_FWNODE_REFERENCE_ARGS 8 + +/** + * struct fwnode_reference_args - Fwnode reference with additional arguments + * @fwnode:- A reference to the base fwnode + * @nargs: Number of elements in @args array + * @args: Integer arguments on the fwnode + */ +struct fwnode_reference_args { + struct fwnode_handle *fwnode; + unsigned int nargs; + unsigned int args[NR_FWNODE_REFERENCE_ARGS]; +}; + +/** + * struct fwnode_operations - Operations for fwnode interface + * @get: Get a reference to an fwnode. + * @put: Put a reference to an fwnode. + * @property_present: Return true if a property is present. + * @property_read_integer_array: Read an array of integer properties. Return + * zero on success, a negative error code + * otherwise. + * @property_read_string_array: Read an array of string properties. Return zero + * on success, a negative error code otherwise. + * @get_parent: Return the parent of an fwnode. + * @get_next_child_node: Return the next child node in an iteration. + * @get_named_child_node: Return a child node with a given name. + * @get_reference_args: Return a reference pointed to by a property, with args + * @graph_get_next_endpoint: Return an endpoint node in an iteration. + * @graph_get_remote_endpoint: Return the remote endpoint node of a local + * endpoint node. + * @graph_get_port_parent: Return the parent node of a port node. + * @graph_parse_endpoint: Parse endpoint for port and endpoint id. + */ +struct fwnode_operations { + void (*get)(struct fwnode_handle *fwnode); + void (*put)(struct fwnode_handle *fwnode); + bool (*device_is_available)(const struct fwnode_handle *fwnode); + bool (*property_present)(const struct fwnode_handle *fwnode, + const char *propname); + int (*property_read_int_array)(const struct fwnode_handle *fwnode, + const char *propname, + unsigned int elem_size, void *val, + size_t nval); + int + (*property_read_string_array)(const struct fwnode_handle *fwnode_handle, + const char *propname, const char **val, + size_t nval); + struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode); + struct fwnode_handle * + (*get_next_child_node)(const struct fwnode_handle *fwnode, + struct fwnode_handle *child); + struct fwnode_handle * + (*get_named_child_node)(const struct fwnode_handle *fwnode, + const char *name); + int (*get_reference_args)(const struct fwnode_handle *fwnode, + const char *prop, const char *nargs_prop, + unsigned int nargs, unsigned int index, + struct fwnode_reference_args *args); + struct fwnode_handle * + (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode, + struct fwnode_handle *prev); + struct fwnode_handle * + (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode); + struct fwnode_handle * + (*graph_get_port_parent)(struct fwnode_handle *fwnode); + int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode, + struct fwnode_endpoint *endpoint); +}; + +#define fwnode_has_op(fwnode, op) \ + ((fwnode) && (fwnode)->ops && (fwnode)->ops->op) +#define fwnode_call_int_op(fwnode, op, ...) \ + (fwnode ? (fwnode_has_op(fwnode, op) ? \ + (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \ + -EINVAL) +#define fwnode_call_bool_op(fwnode, op, ...) \ + (fwnode ? (fwnode_has_op(fwnode, op) ? \ + (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false) : \ + false) +#define fwnode_call_ptr_op(fwnode, op, ...) \ + (fwnode_has_op(fwnode, op) ? \ + (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL) +#define fwnode_call_void_op(fwnode, op, ...) \ + do { \ + if (fwnode_has_op(fwnode, op)) \ + (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \ + } while (false) + +#endif From patchwork Tue Jan 2 09:28:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Jaggi X-Patchwork-Id: 123102 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8755112qgn; Tue, 2 Jan 2018 01:31:13 -0800 (PST) X-Google-Smtp-Source: ACJfBouWH/kpujcrJB8dAyk+nyXlCAZRn2Yruz7Xp8wESn+G/gleoWf7RpzFl1m/KuHkQoCPOqBK X-Received: by 10.36.204.85 with SMTP id x82mr56991496itf.95.1514885473752; Tue, 02 Jan 2018 01:31:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514885473; cv=none; d=google.com; s=arc-20160816; b=b+UGjigZjXuHh4keK2cFG5AuriwGxORDyahBW1VBy1NOFgC4oMgiz0ZyLwTGKZDAu3 xSm4bUeQ//p11JHmAgpuW7UBC/5FBDS3tCOD1yaC3CrxK+muB2/HP4tsMV96mmqehbc2 26JYJmj7qz4fvOKBlfSrYTAD6GuXb5NtBt9xXRfwcx0Mxg+fFOb7/bOS27aIH1rU1NjO urGIFfLUo5+m066n+UN0OR16hPevL05Y4YWqka3Ce0FvuuXb7mUpsJG1gTeMco8mOqJc +DKm4C8PjmZ0D3WKmqoAK+KP2noyLKbdpOAp+OH6o18iRGN40G7GIkWsjjhEV5XWCjUY OY3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=F3ppg/2NpeDgiigi9Nn3pNqjcXvptg1LowVouPP88M4=; b=ZLSGsZ0r3tu+XHUllWF1ZspK5+gJU6v6ky91hZhLLCxe/T6OGb67nZjJqUcViY58PC Bz8+TdM74NvKD0160VtAGCITMAiAEDj/DN2wJS3T+3969l/kp9lf6tukXhVOMJoxcpnu 96assHiEWCWV4moHLczwvqxvQ8+L/dtaCwLg1CXxqbVLwGXcBFsIk46tpHZBfpnHbnVx ops6D8sSBhsmYh+eqelO10QhOr8MR90JzQWfR3Ja7BVkI8MBWUGN3XnQn7uUIK8DN52k DXvD+3BOUzP++PvgPt74KYRwZ3t4FYYS6PiSA4IoxpBCEC8mlfrXX7xUpe94/FjoKZaj sNaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=D7kISlrg; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id d12si13309311iob.58.2018.01.02.01.31.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:31:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=D7kISlrg; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsR-0002ZR-HC; Tue, 02 Jan 2018 09:28:55 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsQ-0002Yj-2g for xen-devel@lists.xenproject.org; Tue, 02 Jan 2018 09:28:54 +0000 X-Inumbo-ID: 31480fd7-ef9f-11e7-b4a6-bc764e045a96 Received: from mail-pl0-x244.google.com (unknown [2607:f8b0:400e:c01::244]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 31480fd7-ef9f-11e7-b4a6-bc764e045a96; Tue, 02 Jan 2018 10:27:46 +0100 (CET) Received: by mail-pl0-x244.google.com with SMTP id d21so28337428pll.1 for ; Tue, 02 Jan 2018 01:28:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=e46ZA+vudQcYWtehhJpe9tH+mRvYgBkITiwOt+Mgcjo=; b=D7kISlrgE3nPFoAwY7FFCxrE/WniPhjk8F5dcdisXZMOtDK286+7TIhOLqtjrqR3U0 21OcCgUrETLqVusWhXJ4OFBk5gl6Ejpn8KrbkieTzpvJKHSABuJsOKe+CSqqFR24Thji VP6KSLLMv5vFvZsRwrrnZ9IKeF6UAss8ZeV7k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=e46ZA+vudQcYWtehhJpe9tH+mRvYgBkITiwOt+Mgcjo=; b=LbEMYJfCCGb69y8w+autvy7RbVSvwnS7avDd9porAKRPPIiWt5btq8ojdXQt1VYGsW l1Qf8o5eRgXn94Kj3dWj4EMliRqvaeJPmIFnnrx4+v93oyA7YMcxewy8G+XT5TF+ZjJC JdzHmRnXANMibJUzPVzlPNkZsx34IfJH9jBleFhInz5Z0r4v5NbcIndimVbJVXYflf10 HUKPqgDiUfZFZiEP1PxAu1s5hcqVYnPp8lDNuwK8wpl+HKKcbtVDWn14qWfcQ/F8AHff Fb2PK46RjCEdqLDfTol0UtDDwxQyMWx4V4C0xXoLOjL2glWeXhQu37n7w9xZA6KJ+Oem 8/AQ== X-Gm-Message-State: AKGB3mI+SurVL0vIL8oV6F7jwKjrnBOEIcc/t5DK07S+FLwrKFFcL2nu Veflxee/S2FEJ1mdjCgneUoFdWEerPA= X-Received: by 10.84.173.1 with SMTP id o1mr45691220plb.135.1514885331945; Tue, 02 Jan 2018 01:28:51 -0800 (PST) Received: from thunder-dev-box.domain.name ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id e8sm22065207pgs.44.2018.01.02.01.28.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:28:51 -0800 (PST) From: manish.jaggi@linaro.org To: xen-devel@lists.xenproject.org, julien.grall@linaro.org, sameer.goel@linaro.org, andre.przywara@linaro.org Date: Tue, 2 Jan 2018 14:58:04 +0530 Message-Id: <20180102092809.1841-7-manish.jaggi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180102092809.1841-1-manish.jaggi@linaro.org> References: <20180102092809.1841-1-manish.jaggi@linaro.org> Cc: Manish Jaggi , manish.jaggi@cavium.com Subject: [Xen-devel] [RFC 06/11] fwnode xen spacific changes X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Manish Jaggi Merge few more changes from linux kernel code (v4.14) into iommu.c Modify code specifc to xen. Signed-off-by: Manish Jaggi --- xen/drivers/passthrough/iommu.c | 75 +++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/device.h | 11 ++++-- xen/include/xen/iommu.h | 22 ++++++++++++ 3 files changed, 106 insertions(+), 2 deletions(-) diff --git a/xen/drivers/passthrough/iommu.c b/xen/drivers/passthrough/iommu.c index 1aecf7cf34..408f44106d 100644 --- a/xen/drivers/passthrough/iommu.c +++ b/xen/drivers/passthrough/iommu.c @@ -13,6 +13,7 @@ */ #include +#include #include #include #include @@ -507,6 +508,80 @@ static void iommu_dump_p2m_table(unsigned char key) } } +/** + * fwnode_handle_put - Drop reference to a device node + * @fwnode: Pointer to the device node to drop the reference to. + * + * This has to be used when terminating device_for_each_child_node() iteration + * with break or return to prevent stale device node references from being left + * behind. + */ +void fwnode_handle_put(struct fwnode_handle *fwnode) +{ + fwnode_call_void_op(fwnode, put); +} + +const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode) +{ + return iommu_get_ops(); +} + +int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, + const struct iommu_ops *ops) +{ + struct iommu_fwspec *fwspec = dev->iommu_fwspec; + + if (fwspec) + return ops == fwspec->ops ? 0 : -EINVAL; + + fwspec = kzalloc(sizeof(*fwspec), GFP_KERNEL); + if (!fwspec) + return -ENOMEM; +#if 0 + of_node_get(to_of_node(iommu_fwnode)); +#endif + fwspec->iommu_fwnode = iommu_fwnode; + fwspec->ops = ops; + dev->iommu_fwspec = fwspec; + return 0; +} + +void iommu_fwspec_free(struct device *dev) +{ + struct iommu_fwspec *fwspec = dev->iommu_fwspec; + + if (fwspec) { + fwnode_handle_put(fwspec->iommu_fwnode); + kfree(fwspec); + dev->iommu_fwspec = NULL; + } +} + +int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids) +{ + struct iommu_fwspec *fwspec = dev->iommu_fwspec; + size_t size; + int i; + + if (!fwspec) + return -EINVAL; + + size = offsetof(struct iommu_fwspec, ids[fwspec->num_ids + num_ids]); + if (size > sizeof(*fwspec)) { + //TBD: fwspec = krealloc(dev->iommu_fwspec, size, GFP_KERNEL); + if (!fwspec) + return -ENOMEM; + + dev->iommu_fwspec = fwspec; + } + + for (i = 0; i < num_ids; i++) + fwspec->ids[fwspec->num_ids + i] = ids[i]; + + fwspec->num_ids += num_ids; + return 0; + +} /* * Local variables: * mode: C diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h index 6734ae8efd..f78482ca0c 100644 --- a/xen/include/asm-arm/device.h +++ b/xen/include/asm-arm/device.h @@ -6,6 +6,8 @@ enum device_type { DEV_DT, + DEV_ACPI, + DEV_PCI, }; struct dev_archdata { @@ -18,8 +20,13 @@ struct device enum device_type type; #ifdef CONFIG_HAS_DEVICE_TREE struct dt_device_node *of_node; /* Used by drivers imported from Linux */ +#endif +#ifdef CONFIG_ACPI + void *acpi_node; #endif struct dev_archdata archdata; + struct fwnode_handle *fwnode; /* firmware device node */ + struct iommu_fwspec *iommu_fwspec; }; typedef struct device device_t; @@ -27,8 +34,8 @@ typedef struct device device_t; #include /* TODO: Correctly implement dev_is_pci when PCI is supported on ARM */ -#define dev_is_pci(dev) ((void)(dev), 0) -#define dev_is_dt(dev) ((dev->type == DEV_DT) +#define dev_is_pci(dev) (dev->type == DEV_PCI) +#define dev_is_dt(dev) (dev->type == DEV_DT) enum device_class { diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 33c8b221dc..56b169bae9 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -208,4 +208,26 @@ DECLARE_PER_CPU(bool_t, iommu_dont_flush_iotlb); extern struct spinlock iommu_pt_cleanup_lock; extern struct page_list_head iommu_pt_cleanup_list; +/** + * struct iommu_fwspec - per-device IOMMU instance data + * @ops: ops for this device's IOMMU + * @iommu_fwnode: firmware handle for this device's IOMMU + * @iommu_priv: IOMMU driver private data for this device + * @num_ids: number of associated device IDs + * @ids: IDs which this device may present to the IOMMU + */ +struct iommu_fwspec { + const struct iommu_ops *ops; + struct fwnode_handle *iommu_fwnode; + void *iommu_priv; + unsigned int num_ids; + u32 ids[1]; +}; + +int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, + const struct iommu_ops *ops); +void iommu_fwspec_free(struct device *dev); +int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids); +const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode); + #endif /* _IOMMU_H_ */ From patchwork Tue Jan 2 09:28:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Jaggi X-Patchwork-Id: 123098 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8755000qgn; Tue, 2 Jan 2018 01:31:04 -0800 (PST) X-Google-Smtp-Source: ACJfBoufXk4+EHdE4aoETzjei4FF2MG2+BgcLvh7j2vB4/nkMJHghpN/1/ZHpHKaBwaihI88Wq4M X-Received: by 10.107.41.79 with SMTP id p76mr13813471iop.105.1514885464509; Tue, 02 Jan 2018 01:31:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514885464; cv=none; d=google.com; s=arc-20160816; b=0DUD2BFmJLficHrFIFL4pnjtTrJ0NnIr2N+Zcl+1222gOcrid0yD7N32LLNVuxsdkg cTl6EALC+zvbvWA7fBhoov8J98vwCEeY/3hWnKd8y/Ya3Bvh6LLJ3i03Aj0fiv+gN3u2 qkyTmVFFDlncS+uo2vFtOMrB9DyBD+MXegWgvW7+P/V/+UpUJA2C9hhHL5aAdthZ6Ay2 vvFkJnQY3au7pfzZCE/eGJaPyFgmx340ZE+ZbkmTopD8D3zDUvT4aZdX5p8jdEF0DreR XK6IJOeBvLN5n90bqCLL+8v4tYlolz2cMIZvMd67nmH6+vW1qFfi9ckz2TTF38+cPKHy M/kA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=UyIXnEnpXw8MaY3SmN97MKXDzm3hdUHgj7/kme/V70g=; b=sHWkyGJlVK/MabrX9/EyVou/oCPNHJf3kDOLCkdyR7WquTQ2FvSV+UvTwOB5VGAzOl ISC17fK52vX0xRWVJNNeTbxRJ7UiduZ6+aG0mNUG/TEmY2r4w1KxlVNCHhB0JxIJ1Jzd /rBp28UQtk8aQaDOb+a7lF7t/A5d4pcs8oFPUlHP7vAb0LF7TdX+5ks4RrAy5pDXawNJ rdh9LJ1Lsok5AYmqwwNvWvb3fDx5/Ppj7sxSYi46m5wo5g1NfXhd2McrFGOqNGRgeU9E 1Rcj6HvD+srKsyXhOqh8H6NZrKF0GMeHyt25RJLO5t5a86n++LT7GuUMbKLjig9YDAxl 1f9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=eB+34UR/; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id e71si24257742itd.171.2018.01.02.01.31.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:31:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=eB+34UR/; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsT-0002b9-Ow; Tue, 02 Jan 2018 09:28:57 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsT-0002ac-8z for xen-devel@lists.xenproject.org; Tue, 02 Jan 2018 09:28:57 +0000 X-Inumbo-ID: 338dfef4-ef9f-11e7-b4a6-bc764e045a96 Received: from mail-pl0-x244.google.com (unknown [2607:f8b0:400e:c01::244]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 338dfef4-ef9f-11e7-b4a6-bc764e045a96; Tue, 02 Jan 2018 10:27:50 +0100 (CET) Received: by mail-pl0-x244.google.com with SMTP id i6so28325668plt.13 for ; Tue, 02 Jan 2018 01:28:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Q3HQQpfZ3loVAOuusmrggKv5ilXvgOHkTSK8yB5usZo=; b=eB+34UR/V6lVHd4fibE07btcbT7YDDBaWzV143ASAgW0ha6lhWIfIIkguqhTWxeffl uruqhWT2EBLeevtVW3KnYFsKOri5TAxzXatr9UPlbnXaK4DN2F7orzXvUlTCRXBr4erL alSAKscli/1jz0VLPAXyR6u3l7v8WJILUS/xs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Q3HQQpfZ3loVAOuusmrggKv5ilXvgOHkTSK8yB5usZo=; b=hfYIn6Pk3LEWkwA5iJ9J0Q9HnL0wje9M3KHTIWBDVU5I2O210F52QdsT21wvlg3/nJ f1jgocPVcg89e1/KaBF8wa2NpoqHW3GNQWkXuIfqh7H7PQYQuaEna3FG7nCmfAuc2IHu WUMqsi+6gA96g0a5ptW8iqt+9I50cAt4tcc4NhcVqPT0smMhIqXLFns+uSK7Qf1BlfZp L8Ktp1mKuZVbWdp3qHcyO8UQ8I4Z4lUffawnZ4nFLx6lapcCeavbwBJeUaV9ErKaWn4/ Wcv3BdjkospDyz/vsh27DS569kaqKR7uFm5DMazCajQmLqMgQUPL4LxlpiKMKbMjGlIi Ymyg== X-Gm-Message-State: AKGB3mLGzDTHjMyfh185Fg8qz/2hVIuX8cL7gerO6nACrwj8Xd64ci5Y fd5lLgJ99umAFftbWktTR5tewFw0HiI= X-Received: by 10.84.218.8 with SMTP id q8mr43770031pli.117.1514885335816; Tue, 02 Jan 2018 01:28:55 -0800 (PST) Received: from thunder-dev-box.domain.name ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id e8sm22065207pgs.44.2018.01.02.01.28.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:28:55 -0800 (PST) From: manish.jaggi@linaro.org To: xen-devel@lists.xenproject.org, julien.grall@linaro.org, sameer.goel@linaro.org, andre.przywara@linaro.org Date: Tue, 2 Jan 2018 14:58:05 +0530 Message-Id: <20180102092809.1841-8-manish.jaggi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180102092809.1841-1-manish.jaggi@linaro.org> References: <20180102092809.1841-1-manish.jaggi@linaro.org> Cc: Manish Jaggi , manish.jaggi@cavium.com Subject: [Xen-devel] [RFC 07/11] Add kernel helper functions X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Manish Jaggi Add kalloc kfree functions from linux kernel. Signed-off-by: Manish Jaggi --- xen/include/xen/kernel.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xen/include/xen/kernel.h b/xen/include/xen/kernel.h index 548b64da9f..78517f6caa 100644 --- a/xen/include/xen/kernel.h +++ b/xen/include/xen/kernel.h @@ -7,6 +7,16 @@ #include +/* Xen: Define compatibility functions */ +#define FW_BUG "[Firmware Bug]: " +#define pr_err(fmt, ...) printk(XENLOG_ERR fmt, ## __VA_ARGS__) +#define pr_warn(fmt, ...) printk(XENLOG_WARNING fmt, ## __VA_ARGS__) + +/* Alias to Xen allocation helpers */ +#define kfree xfree +#define kmalloc(size, flags) _xmalloc(size, sizeof(void *)) +#define kzalloc(size, flags) _xzalloc(size, sizeof(void *)) + /* * min()/max() macros that also do * strict type-checking.. See the From patchwork Tue Jan 2 09:28:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Jaggi X-Patchwork-Id: 123101 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8755083qgn; Tue, 2 Jan 2018 01:31:11 -0800 (PST) X-Google-Smtp-Source: ACJfBovr2/sbdEYTjyhprBu6850g4MFaqqwKhDhm2oo2XgYh2ktm98b8hesPwvdkTwgvU7uLLTgc X-Received: by 10.107.8.139 with SMTP id h11mr47375189ioi.214.1514885471329; Tue, 02 Jan 2018 01:31:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514885471; cv=none; d=google.com; s=arc-20160816; b=DTqI9hqobe0+dT00Kjq8bu5tLyAh39zVaXeKSdvaoE7d4yu+3vUJpyW7ztl7lfVB2N GlD4Vg9YC6b/PWK4yY0v4peWpjFGcdZL72tZxrLe0FOEgTzYgzuYw+IwdbknNdwJ95cW lfzcYEjkw/ivp5n6Lmxif5hTdUbI+mQUTWIdLtufOgL+MlnljxsoGo6sg49i9Uxbbrti OzyB+rz04GlSpDngFX6L7HcF2nh8VFeU33RIxwfRduve9jfUDSx6jTMaeDJI4lON/Y/o xkNAKIQyvZu6vrZEyBqQUYt1qyJlP2ACeYsv2j78ghmWdnQwkIEpBlhzMEPP9UhDBgYj 8nRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=KCsiSmkBos28SUGogrPX1eOgYe5IgoOW55+AKRiUKJU=; b=ZFmG1BvintgSwqc4iFaMhWA5TWB/NVyh/VY9BUMvqM70j/2Jy2SYBfN1OJ+YzhMzRW pIKz6sSdInOsOuLBPo+0X3T3c7c4TURtXZE2q5T4f5MXzQkkTVqygn7pupdG9AuqTo78 Oios8wXIUGLCExJlk3p/MGAD/5EoiQJC8jUOxLFVlbH6kRo3simpPRr8gazZKB4Pu44x dWwqkezYu7OMq7oF1U+fUYQ6S+cDuxKQA3F+bGCMLvG4NwdyRsjTkyOkIIQQV4IanM66 CWUXWwtoy8Q+Ap/J7k8VN1UUhgBBrAjN1mEfvZdBraP+aJIH8VH6A3PuiEiqqPPPut55 Pyjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Xb3kucGP; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id p67si33644129iof.273.2018.01.02.01.31.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:31:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Xb3kucGP; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsZ-0002fU-Ve; Tue, 02 Jan 2018 09:29:03 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsY-0002eN-Kd for xen-devel@lists.xenproject.org; Tue, 02 Jan 2018 09:29:02 +0000 X-Inumbo-ID: 361ab26c-ef9f-11e7-b4a6-bc764e045a96 Received: from mail-pg0-x241.google.com (unknown [2607:f8b0:400e:c05::241]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 361ab26c-ef9f-11e7-b4a6-bc764e045a96; Tue, 02 Jan 2018 10:27:54 +0100 (CET) Received: by mail-pg0-x241.google.com with SMTP id b70so804573pga.2 for ; Tue, 02 Jan 2018 01:29:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4Et/pvdjCBRO2xLVoBNp7lUUTjeGk+qbmQDaSCKwhNk=; b=Xb3kucGPKfcG2IK2o4kTIJVX1nhOwxdV6Gtq4F7iUWwXtKoEOHCoZKCcMs1jzn3FJd 1q7Nac5aXA4P0pOZEzYryrOIp8rrno5bdzyGFudyHbDtpn8B/LNBiEk9jvx7D43j0rDa d+O9J/tF5jY5axzmB0MifchTnIJuQa8U2XKyY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4Et/pvdjCBRO2xLVoBNp7lUUTjeGk+qbmQDaSCKwhNk=; b=L0VQclefpsyr2ZbUaDYW/HpyFzxKrwZ2VUqOdZ2FBvegHNxv1W85F/t76F3DJhhQC5 VyWutd2fcL70/Kzf4mXTSRB6VSB+YWmxyyIIDZ/YOrNRlh1IZ1Agrmoy/IpFvLKPhaqo RKL05AzM3dKjVaxt8nPSWl5gTLeoGTcxTptFe/+4UfyX6lEIdtqx07L1kOvgw6vI8Yw5 qj4Q4K2pXYpDwhPoEbNiRzqUBvp8DuVrjLv7fMvxF1iHQnLB0Axs1KTKJHvpqtXjioEc sJVBHn02O5CooahqOoJaJtqMwyXeGyaxgM4bhLZedMairPlMOrmRNnBYWjgR3JDcQoNF MBYg== X-Gm-Message-State: AKGB3mL5enWEyO0AYFE6qtr2UnxaHZ+ywJS3dSfUd3q6j/d7sTIOMbRC hAkTh2Y9BvF8SfOJVDvlUMOueDjwB+Y= X-Received: by 10.98.196.155 with SMTP id h27mr44649271pfk.137.1514885340101; Tue, 02 Jan 2018 01:29:00 -0800 (PST) Received: from thunder-dev-box.domain.name ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id e8sm22065207pgs.44.2018.01.02.01.28.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:28:59 -0800 (PST) From: manish.jaggi@linaro.org To: xen-devel@lists.xenproject.org, julien.grall@linaro.org, sameer.goel@linaro.org, andre.przywara@linaro.org Date: Tue, 2 Jan 2018 14:58:06 +0530 Message-Id: <20180102092809.1841-9-manish.jaggi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180102092809.1841-1-manish.jaggi@linaro.org> References: <20180102092809.1841-1-manish.jaggi@linaro.org> Cc: Manish Jaggi , manish.jaggi@cavium.com Subject: [Xen-devel] [RFC 08/11] Add ACPI_IORT config X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Manish Jaggi Add ACPI_IORT config Singed-off-by: Manish Jaggi --- xen/arch/arm/Kconfig | 5 +++++ xen/drivers/acpi/Kconfig | 3 +++ 2 files changed, 8 insertions(+) diff --git a/xen/arch/arm/Kconfig b/xen/arch/arm/Kconfig index f58019d6ed..d4767d6ea3 100644 --- a/xen/arch/arm/Kconfig +++ b/xen/arch/arm/Kconfig @@ -42,6 +42,11 @@ config ACPI Advanced Configuration and Power Interface (ACPI) support for Xen is an alternative to device tree on ARM64. +config ACPI_IORT + bool + prompt "ACPI IORT Support" if EXPERT = "y" + depends on ACPI + config HAS_GICV3 bool diff --git a/xen/drivers/acpi/Kconfig b/xen/drivers/acpi/Kconfig index b64d3731fb..15ae98140c 100644 --- a/xen/drivers/acpi/Kconfig +++ b/xen/drivers/acpi/Kconfig @@ -5,5 +5,8 @@ config ACPI config ACPI_LEGACY_TABLES_LOOKUP bool +config ACPI_IORT + bool + config NUMA bool From patchwork Tue Jan 2 09:28:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Jaggi X-Patchwork-Id: 123106 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8755256qgn; Tue, 2 Jan 2018 01:31:24 -0800 (PST) X-Google-Smtp-Source: ACJfBovsUCi97sJuY3p8XRZN8xA7sD98eJ1TkmIXQu9fxVAwGvF6fUa1N6cyCD7qJgJcC0KBNxZt X-Received: by 10.36.181.80 with SMTP id j16mr62437458iti.118.1514885484479; Tue, 02 Jan 2018 01:31:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514885484; cv=none; d=google.com; s=arc-20160816; b=LcI7Wjpm7MlbsZOmojLnGCH6IdYK3Ya8sIe7R+S1ANaXM7h8DBqGNOdn6GCT3WOiKS 8gYQIDqBMFh4w5IngKu238RhPO9PU5vL9U1uLYn6ouV/myoMjemP6MmQhunYnu1x2qv5 zpeuM4lEQLLr+DlDSffozSmV46aVBAtbcPj8XYLCEFj52k3GTxlCdWGv5OcwJj8kgGZ3 L2gYAbILGD2jMVRGMDM//UZdvMZYktrlyO7Bs6vBycxlvgut+Vu2nvWCPIXh2/ka6aE4 G9vm3upO+UOZwDuibvCtF3ea1nZsO1K2EtELkk2pbUifBtGIcEkfnBjQgipTxqiVNu2h VBJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=c5sYUIYIkAYoel/3EAll1O/fw5psnKmlh32kxkLDcFE=; b=F1mVAWaApPVdE93q45TmdCnvTu4vALbqfjC3cF/7V5i6q7dV6BQRFngZ5L2CbD229f Xj9TFsX/fcY9f7B7ApJcGB51fJgVe3bfnOLlRhG+4gJy72O6EqvxYyUbw+N8QPoGNZM9 3BswVubOMzwStx8RKuST/B1el5mt9Ew8xFnMd0tkTCR+QsZQOel7y3bWu30cllfX7KL3 pm6+KLcBZbMpxbMLny0nurU27e048Ha2ax+uctkbyJKoKtPqmYGWqRmx1eyV6/UY2bSk bIUD/KlS5jtdRCaYlCjXygD07cWrN9n5JP584SHM+gFXD+0D+tMyFnmnrG5S32Ueml43 7Y9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Psoq9fL1; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id n133si32156749ion.184.2018.01.02.01.31.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:31:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Psoq9fL1; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsh-0002kF-6o; Tue, 02 Jan 2018 09:29:11 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsf-0002j5-RB for xen-devel@lists.xenproject.org; Tue, 02 Jan 2018 09:29:09 +0000 X-Inumbo-ID: 39ff2a60-ef9f-11e7-b4a6-bc764e045a96 Received: from mail-pf0-x242.google.com (unknown [2607:f8b0:400e:c00::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 39ff2a60-ef9f-11e7-b4a6-bc764e045a96; Tue, 02 Jan 2018 10:28:01 +0100 (CET) Received: by mail-pf0-x242.google.com with SMTP id c204so25456274pfc.13 for ; Tue, 02 Jan 2018 01:29:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TwF0K76wB/0gWjB5RzjzMAe8rJHiAHdrvjW3pSh8Ctg=; b=Psoq9fL1ZsZD67KCZxxmSuy3Picd4DuQPkirQo2IJzSdvomBHwqedmJjOxtLYueiZP 2j/Acx+PUrOYvaeZqOEHoTtymRUSgGZiBvTfmloQdL+UaeQi4MlMlf9I7fh5rzDY2/TX biTPVpoMBLFGLAVwrM7D9/I72rgh0UXYnxkXQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TwF0K76wB/0gWjB5RzjzMAe8rJHiAHdrvjW3pSh8Ctg=; b=gWHd6nC+8AYYlU6/EYCa1ttsiFrGtxKDP1sm3zV5nrXRdjiFw3rtuT11ICRfEZYB/E 1Q9uejlsA2E5aoBgefvqJKawXKhsQ5uil3daP7Aab+24dFHUfLqWRZgNRSxeufwgrXo8 R2IGlGRvYyNd0TU7MGF4Fl94ppncVOAX7+Ir3J+xbgMbu3sIV8yn4gwKEYDgvPOWAHZO e2bbN/tBP/Ndy0nrgi3vd8TqMnNo08APUfqnwGw94fSq3QP/emhD7yudZs/UoSXm8kOb 7TbSvCiaHb1KvwTUmH5VamKZ3sm1W/ohrWiPr8e4NbPB04iCHkz1yPkIK1DEfiIoK9RI Y/Hg== X-Gm-Message-State: AKGB3mL548K9JLWBxkDAAPROH7d0t7SSQpVEP0Yo2pxYSQS94fULnCFh HFRuV8F0XYXpNnG+i6yGuut81srcNDs= X-Received: by 10.98.137.201 with SMTP id n70mr44311586pfk.93.1514885346106; Tue, 02 Jan 2018 01:29:06 -0800 (PST) Received: from thunder-dev-box.domain.name ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id e8sm22065207pgs.44.2018.01.02.01.29.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:29:05 -0800 (PST) From: manish.jaggi@linaro.org To: xen-devel@lists.xenproject.org, julien.grall@linaro.org, sameer.goel@linaro.org, andre.przywara@linaro.org Date: Tue, 2 Jan 2018 14:58:07 +0530 Message-Id: <20180102092809.1841-10-manish.jaggi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180102092809.1841-1-manish.jaggi@linaro.org> References: <20180102092809.1841-1-manish.jaggi@linaro.org> Cc: Manish Jaggi , manish.jaggi@cavium.com Subject: [Xen-devel] [RFC 09/11] Xen IORT Changes X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Manish Jaggi This patch adds xen specific changes to iort.c Signed-off-by: Manish Jaggi --- xen/arch/arm/setup.c | 2 + xen/drivers/acpi/arm/Makefile | 1 + xen/drivers/acpi/arm/iort.c | 1040 +++-------------------------------------- xen/include/acpi/acpi_iort.h | 6 +- 4 files changed, 71 insertions(+), 978 deletions(-) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 16a3b1be8e..7ada48920f 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -800,6 +801,7 @@ void __init start_xen(unsigned long boot_phys_offset, tasklet_subsys_init(); + acpi_iort_init(); xsm_dt_init(); diff --git a/xen/drivers/acpi/arm/Makefile b/xen/drivers/acpi/arm/Makefile index 13f1a9159f..5d16161016 100644 --- a/xen/drivers/acpi/arm/Makefile +++ b/xen/drivers/acpi/arm/Makefile @@ -1,2 +1,3 @@ obj-y = ridmap.o obj-y += gen-iort.o +obj-y += iort.o diff --git a/xen/drivers/acpi/arm/iort.c b/xen/drivers/acpi/arm/iort.c index de56394dd1..a47ee2df4c 100644 --- a/xen/drivers/acpi/arm/iort.c +++ b/xen/drivers/acpi/arm/iort.c @@ -14,17 +14,20 @@ * 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 + * + * Imported from Linux 4.14.0 + * Xen Modifications : Manish Jaggi */ #define pr_fmt(fmt) "ACPI: IORT: " fmt -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #define IORT_TYPE_MASK(type) (1 << (type)) #define IORT_MSI_TYPE (1 << ACPI_IORT_NODE_ITS_GROUP) @@ -36,6 +39,22 @@ #define ACPI_IORT_SMMU_V3_CAVIUM_CN99XX 0x2 #endif +/* Redefine WARN macros */ +#undef WARN +#undef WARN_ON +#define WARN(condition, format...) ({ \ + int __ret_warn_on = !!(condition); \ + if (unlikely(__ret_warn_on)) \ + printk(format); \ + unlikely(__ret_warn_on); \ +}) +#define WARN_TAINT(cond, taint, format...) WARN(cond, format) +#define WARN_ON(cond) (!!cond) + + +#define MAX_ERRNO 4095 +#define IS_ERR_VALUE(x) unlikely((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO) + struct iort_its_msi_chip { struct list_head list; struct fwnode_handle *fw_node; @@ -49,7 +68,7 @@ struct iort_fwnode { }; static LIST_HEAD(iort_fwnode_list); static DEFINE_SPINLOCK(iort_fwnode_lock); - +const struct fwnode_operations acpi_static_fwnode_ops; /** * iort_set_fwnode() - Create iort_fwnode and use it to register * iommu data in the iort_fwnode_list @@ -73,7 +92,6 @@ static inline int iort_set_fwnode(struct acpi_iort_node *iort_node, INIT_LIST_HEAD(&np->list); np->iort_node = iort_node; np->fwnode = fwnode; - spin_lock(&iort_fwnode_lock); list_add_tail(&np->list, &iort_fwnode_list); spin_unlock(&iort_fwnode_lock); @@ -93,7 +111,6 @@ struct fwnode_handle *iort_get_fwnode(struct acpi_iort_node *node) { struct iort_fwnode *curr; struct fwnode_handle *fwnode = NULL; - spin_lock(&iort_fwnode_lock); list_for_each_entry(curr, &iort_fwnode_list, list) { if (curr->iort_node == node) { @@ -132,79 +149,6 @@ typedef acpi_status (*iort_find_node_callback) /* Root pointer to the mapped IORT table */ static struct acpi_table_header *iort_table; -static LIST_HEAD(iort_msi_chip_list); -static DEFINE_SPINLOCK(iort_msi_chip_lock); - -/** - * iort_register_domain_token() - register domain token and related ITS ID - * to the list from where we can get it back later on. - * @trans_id: ITS ID. - * @fw_node: Domain token. - * - * Returns: 0 on success, -ENOMEM if no memory when allocating list element - */ -int iort_register_domain_token(int trans_id, struct fwnode_handle *fw_node) -{ - struct iort_its_msi_chip *its_msi_chip; - - its_msi_chip = kzalloc(sizeof(*its_msi_chip), GFP_KERNEL); - if (!its_msi_chip) - return -ENOMEM; - - its_msi_chip->fw_node = fw_node; - its_msi_chip->translation_id = trans_id; - - spin_lock(&iort_msi_chip_lock); - list_add(&its_msi_chip->list, &iort_msi_chip_list); - spin_unlock(&iort_msi_chip_lock); - - return 0; -} - -/** - * iort_deregister_domain_token() - Deregister domain token based on ITS ID - * @trans_id: ITS ID. - * - * Returns: none. - */ -void iort_deregister_domain_token(int trans_id) -{ - struct iort_its_msi_chip *its_msi_chip, *t; - - spin_lock(&iort_msi_chip_lock); - list_for_each_entry_safe(its_msi_chip, t, &iort_msi_chip_list, list) { - if (its_msi_chip->translation_id == trans_id) { - list_del(&its_msi_chip->list); - kfree(its_msi_chip); - break; - } - } - spin_unlock(&iort_msi_chip_lock); -} - -/** - * iort_find_domain_token() - Find domain token based on given ITS ID - * @trans_id: ITS ID. - * - * Returns: domain token when find on the list, NULL otherwise - */ -struct fwnode_handle *iort_find_domain_token(int trans_id) -{ - struct fwnode_handle *fw_node = NULL; - struct iort_its_msi_chip *its_msi_chip; - - spin_lock(&iort_msi_chip_lock); - list_for_each_entry(its_msi_chip, &iort_msi_chip_list, list) { - if (its_msi_chip->translation_id == trans_id) { - fw_node = its_msi_chip->fw_node; - break; - } - } - spin_unlock(&iort_msi_chip_lock); - - return fw_node; -} - static struct acpi_iort_node *iort_scan_node(enum acpi_iort_node_type type, iort_find_node_callback callback, void *context) @@ -215,7 +159,6 @@ static struct acpi_iort_node *iort_scan_node(enum acpi_iort_node_type type, if (!iort_table) return NULL; - /* Get the first IORT node */ iort = (struct acpi_table_iort *)iort_table; iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort, @@ -245,29 +188,11 @@ static acpi_status iort_match_node_callback(struct acpi_iort_node *node, struct device *dev = context; acpi_status status = AE_NOT_FOUND; - if (node->type == ACPI_IORT_NODE_NAMED_COMPONENT) { - struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL }; - struct acpi_device *adev = to_acpi_device_node(dev->fwnode); - struct acpi_iort_named_component *ncomp; - - if (!adev) - goto out; - - status = acpi_get_name(adev->handle, ACPI_FULL_PATHNAME, &buf); - if (ACPI_FAILURE(status)) { - dev_warn(dev, "Can't get device full path name\n"); - goto out; - } - - ncomp = (struct acpi_iort_named_component *)node->node_data; - status = !strcmp(ncomp->device_name, buf.pointer) ? - AE_OK : AE_NOT_FOUND; - acpi_os_free(buf.pointer); - } else if (node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) { + if (node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) { struct acpi_iort_root_complex *pci_rc; - struct pci_bus *bus; + struct pci_dev *pdev; - bus = to_pci_bus(dev); + pdev = to_pci_dev(dev); pci_rc = (struct acpi_iort_root_complex *)node->node_data; /* @@ -275,333 +200,19 @@ static acpi_status iort_match_node_callback(struct acpi_iort_node *node, * with root complexes. Each segment number can represent only * one root complex. */ - status = pci_rc->pci_segment_number == pci_domain_nr(bus) ? + status = pci_rc->pci_segment_number == pci_domain_nr(pdev) ? AE_OK : AE_NOT_FOUND; } -out: - return status; -} - -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_get_id(struct acpi_iort_node *node, - u32 *id_out, int index) -{ - struct acpi_iort_node *parent; - struct acpi_iort_id_mapping *map; - - if (!node->mapping_offset || !node->mapping_count || - index >= node->mapping_count) - return NULL; - - map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, node, - node->mapping_offset + index * sizeof(*map)); - - /* Firmware bug! */ - if (!map->output_reference) { - pr_err(FW_BUG "[node %p type %d] ID map has NULL parent reference\n", - node, node->type); - return NULL; - } - - parent = ACPI_ADD_PTR(struct acpi_iort_node, iort_table, - map->output_reference); - - if (map->flags & ACPI_IORT_ID_SINGLE_MAPPING) { - if (node->type == ACPI_IORT_NODE_NAMED_COMPONENT || - node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) { - *id_out = map->output_base; - return parent; - } - } - - return NULL; -} - -static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node, - u32 id_in, u32 *id_out, - u8 type_mask) -{ - u32 id = id_in; - - /* Parse the ID mapping tree to find specified node type */ - while (node) { - struct acpi_iort_id_mapping *map; - int i; - - if (IORT_TYPE_MASK(node->type) & type_mask) { - if (id_out) - *id_out = id; - 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 ID translation */ - for (i = 0; i < node->mapping_count; i++, map++) { - if (!iort_id_map(map, node->type, id, &id)) - 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 ID to output ID unchanged on mapping failure */ - if (id_out) - *id_out = id_in; - - return NULL; -} - -static -struct acpi_iort_node *iort_node_map_platform_id(struct acpi_iort_node *node, - u32 *id_out, u8 type_mask, - int index) -{ - struct acpi_iort_node *parent; - u32 id; - - /* step 1: retrieve the initial dev id */ - parent = iort_node_get_id(node, &id, index); - if (!parent) - return NULL; - - /* - * optional step 2: map the initial dev id if its parent is not - * the target type we want, map it again for the use cases such - * as NC (named component) -> SMMU -> ITS. If the type is matched, - * return the initial dev id and its parent pointer directly. - */ - if (!(IORT_TYPE_MASK(parent->type) & type_mask)) - parent = iort_node_map_id(parent, id, id_out, type_mask); - else - if (id_out) - *id_out = id; - - return parent; -} -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); -} - -/** - * iort_msi_map_rid() - Map a MSI requester ID for a device - * @dev: The device for which the mapping is to be done. - * @req_id: The device requester ID. - * - * Returns: mapped MSI RID on success, input requester ID otherwise - */ -u32 iort_msi_map_rid(struct device *dev, u32 req_id) -{ - struct acpi_iort_node *node; - u32 dev_id; - - node = iort_find_dev_node(dev); - if (!node) - return req_id; - - iort_node_map_id(node, req_id, &dev_id, IORT_MSI_TYPE); - return dev_id; -} - -/** - * iort_pmsi_get_dev_id() - Get the device id for a device - * @dev: The device for which the mapping is to be done. - * @dev_id: The device ID found. - * - * Returns: 0 for successful find a dev id, -ENODEV on error - */ -int iort_pmsi_get_dev_id(struct device *dev, u32 *dev_id) -{ - int i; - struct acpi_iort_node *node; - - node = iort_find_dev_node(dev); - if (!node) - return -ENODEV; - - for (i = 0; i < node->mapping_count; i++) { - if (iort_node_map_platform_id(node, dev_id, IORT_MSI_TYPE, i)) - return 0; - } - - return -ENODEV; -} - -/** - * iort_dev_find_its_id() - Find the ITS identifier for a device - * @dev: The device. - * @req_id: Device's requester ID - * @idx: Index of the ITS identifier list. - * @its_id: ITS identifier. - * - * Returns: 0 on success, appropriate error value otherwise - */ -static int iort_dev_find_its_id(struct device *dev, u32 req_id, - unsigned int idx, int *its_id) -{ - struct acpi_iort_its_group *its; - struct acpi_iort_node *node; - - node = iort_find_dev_node(dev); - if (!node) - return -ENXIO; - - node = iort_node_map_id(node, req_id, NULL, IORT_MSI_TYPE); - if (!node) - return -ENXIO; - - /* Move to ITS specific data */ - its = (struct acpi_iort_its_group *)node->node_data; - if (idx > its->its_count) { - dev_err(dev, "requested ITS ID index [%d] is greater than available [%d]\n", - idx, its->its_count); - return -ENXIO; - } - - *its_id = its->identifiers[idx]; - return 0; -} - -/** - * iort_get_device_domain() - Find MSI domain related to a device - * @dev: The device. - * @req_id: Requester ID for the device. - * - * Returns: the MSI domain for this device, NULL otherwise - */ -struct irq_domain *iort_get_device_domain(struct device *dev, u32 req_id) -{ - struct fwnode_handle *handle; - int its_id; - - if (iort_dev_find_its_id(dev, req_id, 0, &its_id)) - return NULL; - - handle = iort_find_domain_token(its_id); - if (!handle) - return NULL; - - return irq_find_matching_fwnode(handle, DOMAIN_BUS_PCI_MSI); -} - -/** - * iort_get_platform_device_domain() - Find MSI domain related to a - * platform device - * @dev: the dev pointer associated with the platform device - * - * Returns: the MSI domain for this device, NULL otherwise - */ -static struct irq_domain *iort_get_platform_device_domain(struct device *dev) -{ - struct acpi_iort_node *node, *msi_parent; - struct fwnode_handle *iort_fwnode; - struct acpi_iort_its_group *its; - int i; - - /* find its associated iort node */ - node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT, - iort_match_node_callback, dev); - if (!node) - return NULL; - - /* then find its msi parent node */ - for (i = 0; i < node->mapping_count; i++) { - msi_parent = iort_node_map_platform_id(node, NULL, - IORT_MSI_TYPE, i); - if (msi_parent) - break; - } - - if (!msi_parent) - return NULL; - - /* Move to ITS specific data */ - its = (struct acpi_iort_its_group *)msi_parent->node_data; - - iort_fwnode = iort_find_domain_token(its->identifiers[0]); - if (!iort_fwnode) - return NULL; - - return irq_find_matching_fwnode(iort_fwnode, DOMAIN_BUS_PLATFORM_MSI); -} - -void acpi_configure_pmsi_domain(struct device *dev) -{ - struct irq_domain *msi_domain; - - msi_domain = iort_get_platform_device_domain(dev); - if (msi_domain) - dev_set_msi_domain(dev, msi_domain); -} - -static int __maybe_unused __get_pci_rid(struct pci_dev *pdev, u16 alias, - void *data) -{ - u32 *rid = data; - - *rid = alias; - return 0; + return status; } static int arm_smmu_iort_xlate(struct device *dev, u32 streamid, struct fwnode_handle *fwnode, const struct iommu_ops *ops) { - int ret = iommu_fwspec_init(dev, fwnode, ops); + int ret; + ret = iommu_fwspec_init(dev, fwnode, ops); if (!ret) ret = iommu_fwspec_add_ids(dev, &streamid, 1); @@ -609,45 +220,12 @@ static int arm_smmu_iort_xlate(struct device *dev, u32 streamid, return ret; } -static inline bool iort_iommu_driver_enabled(u8 type) -{ - switch (type) { - case ACPI_IORT_NODE_SMMU_V3: - return IS_BUILTIN(CONFIG_ARM_SMMU_V3); - case ACPI_IORT_NODE_SMMU: - return IS_BUILTIN(CONFIG_ARM_SMMU); - default: - pr_warn("IORT node type %u does not describe an SMMU\n", type); - return false; - } -} - -#ifdef CONFIG_IOMMU_API static inline const struct iommu_ops *iort_fwspec_iommu_ops(struct iommu_fwspec *fwspec) { return (fwspec && fwspec->ops) ? fwspec->ops : NULL; } -static inline -int iort_add_device_replay(const struct iommu_ops *ops, struct device *dev) -{ - int err = 0; - - if (ops->add_device && dev->bus && !dev->iommu_group) - err = ops->add_device(dev); - - return err; -} -#else -static inline -const struct iommu_ops *iort_fwspec_iommu_ops(struct iommu_fwspec *fwspec) -{ return NULL; } -static inline -int iort_add_device_replay(const struct iommu_ops *ops, struct device *dev) -{ return 0; } -#endif - static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node, u32 streamid) { @@ -670,9 +248,9 @@ static int iort_iommu_xlate(struct device *dev, struct acpi_iort_node *node, * or just abort it. */ ops = iommu_ops_from_fwnode(iort_fwnode); - if (!ops) - return iort_iommu_driver_enabled(node->type) ? - -EPROBE_DEFER : -ENODEV; + if (!ops) { + return -1; + } return arm_smmu_iort_xlate(dev, streamid, iort_fwnode, ops); } @@ -685,89 +263,19 @@ struct iort_pci_alias_info { static int iort_pci_iommu_init(struct pci_dev *pdev, u16 alias, void *data) { struct iort_pci_alias_info *info = data; - struct acpi_iort_node *parent; + struct acpi_iort_node *smmu_node; u32 streamid; - parent = iort_node_map_id(info->node, alias, &streamid, - IORT_IOMMU_TYPE); - return iort_iommu_xlate(info->dev, parent, streamid); + query_streamid(info->node, alias, &streamid, &smmu_node); + return iort_iommu_xlate(info->dev, smmu_node, streamid); } -static int nc_dma_get_range(struct device *dev, u64 *size) +int pci_for_each_dma_alias(struct pci_dev *pdev, + int (*fn)(struct pci_dev *pdev, + u16 alias, void *data), void *data) { - struct acpi_iort_node *node; - struct acpi_iort_named_component *ncomp; - - node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT, - iort_match_node_callback, dev); - if (!node) - return -ENODEV; - - ncomp = (struct acpi_iort_named_component *)node->node_data; - - *size = ncomp->memory_address_limit >= 64 ? U64_MAX : - 1ULL<memory_address_limit; - - return 0; -} - -/** - * iort_dma_setup() - Set-up device DMA parameters. - * - * @dev: device to configure - * @dma_addr: device DMA address result pointer - * @size: DMA range size result pointer - */ -void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) -{ - u64 mask, dmaaddr = 0, size = 0, offset = 0; - int ret, msb; - - /* - * Set default coherent_dma_mask to 32 bit. Drivers are expected to - * setup the correct supported mask. - */ - if (!dev->coherent_dma_mask) - dev->coherent_dma_mask = DMA_BIT_MASK(32); - - /* - * Set it to coherent_dma_mask by default if the architecture - * code has not set it. - */ - if (!dev->dma_mask) - dev->dma_mask = &dev->coherent_dma_mask; - - size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1); - - if (dev_is_pci(dev)) - ret = acpi_dma_get_range(dev, &dmaaddr, &offset, &size); - else - ret = nc_dma_get_range(dev, &size); - - if (!ret) { - msb = fls64(dmaaddr + size - 1); - /* - * Round-up to the power-of-two mask or set - * the mask to the whole 64-bit address space - * in case the DMA region covers the full - * memory window. - */ - mask = msb == 64 ? U64_MAX : (1ULL << msb) - 1; - /* - * Limit coherent and dma mask based on size - * retrieved from firmware. - */ - dev->coherent_dma_mask = mask; - *dev->dma_mask = mask; - } - - *dma_addr = dmaaddr; - *dma_size = size; - - dev->dma_pfn_offset = PFN_DOWN(offset); - dev_dbg(dev, "dma_pfn_offset(%#08llx)\n", offset); + return fn(pdev, PCI_BDF2(pdev->bus, pdev->devfn), data); } - /** * iort_iommu_configure - Set-up IOMMU configuration for a device. * @@ -778,9 +286,8 @@ void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) */ const struct iommu_ops *iort_iommu_configure(struct device *dev) { - struct acpi_iort_node *node, *parent; + struct acpi_iort_node *node; const struct iommu_ops *ops; - u32 streamid = 0; int err = -ENODEV; /* @@ -792,472 +299,58 @@ const struct iommu_ops *iort_iommu_configure(struct device *dev) return ops; if (dev_is_pci(dev)) { - struct pci_bus *bus = to_pci_dev(dev)->bus; struct iort_pci_alias_info info = { .dev = dev }; - node = iort_scan_node(ACPI_IORT_NODE_PCI_ROOT_COMPLEX, - iort_match_node_callback, &bus->dev); + iort_match_node_callback, dev); if (!node) return NULL; - info.node = node; err = pci_for_each_dma_alias(to_pci_dev(dev), iort_pci_iommu_init, &info); - } else { - int i = 0; - - node = iort_scan_node(ACPI_IORT_NODE_NAMED_COMPONENT, - iort_match_node_callback, dev); - if (!node) - return NULL; - - do { - parent = iort_node_map_platform_id(node, &streamid, - IORT_IOMMU_TYPE, - i++); - - if (parent) - err = iort_iommu_xlate(dev, parent, streamid); - } while (parent && !err); - } - - /* - * If we have reason to believe the IOMMU driver missed the initial - * add_device callback for dev, replay it to get things in order. - */ - if (!err) { - ops = iort_fwspec_iommu_ops(dev->iommu_fwspec); - err = iort_add_device_replay(ops, dev); } - - /* Ignore all other errors apart from EPROBE_DEFER */ - if (err == -EPROBE_DEFER) { - ops = ERR_PTR(err); - } else if (err) { - dev_dbg(dev, "Adding to IOMMU failed: %d\n", err); - ops = NULL; - } - return ops; } -static void __init acpi_iort_register_irq(int hwirq, const char *name, - int trigger, - struct resource *res) -{ - int irq = acpi_register_gsi(NULL, hwirq, trigger, - ACPI_ACTIVE_HIGH); - - if (irq <= 0) { - pr_err("could not register gsi hwirq %d name [%s]\n", hwirq, - name); - return; - } - - res->start = irq; - res->end = irq; - res->flags = IORESOURCE_IRQ; - res->name = name; -} - -static int __init arm_smmu_v3_count_resources(struct acpi_iort_node *node) -{ - struct acpi_iort_smmu_v3 *smmu; - /* Always present mem resource */ - int num_res = 1; - - /* Retrieve SMMUv3 specific data */ - smmu = (struct acpi_iort_smmu_v3 *)node->node_data; - - if (smmu->event_gsiv) - num_res++; - - if (smmu->pri_gsiv) - num_res++; - - if (smmu->gerr_gsiv) - num_res++; - - if (smmu->sync_gsiv) - num_res++; - - return num_res; -} - -static bool arm_smmu_v3_is_combined_irq(struct acpi_iort_smmu_v3 *smmu) -{ - /* - * Cavium ThunderX2 implementation doesn't not support unique - * irq line. Use single irq line for all the SMMUv3 interrupts. - */ - if (smmu->model != ACPI_IORT_SMMU_V3_CAVIUM_CN99XX) - return false; - - /* - * ThunderX2 doesn't support MSIs from the SMMU, so we're checking - * SPI numbers here. - */ - return smmu->event_gsiv == smmu->pri_gsiv && - smmu->event_gsiv == smmu->gerr_gsiv && - smmu->event_gsiv == smmu->sync_gsiv; -} - -static unsigned long arm_smmu_v3_resource_size(struct acpi_iort_smmu_v3 *smmu) -{ - /* - * Override the size, for Cavium ThunderX2 implementation - * which doesn't support the page 1 SMMU register space. - */ - if (smmu->model == ACPI_IORT_SMMU_V3_CAVIUM_CN99XX) - return SZ_64K; - - return SZ_128K; -} - -static void __init arm_smmu_v3_init_resources(struct resource *res, - struct acpi_iort_node *node) -{ - struct acpi_iort_smmu_v3 *smmu; - int num_res = 0; - - /* Retrieve SMMUv3 specific data */ - smmu = (struct acpi_iort_smmu_v3 *)node->node_data; - - res[num_res].start = smmu->base_address; - res[num_res].end = smmu->base_address + - arm_smmu_v3_resource_size(smmu) - 1; - res[num_res].flags = IORESOURCE_MEM; - - num_res++; - if (arm_smmu_v3_is_combined_irq(smmu)) { - if (smmu->event_gsiv) - acpi_iort_register_irq(smmu->event_gsiv, "combined", - ACPI_EDGE_SENSITIVE, - &res[num_res++]); - } else { - - if (smmu->event_gsiv) - acpi_iort_register_irq(smmu->event_gsiv, "eventq", - ACPI_EDGE_SENSITIVE, - &res[num_res++]); - - if (smmu->pri_gsiv) - acpi_iort_register_irq(smmu->pri_gsiv, "priq", - ACPI_EDGE_SENSITIVE, - &res[num_res++]); - - if (smmu->gerr_gsiv) - acpi_iort_register_irq(smmu->gerr_gsiv, "gerror", - ACPI_EDGE_SENSITIVE, - &res[num_res++]); - - if (smmu->sync_gsiv) - acpi_iort_register_irq(smmu->sync_gsiv, "cmdq-sync", - ACPI_EDGE_SENSITIVE, - &res[num_res++]); - } -} - -static bool __init arm_smmu_v3_is_coherent(struct acpi_iort_node *node) -{ - struct acpi_iort_smmu_v3 *smmu; - - /* Retrieve SMMUv3 specific data */ - smmu = (struct acpi_iort_smmu_v3 *)node->node_data; - - return smmu->flags & ACPI_IORT_SMMU_V3_COHACC_OVERRIDE; -} - -#if defined(CONFIG_ACPI_NUMA) && defined(ACPI_IORT_SMMU_V3_PXM_VALID) -/* - * set numa proximity domain for smmuv3 device - */ -static void __init arm_smmu_v3_set_proximity(struct device *dev, - struct acpi_iort_node *node) -{ - struct acpi_iort_smmu_v3 *smmu; - - smmu = (struct acpi_iort_smmu_v3 *)node->node_data; - if (smmu->flags & ACPI_IORT_SMMU_V3_PXM_VALID) { - set_dev_node(dev, acpi_map_pxm_to_node(smmu->pxm)); - pr_info("SMMU-v3[%llx] Mapped to Proximity domain %d\n", - smmu->base_address, - smmu->pxm); - } -} -#else -#define arm_smmu_v3_set_proximity NULL -#endif - -static int __init arm_smmu_count_resources(struct acpi_iort_node *node) -{ - struct acpi_iort_smmu *smmu; - - /* Retrieve SMMU specific data */ - smmu = (struct acpi_iort_smmu *)node->node_data; - - /* - * Only consider the global fault interrupt and ignore the - * configuration access interrupt. - * - * MMIO address and global fault interrupt resources are always - * present so add them to the context interrupt count as a static - * value. - */ - return smmu->context_interrupt_count + 2; -} - -static void __init arm_smmu_init_resources(struct resource *res, - struct acpi_iort_node *node) -{ - struct acpi_iort_smmu *smmu; - int i, hw_irq, trigger, num_res = 0; - u64 *ctx_irq, *glb_irq; - - /* Retrieve SMMU specific data */ - smmu = (struct acpi_iort_smmu *)node->node_data; - - res[num_res].start = smmu->base_address; - res[num_res].end = smmu->base_address + smmu->span - 1; - res[num_res].flags = IORESOURCE_MEM; - num_res++; - - glb_irq = ACPI_ADD_PTR(u64, node, smmu->global_interrupt_offset); - /* Global IRQs */ - hw_irq = IORT_IRQ_MASK(glb_irq[0]); - trigger = IORT_IRQ_TRIGGER_MASK(glb_irq[0]); - - acpi_iort_register_irq(hw_irq, "arm-smmu-global", trigger, - &res[num_res++]); - - /* Context IRQs */ - ctx_irq = ACPI_ADD_PTR(u64, node, smmu->context_interrupt_offset); - for (i = 0; i < smmu->context_interrupt_count; i++) { - hw_irq = IORT_IRQ_MASK(ctx_irq[i]); - trigger = IORT_IRQ_TRIGGER_MASK(ctx_irq[i]); - - acpi_iort_register_irq(hw_irq, "arm-smmu-context", trigger, - &res[num_res++]); - } -} - -static bool __init arm_smmu_is_coherent(struct acpi_iort_node *node) -{ - struct acpi_iort_smmu *smmu; - - /* Retrieve SMMU specific data */ - smmu = (struct acpi_iort_smmu *)node->node_data; - - return smmu->flags & ACPI_IORT_SMMU_COHERENT_WALK; -} - -struct iort_iommu_config { - const char *name; - int (*iommu_init)(struct acpi_iort_node *node); - bool (*iommu_is_coherent)(struct acpi_iort_node *node); - int (*iommu_count_resources)(struct acpi_iort_node *node); - void (*iommu_init_resources)(struct resource *res, - struct acpi_iort_node *node); - void (*iommu_set_proximity)(struct device *dev, - struct acpi_iort_node *node); -}; - -static const struct iort_iommu_config iort_arm_smmu_v3_cfg __initconst = { - .name = "arm-smmu-v3", - .iommu_is_coherent = arm_smmu_v3_is_coherent, - .iommu_count_resources = arm_smmu_v3_count_resources, - .iommu_init_resources = arm_smmu_v3_init_resources, - .iommu_set_proximity = arm_smmu_v3_set_proximity, -}; - -static const struct iort_iommu_config iort_arm_smmu_cfg __initconst = { - .name = "arm-smmu", - .iommu_is_coherent = arm_smmu_is_coherent, - .iommu_count_resources = arm_smmu_count_resources, - .iommu_init_resources = arm_smmu_init_resources -}; - -static __init -const struct iort_iommu_config *iort_get_iommu_cfg(struct acpi_iort_node *node) -{ - switch (node->type) { - case ACPI_IORT_NODE_SMMU_V3: - return &iort_arm_smmu_v3_cfg; - case ACPI_IORT_NODE_SMMU: - return &iort_arm_smmu_cfg; - default: - return NULL; - } -} - -/** - * iort_add_smmu_platform_device() - Allocate a platform device for SMMU - * @node: Pointer to SMMU ACPI IORT node - * - * Returns: 0 on success, <0 failure - */ static int __init iort_add_smmu_platform_device(struct acpi_iort_node *node) { + struct device *dev; struct fwnode_handle *fwnode; - struct platform_device *pdev; - struct resource *r; - enum dev_dma_attr attr; - int ret, count; - const struct iort_iommu_config *ops = iort_get_iommu_cfg(node); + int ret; - if (!ops) - return -ENODEV; - - pdev = platform_device_alloc(ops->name, PLATFORM_DEVID_AUTO); - if (!pdev) + dev = kzalloc(sizeof (struct device), GFP_KERNEL); + if (!dev) return -ENOMEM; - if (ops->iommu_set_proximity) - ops->iommu_set_proximity(&pdev->dev, node); - - count = ops->iommu_count_resources(node); - - r = kcalloc(count, sizeof(*r), GFP_KERNEL); - if (!r) { - ret = -ENOMEM; - goto dev_put; - } - - ops->iommu_init_resources(r, node); - - ret = platform_device_add_resources(pdev, r, count); - /* - * Resources are duplicated in platform_device_add_resources, - * free their allocated memory - */ - kfree(r); - - if (ret) - goto dev_put; - - /* - * Add a copy of IORT node pointer to platform_data to - * be used to retrieve IORT data information. - */ - ret = platform_device_add_data(pdev, &node, sizeof(node)); - if (ret) - goto dev_put; - - /* - * We expect the dma masks to be equivalent for - * all SMMUs set-ups - */ - pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; + dev->type = DEV_ACPI; + dev->acpi_node = node; fwnode = iort_get_fwnode(node); if (!fwnode) { ret = -ENODEV; - goto dev_put; + goto end; } - pdev->dev.fwnode = fwnode; - - attr = ops->iommu_is_coherent(node) ? - DEV_DMA_COHERENT : DEV_DMA_NON_COHERENT; - - /* Configure DMA for the page table walker */ - acpi_dma_configure(&pdev->dev, attr); - - ret = platform_device_add(pdev); - if (ret) - goto dma_deconfigure; - - return 0; - -dma_deconfigure: - acpi_dma_deconfigure(&pdev->dev); -dev_put: - platform_device_put(pdev); - + dev->fwnode = fwnode; + dev->iommu_fwspec = kzalloc(sizeof (struct iommu_fwspec), GFP_KERNEL); + /* Call the acpi init functions for IOMMU devices */ + ret = acpi_device_init(DEVICE_IOMMU, (void *) dev, node->type); +end: return ret; } -static bool __init iort_enable_acs(struct acpi_iort_node *iort_node) -{ - if (iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) { - struct acpi_iort_node *parent; - struct acpi_iort_id_mapping *map; - int i; - - map = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node, - iort_node->mapping_offset); - - for (i = 0; i < iort_node->mapping_count; i++, map++) { - if (!map->output_reference) - continue; - - parent = ACPI_ADD_PTR(struct acpi_iort_node, - iort_table, map->output_reference); - /* - * If we detect a RC->SMMU mapping, make sure - * we enable ACS on the system. - */ - if ((parent->type == ACPI_IORT_NODE_SMMU) || - (parent->type == ACPI_IORT_NODE_SMMU_V3)) { - pci_request_acs(); - return true; - } - } - } - - return false; -} -static void __init iort_init_platform_devices(void) +static inline struct fwnode_handle *acpi_alloc_fwnode_static(void) { - struct acpi_iort_node *iort_node, *iort_end; - struct acpi_table_iort *iort; struct fwnode_handle *fwnode; - int i, ret; - bool acs_enabled = false; - /* - * iort_table and iort both point to the start of IORT table, but - * have different struct types - */ - iort = (struct acpi_table_iort *)iort_table; - - /* Get the first IORT node */ - iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort, - iort->node_offset); - iort_end = ACPI_ADD_PTR(struct acpi_iort_node, iort, - iort_table->length); - - for (i = 0; i < iort->node_count; i++) { - if (iort_node >= iort_end) { - pr_err("iort node pointer overflows, bad table\n"); - return; - } - - if (!acs_enabled) - acs_enabled = iort_enable_acs(iort_node); - - if ((iort_node->type == ACPI_IORT_NODE_SMMU) || - (iort_node->type == ACPI_IORT_NODE_SMMU_V3)) { - - fwnode = acpi_alloc_fwnode_static(); - if (!fwnode) - return; - - iort_set_fwnode(iort_node, fwnode); + fwnode = kzalloc(sizeof(struct fwnode_handle), GFP_KERNEL); + if (!fwnode) + return NULL; - ret = iort_add_smmu_platform_device(iort_node); - if (ret) { - iort_delete_fwnode(iort_node); - acpi_free_fwnode_static(fwnode); - return; - } - } + fwnode->ops = &acpi_static_fwnode_ops; - iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort_node, - iort_node->length); - } + return fwnode; } void __init acpi_iort_init(void) @@ -1265,15 +358,12 @@ void __init acpi_iort_init(void) acpi_status status; status = acpi_get_table(ACPI_SIG_IORT, 0, &iort_table); + if (ACPI_FAILURE(status)) { if (status != AE_NOT_FOUND) { const char *msg = acpi_format_exception(status); - pr_err("Failed to get table, %s\n", msg); } - return; } - - iort_init_platform_devices(); } diff --git a/xen/include/acpi/acpi_iort.h b/xen/include/acpi/acpi_iort.h index 8d3f0bf803..559226a312 100644 --- a/xen/include/acpi/acpi_iort.h +++ b/xen/include/acpi/acpi_iort.h @@ -19,9 +19,9 @@ #ifndef __ACPI_IORT_H__ #define __ACPI_IORT_H__ -#include -#include -#include +#include +#include +#include #define IORT_IRQ_MASK(irq) (irq & 0xffffffffULL) #define IORT_IRQ_TRIGGER_MASK(irq) ((irq >> 32) & 0xffffffffULL) From patchwork Tue Jan 2 09:28:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Jaggi X-Patchwork-Id: 123105 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8755163qgn; Tue, 2 Jan 2018 01:31:18 -0800 (PST) X-Google-Smtp-Source: ACJfBot6ay4DayEQHs9WhMM9DfcZtkK05A1CxEVmU2w4BPQBtq/xKX+yebcgxsRypn+6fMBUA+yh X-Received: by 10.36.164.74 with SMTP id v10mr60293371iti.26.1514885478314; Tue, 02 Jan 2018 01:31:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514885478; cv=none; d=google.com; s=arc-20160816; b=ZJ3nZwIALmsKBtPvqr4xfog1fY8Zpfk8XOfnJPvzcbCAA9m9krZH7ATGvboPCST1Fl LVCLMkHLaPDy8Nqj0lV7o+4MIiko3OWMmmba5pEM36cWz2BXRGpDm4Xv3IYYpuiXz6qc SeNJ+K3eYMYWVtCd5IMkxl7mF2gD40/0sHY4NEH8vPcyN3YLa6ak7viUSq+KkKvgeRw6 8/AACuPW9/p0SR9heoCfTmW7l5Fdnmt9Q2528IohwNEVJCNxf8lX798Ve8eXhA4DCKx1 +kkfjc49prjhL3ZWABt1vkKcbYgMH8cIGB74PTFxS77kHoLWFvTeVDspPgPFkbo0UYN/ vekg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=COcoFmlrU8mhyXk4S+VWMRuBtsObcO7ckN5494Re3mY=; b=Jj7BKy+61VkbpFeKx+fnnFcIUu/KsJNwmO75z++9YAWVl3rJVXAhfEeg4d3b2IT0XY uTomxV44BL1ter8muQ2O9fFFF3za7Mft57Av429Y1KV3Cve4OX6JUR0WKaL+K3LOKgoX NTzFWteUIG18vsbrHZv3E7d/57Fkdspkh+Cr1MSxmRV0d6a+vfnQnpnxjPu+CYDiMc5r kSkD+us2rh63QupFYjxNanGz+dttGWP2K32AZJtMQoZwMyVmJfvVoVkNvD5y7gVinzX1 4c0rViaUjZTzqQky4G4IwMFLR2A2aOfR5BAFmeqiq/POgCWseqFxxaAw2YF/+QVqrdRs JYFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=EVCv39Z8; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id u140si23538166itc.55.2018.01.02.01.31.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:31:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=EVCv39Z8; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsj-0002na-Jv; Tue, 02 Jan 2018 09:29:13 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsi-0002mU-Cr for xen-devel@lists.xenproject.org; Tue, 02 Jan 2018 09:29:12 +0000 X-Inumbo-ID: 3c014eb4-ef9f-11e7-b4a6-bc764e045a96 Received: from mail-pl0-x243.google.com (unknown [2607:f8b0:400e:c01::243]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 3c014eb4-ef9f-11e7-b4a6-bc764e045a96; Tue, 02 Jan 2018 10:28:04 +0100 (CET) Received: by mail-pl0-x243.google.com with SMTP id s10so28314522plj.5 for ; Tue, 02 Jan 2018 01:29:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=R6aXx5d6zfzvk/s5m+EwifCdhy5Kayh9+ltEzmfvJnY=; b=EVCv39Z8Os3uSXpWw+xz+/ZWmv6QZqjmL6KlpwkPdRTnebHNfQ9HwwTgZfCKpVkDPw acCxjoQmOylAD05jg677i8IiTXZoHGiWIaYebRkOOhNcgk4RrPQuY3i4VGcCT+k/Tp2b pq86wyMsFsRsQ7NDEmwCB//ASNu+sB4lpvsRI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=R6aXx5d6zfzvk/s5m+EwifCdhy5Kayh9+ltEzmfvJnY=; b=M+IcVpa7QwfyJcwP4pFBy27AVVMeTH/7GKYnl57fH1fuygt/riO0J03zOMDeXkRL2M m5aK2RKMl5tKBZ1U02+qamXKop7zfMOGuJZr/T0dGUC9ISWWJc9ORTWnN7R78KEzjimX FRYpx+ZilOAV1IV8VfDMeCdB44vBiNhCl6Mbd+srgxAi3thvUnt0s0NHyFodmYYjkaA7 KgFrRJQthSiJuyap/DDtM9ZwMIcBwvqIrkGXJ6XNlexxeNdV72a7AAoKYbU+cVbvpLY8 WD0vh7MxESJN8wA5ciSkk9uuBjJhV84G5uxuCbPwU4quzh+x/fh2D4FiLdi8m7TMWeEj NhWw== X-Gm-Message-State: AKGB3mL0NpkaMV8raLJnapuuUyoTRZmWFi/1mPfQh1FR5K4ts0lFzVSK 85ZtR5VfVTr5fayWg7XE38iUsYCgtnY= X-Received: by 10.84.131.130 with SMTP id d2mr44591445pld.226.1514885349942; Tue, 02 Jan 2018 01:29:09 -0800 (PST) Received: from thunder-dev-box.domain.name ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id e8sm22065207pgs.44.2018.01.02.01.29.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:29:09 -0800 (PST) From: manish.jaggi@linaro.org To: xen-devel@lists.xenproject.org, julien.grall@linaro.org, sameer.goel@linaro.org, andre.przywara@linaro.org Date: Tue, 2 Jan 2018 14:58:08 +0530 Message-Id: <20180102092809.1841-11-manish.jaggi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180102092809.1841-1-manish.jaggi@linaro.org> References: <20180102092809.1841-1-manish.jaggi@linaro.org> Cc: Manish Jaggi , manish.jaggi@cavium.com Subject: [Xen-devel] [RFC 10/11] IORT parsing functions to prepare requesterId maps X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Manish Jaggi This patch adds functions to parse the IORT and use the requesterID public API to update the maps. Signed-off-by: Manish jaggi --- xen/drivers/acpi/arm/iort.c | 200 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+) diff --git a/xen/drivers/acpi/arm/iort.c b/xen/drivers/acpi/arm/iort.c index a47ee2df4c..00a9f18046 100644 --- a/xen/drivers/acpi/arm/iort.c +++ b/xen/drivers/acpi/arm/iort.c @@ -353,6 +353,205 @@ static inline struct fwnode_handle *acpi_alloc_fwnode_static(void) return fwnode; } +static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr) +{ + return unlikely(!ptr) || IS_ERR_VALUE((unsigned long)ptr); +} + +static inline bool is_acpi_static_node(const struct fwnode_handle *fwnode) +{ + return !IS_ERR_OR_NULL(fwnode) && + fwnode->ops == &acpi_static_fwnode_ops; +} + +static inline void acpi_free_fwnode_static(struct fwnode_handle *fwnode) +{ + if (WARN_ON(!is_acpi_static_node(fwnode))) + return; + + kfree(fwnode); +} +int fixup_rid_deviceid_map(struct acpi_iort_node *inode, + struct acpi_iort_id_mapping *pci_idmap, + struct acpi_iort_node *smmu_node) +{ + + unsigned int p_input_base, p_output_base, p_id_count; + unsigned int s_input_base, s_output_base, s_id_count; + unsigned int delta, i; + int ret = 0; + struct acpi_iort_id_mapping *smmu_idmap = NULL; + struct acpi_iort_node *its_node; + struct acpi_table_iort *iort; + + iort = (struct acpi_table_iort*) iort_table; + + p_input_base = pci_idmap->input_base; + p_output_base = pci_idmap->output_base; + p_id_count = pci_idmap->id_count; + + smmu_idmap = (struct acpi_iort_id_mapping*) ((u8*) smmu_node + + smmu_node->mapping_offset); + + for (i = 0; i < smmu_node->mapping_count; i++, smmu_idmap++) { + s_input_base = smmu_idmap->input_base; + s_output_base = smmu_idmap->output_base; + s_id_count = smmu_idmap->id_count; + its_node = ACPI_ADD_PTR(struct acpi_iort_node, iort, + smmu_idmap->output_reference); + + if (s_input_base <= p_output_base) { + int count; + if (s_input_base + s_id_count < p_output_base) + continue; + + delta = p_output_base - s_input_base; + count = s_input_base + s_id_count <= p_output_base + + p_id_count ? s_id_count - delta : p_id_count; + + ret = add_rid_deviceid_map (inode, its_node, + p_input_base, + s_output_base + delta, + count); + if (ret) + return ret; + } else { + int count; + if (p_output_base + p_id_count < s_input_base) + continue; + + delta = s_input_base - p_output_base; + count = s_input_base + s_id_count < p_output_base + + p_id_count ? s_id_count : p_id_count - delta; + + ret = add_rid_deviceid_map (inode, its_node, + p_input_base + delta, + s_output_base, count); + + if (ret) + return ret; + } + } + + return ret; +} + +void parse_pcirc_node(struct acpi_iort_node *iort_node) +{ + int j , ret; + struct acpi_iort_id_mapping *idmap; + struct acpi_iort_node *onode; + struct acpi_table_iort *iort; + + iort = (struct acpi_table_iort*) iort_table; + idmap = ACPI_ADD_PTR(struct acpi_iort_id_mapping, iort_node, + iort_node->mapping_offset); + + /* iterate over idmap */ + for ( j = 0; j < iort_node->mapping_count; j++ ) { + + struct acpi_iort_node *its_node; + struct acpi_iort_node *smmu_node; + onode = ACPI_ADD_PTR(struct acpi_iort_node, iort, + idmap->output_reference); + + switch (onode->type) { + case ACPI_IORT_NODE_ITS_GROUP: + + its_node = ACPI_ADD_PTR(struct acpi_iort_node, iort, + idmap->output_reference); + + ret = add_rid_deviceid_map(iort_node, its_node, + idmap->input_base, + idmap->output_base, + idmap->id_count); + if (ret) { + pr_err("%s: add_rid_deviceid_map" + "failed with ret=%d \r\n", + __func__, ret); + break; + } + break; + + case ACPI_IORT_NODE_SMMU: + case ACPI_IORT_NODE_SMMU_V3: + + smmu_node = ACPI_ADD_PTR( + struct acpi_iort_node, + iort_table, + idmap->output_reference); + + ret = add_rid_streamid_map(iort_node, + smmu_node, + idmap->input_base, + idmap->output_base, + idmap->id_count); + if (ret) { + pr_err("%s: add_rid_streamid_map" + "failed with ret=%d \r\n", + __func__, ret); + break; + } + + ret = fixup_rid_deviceid_map(iort_node, idmap, + onode); + if (ret) { + pr_err("%s: fixup_rid_deviceid_map" + "failed with ret=%d \r\n", + __func__, ret); + break; + } + break; + } + idmap++; + } +} + +void parse_smmu_node(struct acpi_iort_node *iort_node) +{ + int ret; + struct fwnode_handle *fwnode; + fwnode = acpi_alloc_fwnode_static(); + if (!fwnode) + return; + + iort_set_fwnode(iort_node, fwnode); + ret = iort_add_smmu_platform_device(iort_node); + if (ret) + acpi_free_fwnode_static(fwnode); +} + +void parse_iort(void) +{ + struct acpi_iort_node *iort_node, *iort_end; + struct acpi_table_iort *iort; + int i; + + iort = (struct acpi_table_iort*) iort_table; + iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort, + iort->node_offset); + iort_end = ACPI_ADD_PTR(struct acpi_iort_node, iort, + iort->header.length); + init_ridmaps(); + + for (i = 0; i < iort->node_count; i++) { + if ( iort_node >= iort_end ) { + pr_err("iort node pointer overflows, bad table\n"); + return; + } + + if ( iort_node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX ) + parse_pcirc_node(iort_node); + else if ( (iort_node->type == ACPI_IORT_NODE_SMMU || + iort_node->type == ACPI_IORT_NODE_SMMU_V3) ) + parse_smmu_node(iort_node); + + iort_node = ACPI_ADD_PTR(struct acpi_iort_node, iort_node, + iort_node->length); + } +} + + void __init acpi_iort_init(void) { acpi_status status; @@ -366,4 +565,5 @@ void __init acpi_iort_init(void) } return; } + parse_iort(); } From patchwork Tue Jan 2 09:28:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Jaggi X-Patchwork-Id: 123103 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8755124qgn; Tue, 2 Jan 2018 01:31:15 -0800 (PST) X-Google-Smtp-Source: ACJfBoszqCk791VhLav5gef/U501SjkTNhrh52R6dco+awBAaGwUeJdgpm79keqPtmsEU1YJG7UT X-Received: by 10.36.118.195 with SMTP id z186mr60164335itb.106.1514885474994; Tue, 02 Jan 2018 01:31:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514885474; cv=none; d=google.com; s=arc-20160816; b=xeK6RW7XWSO5sq7Kqm8qbbsApbqDe5P+Wr+xly6frfaoC1KxBxq4Ha7rlAAJmapnb2 Kzec2Eg+S+6sNDNLOTE53Wazopv4jDYJPzh1ByZeO4to55zWWTT9I5C6DH8OwikKLCOs z7z3vgw4p7IWTYANDPqBJZrUhGuvUSHcCWwkf/+eoddu2r/zJ2K6VNicRs5jr5SYjPay qDlrfePyIUpretP9xQThRhED2wL32UOwZjuJ8S9v5pHusA1LllryYw2uM3wkEdmsT1YT P5/iejMUZdn87sv7eHIZA6sEXU6lCIoEfsqIsrVShcKUKq0zQXKEutE8J5vmHwcj5l1d Ccmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=YP84MTl3ozEZQmbEKHfe0j7xKc+/tgauCEp85Sb0dhU=; b=Y/FcJTewBrUCRp3aQw0eCiANWXRkjNSu1WIcNWIPq1oQhJEaxLelbgqSQAaTJGdpG6 2eB2c+TrU0rx7hZyzjSX+MHZGM4I2652Zibi22QR3w7LTh4mTDoLW4V80BaHc3cXeRx2 U7gsk1SBGC4BBm9U5GhsbyMYC6LVL6y75l0CDbqYcUqa2w+maUc9wgeM34AMYHy/+adv aoOXTDirXvhElWBVa3tKoIV6zdTxHf+2nQd+gBPs9LjObKsY9a4K0WWQp+xuvdn04p1T CrO24JbIiggmLJ6UKRPz1oxZbIwW2OI9FQGl3G2IoOPWA+e5/vE1QPTygkXrB/OVe/c0 ieQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=X0xnTc1B; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id b12si14551325iof.175.2018.01.02.01.31.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:31:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=X0xnTc1B; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsn-0002sE-Qw; Tue, 02 Jan 2018 09:29:17 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWIsm-0002rI-Ln for xen-devel@lists.xenproject.org; Tue, 02 Jan 2018 09:29:16 +0000 X-Inumbo-ID: 3eae6519-ef9f-11e7-b4a6-bc764e045a96 Received: from mail-pl0-x243.google.com (unknown [2607:f8b0:400e:c01::243]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 3eae6519-ef9f-11e7-b4a6-bc764e045a96; Tue, 02 Jan 2018 10:28:09 +0100 (CET) Received: by mail-pl0-x243.google.com with SMTP id b96so28335661pli.2 for ; Tue, 02 Jan 2018 01:29:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=roswu9BnNPiNA4KFv7UbKhORPI+pqOGS7up8OSzuxxQ=; b=X0xnTc1BhoTS7GaEQKdCvSBuNZPuZwApbvY9Pp6XWVtmo+sYAhYokB0Qqay9NRdb/X jsUfPwq14nnMs31LiwsYBe6lzuci+/D//2IE2qpFglpHvnth2WIuI/rv8F6AHCd1iY6H kqeV/ptF5M8DIWS+fBN8FFZdnIpGLaujvOk08= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=roswu9BnNPiNA4KFv7UbKhORPI+pqOGS7up8OSzuxxQ=; b=j6qWdXoXY7mg4aZz7dsNoritQu9ETKdRRnauMOXJGhqhghsgivFt49MpSDBSuWnewF OlFENHhIbF7IrcZYm3v6lCkQkl08YhPmuocrQBlSf83+HU9vKBK96N+umw4Oc2MuKXRO fMSx7V9QXp1LnvWBCi2pGhrBThrz41g6AgtuRVGEqwFR0GXlq6NPyxbtYPJ0h5YZeBcg Plg7jeuHHb7/NkFyhxZ6xVQd3ogKjiHoRaLGvNe+rpQ6m4J+rCs03vc1qAp6kRihSYVs cCZNpwzSa8C9hHTpKCPYxFLTc0phkqkrYwMavjeaOlaVWjkPrDQT0Vz84kRz1lRw1NGl uIXA== X-Gm-Message-State: AKGB3mICSqdvYzTMeR0pLvVpstqbwNtTc4JN73AuyWZLddsOjS5XkjVA 7X9Sff+8NR8z9bUzxvEiMKl3t3Px0Jc= X-Received: by 10.159.253.5 with SMTP id p5mr19377228pls.7.1514885354502; Tue, 02 Jan 2018 01:29:14 -0800 (PST) Received: from thunder-dev-box.domain.name ([111.93.218.67]) by smtp.gmail.com with ESMTPSA id e8sm22065207pgs.44.2018.01.02.01.29.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jan 2018 01:29:14 -0800 (PST) From: manish.jaggi@linaro.org To: xen-devel@lists.xenproject.org, julien.grall@linaro.org, sameer.goel@linaro.org, andre.przywara@linaro.org Date: Tue, 2 Jan 2018 14:58:09 +0530 Message-Id: <20180102092809.1841-12-manish.jaggi@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180102092809.1841-1-manish.jaggi@linaro.org> References: <20180102092809.1841-1-manish.jaggi@linaro.org> Cc: Manish Jaggi , manish.jaggi@cavium.com Subject: [Xen-devel] [RFC 11/11] Add to_pci_dev macro X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Manish Jaggi This patch adds to_pci_dev macro Signed-off-by: Manish Jaggi --- xen/include/xen/pci.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index 43f21251a5..4c7ff4dd10 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -92,8 +92,11 @@ struct pci_dev { #define PT_FAULT_THRESHOLD 10 } fault; u64 vf_rlen[6]; + struct device dev; }; +#define to_pci_dev(p) container_of(p, struct pci_dev, dev) +#define pci_domain_nr(dev) dev->seg #define for_each_pdev(domain, pdev) \ list_for_each_entry(pdev, &(domain->arch.pdev_list), domain_list)