From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6E17CEE57DF for ; Mon, 11 Sep 2023 19:29:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=te4f81eGPtg0bouW4SAmXDWbnZKT5YROkCJuS9oTn7U=; b=YwVf5v52ojURq5 mnuSKv0loO8fZ93gJ1A0GkL/7T0lQw1Jz5d31A0SPD17X5tbbS+1NvzU5WDSr38SUhlA5V15ACzJO MCGo2V5L/OKcknrCnJtHzFCeRi0rygnVw7qjnKj+2BuRF5el43b+JrZyZvtZXAnXGP9FbKdTloDgR gVTCY6rG+PxxTGoFwCN/hjYF6pGj/w5nrEjAJgZmfEJbSkUXbPHgktxvYO86cu/4nEtusprXq4OGR God4U3/4Homvrc6LKvsy2D4Yq50RybGym0R8De5mvW3JIIZ3hU6r4cIDfsepH2sOu5+W3vbz4hCOc DDkzW80RyEg3Lhf2Ktfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qfmb7-001CMP-0x; Mon, 11 Sep 2023 19:29:25 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qfmb4-001CLv-1E for linux-arm-kernel@lists.infradead.org; Mon, 11 Sep 2023 19:29:23 +0000 Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-52a4737a08fso6073268a12.3 for ; Mon, 11 Sep 2023 12:29:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694460560; x=1695065360; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qZzh/DBuy01jQlncJ8BxreG4T0oh4ErWrLQjt3L1jcs=; b=UfDao2/D4wmOnMFP3045ms+4oR1x/yAs5snLALsXUvMAW7gFdSy06vdzD8zGpzgKe0 G5//uZ/K3CnEJlWAo/4w+A4WkoCHIvhLtXowBr9fmF0OSQ7mgAVyl2ke51OcqzF5fkg4 BGQoSj/bissOpU0b+Cj8h0HGWVzLez8xg7bEZ30OZGkliMQMafsgy0L+fZ9r+oAAeh2I UuygWoKq1IXVxQduQUiIoYg8ellyXkaYQ/Jl00XUSP1oQAP5T41Mu34MYFG5puWVQu6r Z64NvqXkJ3X9oGnMPDNSeRMiofQTQGtm31c6YPtaa9HOxlt8Lftxd0A8DDIV6DDplmWA 5Ogg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694460560; x=1695065360; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qZzh/DBuy01jQlncJ8BxreG4T0oh4ErWrLQjt3L1jcs=; b=Bf+IwEvZdAL6D/yGvu2qusOckAAj4qIFe1MiUQMoGiWFrEuWsr6qSMmoIiYCk7cXZO /X7t78zOhiKkF3jcI2ZbVKgf7Hs7GgNtvsNcmTbxzQrtqgIezSeZA2ftFX54F6zb0bnd l3PybObGZ53VgLifj4kEDD6YBvb20roSwA1jSgFCM7ozHAeH1xWubFnCL8usASU0ZdOB DVRUx3qH714Qfd8nvWsGovEqR59TJ6C5tLbhxf7CqPrZiDSu4fulhyyhuWoyA7qWllS8 7cKcSoXvKvLDgze5gcnDCBo6/IBWz7GkvWoF+LxYmqS+UGWLwz+4k13fU6Le03Y06XY1 GHjw== X-Gm-Message-State: AOJu0YygCR7PBaNrzYgG26xKoQVtekAwRJFUnOmr8QZLVr51nQyk6G/F YC5QxZH9qsDwvWFF3pC2QnE5fXT+ZFzqSQ== X-Google-Smtp-Source: AGHT+IH3JKjxir6dCvy6TAASsokGwwD1qL65KbvEhXU9Z1phY7jA9USqKstRMNkQ2Jhj8vTcYYdzXg== X-Received: by 2002:aa7:d1cb:0:b0:52c:9f89:4447 with SMTP id g11-20020aa7d1cb000000b0052c9f894447mr8580218edp.4.1694460559977; Mon, 11 Sep 2023 12:29:19 -0700 (PDT) Received: from archlinux.localnet (82-149-12-148.dynamic.telemach.net. [82.149.12.148]) by smtp.gmail.com with ESMTPSA id w9-20020aa7cb49000000b0051bed21a635sm5027658edt.74.2023.09.11.12.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 12:29:19 -0700 (PDT) From: Jernej =?utf-8?B?xaBrcmFiZWM=?= To: joro@8bytes.org, will@kernel.org, Robin Murphy Cc: wens@csie.org, samuel@sholland.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iommu/sun50i: Allow page sizes between 4K and 1M Date: Mon, 11 Sep 2023 21:29:18 +0200 Message-ID: <5707055.DvuYhMxLoT@archlinux> In-Reply-To: <40649946-739b-fec6-d743-f7828613fec5@arm.com> References: <20230911190218.1758812-1-jernej.skrabec@gmail.com> <40649946-739b-fec6-d743-f7828613fec5@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230911_122922_426986_2793BB61 X-CRM114-Status: GOOD ( 25.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Monday, September 11, 2023 9:06:12 PM CEST Robin Murphy wrote: > On 2023-09-11 20:02, Jernej Skrabec wrote: > > While peripheral supports only 4K page sizes, we can easily emulate > > support for bigger page sizes, up to 1M. This is done by making multiple > > entries in map function or clearing multiple entries in unmap. > > No, it's done by converting over to the {map,unmap}_pages ops. There's > no need to resurrect this horrible bodge. Missed those, thanks! In any case, logic to implement those isn't that different than here. Best regards, Jernej > > Thanks, > Robin. > > > Signed-off-by: Jernej Skrabec > > --- > > > > drivers/iommu/sun50i-iommu.c | 49 +++++++++++++++++++++++------------- > > 1 file changed, 31 insertions(+), 18 deletions(-) > > > > diff --git a/drivers/iommu/sun50i-iommu.c b/drivers/iommu/sun50i-iommu.c > > index 74c5cb93e900..93077575d60f 100644 > > --- a/drivers/iommu/sun50i-iommu.c > > +++ b/drivers/iommu/sun50i-iommu.c > > @@ -95,6 +95,10 @@ > > > > #define SPAGE_SIZE 4096 > > > > +#define SUN50I_IOMMU_PGSIZES (SZ_4K | SZ_8K | SZ_16K | SZ_32K | \ > > + SZ_64K | SZ_128K | SZ_256K | \ > > + SZ_512K | SZ_1M) > > + > > > > struct sun50i_iommu { > > > > struct iommu_device iommu; > > > > @@ -593,10 +597,12 @@ static int sun50i_iommu_map(struct iommu_domain > > *domain, unsigned long iova,> > > { > > > > struct sun50i_iommu_domain *sun50i_domain = to_sun50i_domain(domain); > > struct sun50i_iommu *iommu = sun50i_domain->iommu; > > > > - u32 pte_index; > > + u32 pte_index, pages, i; > > > > u32 *page_table, *pte_addr; > > int ret = 0; > > > > + pages = size / SPAGE_SIZE; > > + > > > > page_table = sun50i_dte_get_page_table(sun50i_domain, iova, gfp); > > if (IS_ERR(page_table)) { > > > > ret = PTR_ERR(page_table); > > > > @@ -604,18 +610,22 @@ static int sun50i_iommu_map(struct iommu_domain > > *domain, unsigned long iova,> > > } > > > > pte_index = sun50i_iova_get_pte_index(iova); > > > > - pte_addr = &page_table[pte_index]; > > - if (unlikely(sun50i_pte_is_page_valid(*pte_addr))) { > > - phys_addr_t page_phys = sun50i_pte_get_page_address(*pte_addr); > > - dev_err(iommu->dev, > > - "iova %pad already mapped to %pa cannot remap to %pa prot: %#x\n", > > - &iova, &page_phys, &paddr, prot); > > - ret = -EBUSY; > > - goto out; > > + for (i = 0; i < pages; i++) { > > + pte_addr = &page_table[pte_index + i]; > > + if (unlikely(sun50i_pte_is_page_valid(*pte_addr))) { > > + phys_addr_t page_phys = sun50i_pte_get_page_address(*pte_addr); > > + > > + dev_err(iommu->dev, > > + "iova %pad already mapped to %pa cannot remap to %pa prot: %#x\n", > > + &iova, &page_phys, &paddr, prot); > > + ret = -EBUSY; > > + goto out; > > + } > > + *pte_addr = sun50i_mk_pte(paddr, prot); > > + paddr += SPAGE_SIZE; > > > > } > > > > - *pte_addr = sun50i_mk_pte(paddr, prot); > > - sun50i_table_flush(sun50i_domain, pte_addr, 1); > > + sun50i_table_flush(sun50i_domain, &page_table[pte_index], pages); > > > > out: > > return ret; > > > > @@ -626,8 +636,10 @@ static size_t sun50i_iommu_unmap(struct iommu_domain > > *domain, unsigned long iova> > > { > > > > struct sun50i_iommu_domain *sun50i_domain = to_sun50i_domain(domain); > > phys_addr_t pt_phys; > > > > + u32 dte, pages, i; > > > > u32 *pte_addr; > > > > - u32 dte; > > + > > + pages = size / SPAGE_SIZE; > > > > dte = sun50i_domain->dt[sun50i_iova_get_dte_index(iova)]; > > if (!sun50i_dte_is_pt_valid(dte)) > > > > @@ -636,13 +648,14 @@ static size_t sun50i_iommu_unmap(struct iommu_domain > > *domain, unsigned long iova> > > pt_phys = sun50i_dte_get_pt_address(dte); > > pte_addr = (u32 *)phys_to_virt(pt_phys) + > > sun50i_iova_get_pte_index(iova); > > > > - if (!sun50i_pte_is_page_valid(*pte_addr)) > > - return 0; > > + for (i = 0; i < pages; i++) > > + if (!sun50i_pte_is_page_valid(pte_addr[i])) > > + return 0; > > > > - memset(pte_addr, 0, sizeof(*pte_addr)); > > - sun50i_table_flush(sun50i_domain, pte_addr, 1); > > + memset(pte_addr, 0, sizeof(*pte_addr) * pages); > > + sun50i_table_flush(sun50i_domain, pte_addr, pages); > > > > - return SZ_4K; > > + return size; > > > > } > > > > static phys_addr_t sun50i_iommu_iova_to_phys(struct iommu_domain > > *domain, > > > > @@ -827,7 +840,7 @@ static int sun50i_iommu_of_xlate(struct device *dev, > > > > } > > > > static const struct iommu_ops sun50i_iommu_ops = { > > > > - .pgsize_bitmap = SZ_4K, > > + .pgsize_bitmap = SUN50I_IOMMU_PGSIZES, > > > > .device_group = sun50i_iommu_device_group, > > .domain_alloc = sun50i_iommu_domain_alloc, > > .of_xlate = sun50i_iommu_of_xlate, _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel