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: + */