From patchwork Sun Oct 23 19:41:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shimrra Shai X-Patchwork-Id: 13016423 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 A9721ECAAA1 for ; Sun, 23 Oct 2022 19:43:00 +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: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:In-Reply-To:References: List-Owner; bh=8Q8BIiJ2MNSULJgJmGyK2hUqUGb890oE/Mte01pXe9s=; b=lDq8Py9xBdnhM2 KUvaoaXsS9Tqca1Ilv4/9K0IGendJe37Pb8s8hR/njcxHz2VmXw/IuDmCOPPZGt6YAJSp9Qh1BnlK ZNwGEldoKulREV9Gyxa4XmMaELdZpGPADQJGuLkez/YuGIiFlCeSZf3Px+bdhV8CAfeaQSjPQa9Qd CcUQDaHGBBttVVJKen05p2pGlHwNKBG9ev8mzoJ67YdhpslnRIdPFF5GGvNh7dJcOBUm9D17TKMxZ gvMPwD0+x7nwOL6nb0VEwTM65B5QtZ8qnR5qagYYTSfgdlvJUu88WtbuwTQHm7oI97i9iB5ECXGX+ klAb1jpYlOvKBxjPbS8Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1omgqz-00G77J-7T; Sun, 23 Oct 2022 19:41:49 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1omgqw-00G76g-5G for linux-arm-kernel@lists.infradead.org; Sun, 23 Oct 2022 19:41:47 +0000 Received: by mail-pf1-x436.google.com with SMTP id 192so200746pfx.5 for ; Sun, 23 Oct 2022 12:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=GmCyjO3jMazJwYGiGokKF6SV+kz6Mn0ZPRsnviHfL34=; b=RgHukHjs3kyeRBnBcffVeb46vrlBrurwmgar3dm/7WyIBX8l2W+MvYYQKgTPdwZUIQ PONxqtYlC8/cccj+/LQWz9Lrjbv+Bifzvc7Ija34wOcaTDHx/xJli/76tjv1iHdKR3mi 5T0IO4vlK6n+WXX04ONYniB4hYDMBmpK89r20oO+IHcHqWhYcMMhoMCfDaxykhrqD3RD xK1Llw/M+LsVLnBQH50RXsWPJmdQKlyKfaCx0jK7t84ehGATjeJhhAGDOl/D5rPFwJRo frDZT364WFsv6zl4Viehx80vjLz1OEIz+/r6b/LtAyH6kpaD5TRhXQVzZaxdEpOsdMIw loNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GmCyjO3jMazJwYGiGokKF6SV+kz6Mn0ZPRsnviHfL34=; b=b5Gxib5gd56/us8pcoyH4/9ZX95HRBQ5gewBJT/paS/zHdMA5E7PhwAyNvdNhQNUMq ntDJk0MkXv74gMO0JrJxMqBrKk9b95uFzg7OX2D/XkhCS84Slr9UtM7kRK3jXkGk/x/C QgQow5s5EN3dKXLwrco6pUWBHf306dOXBLO+93hRxxqp+DHGt05dMHtG1bEbdw8Cm2qJ uLN+HEpytYHR42ofRszGvQFtM+GMB6Kmg2ll/qHI04ooNMpmT9Y1Z40VLe8O2TRgwdFQ cE6f5E5dpsogDoJWRdr3V24KuKCvoFXtwK3ZOsYpCJnEoW8uwqJC36oBH96mkob8gzkd L9Lw== X-Gm-Message-State: ACrzQf2OT7/E/P4SHYNp3b2x+yXBa7RUzyQgW23y5dpEECQ/ehpPBZKO nYZQBCav4Z8HkZCzHnhqo26g1UMNZnKQCA== X-Google-Smtp-Source: AMsMyM7GvIVNz9P8rnqeF40QbMF9ROdpzrkSC41B4ESoVLCPQIz1/hEVwQmbSxOHSvemSF83+P9qRw== X-Received: by 2002:a63:e153:0:b0:439:2fa3:74d1 with SMTP id h19-20020a63e153000000b004392fa374d1mr25100404pgk.85.1666554103352; Sun, 23 Oct 2022 12:41:43 -0700 (PDT) Received: from localhost.localdomain ([50.52.121.173]) by smtp.gmail.com with ESMTPSA id q18-20020a170902dad200b00176a2d23d1asm900831plx.56.2022.10.23.12.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 12:41:42 -0700 (PDT) From: Shimmy Shai To: linux-arm-kernel@lists.infradead.org Cc: Shimrra Shai Subject: [PATCH] irqchip/irq-gic-v3-its: add code needed for proper initialization on Firefly ITX-3588J Date: Sun, 23 Oct 2022 12:41:28 -0700 Message-Id: <20221023194128.15113-1-shimmyshai00@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221023_124146_226698_F81A9139 X-CRM114-Status: GOOD ( 18.98 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Given the lack of responses to my post characterizing this as a "draft" and asking about whether the chip/board vendor code's inclusion of this as under the custom, Android-related CONFIG_NO_GKI flag posed an issue to inclusion, I am going to decide it didn't, and assert this to be a full patch. Further research suggested that option appears to select to *not* generate a kernel conforming to certain Android standards, so presumably, this code should be entirely OK to include in a proper Linux kernel. It looks necessary to get proper bootup on the Firefly ITX-3588J board, as else the kernel complains and dies with "its_queue_timeout" errors in early boot. Also, while obtained from vendor-supplied kernel package, I presume it is OK to upload to mainline kernel because of the GPL. (just CMA because I am new to this and have not gotten replies on my other threads) Signed-off-by: Shimrra Shai diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index 973ede0197e3..13d1f1172102 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -2178,6 +2178,9 @@ static struct page *its_allocate_prop_table(gfp_t gfp_flags) { struct page *prop_page; + if (of_machine_is_compatible("rockchip,rk3568") || + of_machine_is_compatible("rockchip,rk3566")) + gfp_flags |= GFP_DMA32; prop_page = alloc_pages(gfp_flags, get_order(LPI_PROPBASE_SZ)); if (!prop_page) return NULL; @@ -2301,6 +2304,7 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser, u32 alloc_pages, psz; struct page *page; void *base; + gfp_t gfp_flags; psz = baser->psz; alloc_pages = (PAGE_ORDER_TO_SIZE(order) / psz); @@ -2312,7 +2316,11 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser, order = get_order(GITS_BASER_PAGES_MAX * psz); } - page = alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, order); + gfp_flags = GFP_KERNEL | __GFP_ZERO; + if (of_machine_is_compatible("rockchip,rk3568") || + of_machine_is_compatible("rockchip,rk3566")) + gfp_flags |= GFP_DMA32; + page = alloc_pages_node(its->numa_node, gfp_flags, order); if (!page) return -ENOMEM; @@ -2359,6 +2367,16 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser, its_write_baser(its, baser, val); tmp = baser->val; + /* note: should not be used in Android GKI */ + if (of_machine_is_compatible("rockchip,rk3568") || + of_machine_is_compatible("rockchip,rk3566") || + of_machine_is_compatible("rockchip,rk3588")) { + if (tmp & GITS_BASER_SHAREABILITY_MASK) + tmp &= ~GITS_BASER_SHAREABILITY_MASK; + else + gic_flush_dcache_to_poc(base, PAGE_ORDER_TO_SIZE(order)); + } + if ((val ^ tmp) & GITS_BASER_SHAREABILITY_MASK) { /* * Shareability didn't stick. Just use @@ -2941,6 +2959,9 @@ static struct page *its_allocate_pending_table(gfp_t gfp_flags) { struct page *pend_page; + if (of_machine_is_compatible("rockchip,rk3568") || + of_machine_is_compatible("rockchip,rk3566")) + gfp_flags |= GFP_DMA32; pend_page = alloc_pages(gfp_flags | __GFP_ZERO, get_order(LPI_PENDBASE_SZ)); if (!pend_page) @@ -3096,6 +3117,12 @@ static void its_cpu_init_lpis(void) gicr_write_propbaser(val, rbase + GICR_PROPBASER); tmp = gicr_read_propbaser(rbase + GICR_PROPBASER); + /* note: should not be used in Android GKI */ + if (of_machine_is_compatible("rockchip,rk3568") || + of_machine_is_compatible("rockchip,rk3566") || + of_machine_is_compatible("rockchip,rk3588")) + tmp &= ~GICR_PROPBASER_SHAREABILITY_MASK; + if ((tmp ^ val) & GICR_PROPBASER_SHAREABILITY_MASK) { if (!(tmp & GICR_PROPBASER_SHAREABILITY_MASK)) { /* @@ -3120,6 +3147,12 @@ static void its_cpu_init_lpis(void) gicr_write_pendbaser(val, rbase + GICR_PENDBASER); tmp = gicr_read_pendbaser(rbase + GICR_PENDBASER); + /* note: should not be used in Android GKI */ + if (of_machine_is_compatible("rockchip,rk3568") || + of_machine_is_compatible("rockchip,rk3566") || + of_machine_is_compatible("rockchip,rk3588")) + tmp &= ~GICR_PENDBASER_SHAREABILITY_MASK; + if (!(tmp & GICR_PENDBASER_SHAREABILITY_MASK)) { /* * The HW reports non-shareable, we must remove the @@ -3283,7 +3316,12 @@ static bool its_alloc_table_entry(struct its_node *its, /* Allocate memory for 2nd level table */ if (!table[idx]) { - page = alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, + gfp_t gfp_flags = GFP_KERNEL | __GFP_ZERO; + + if (of_machine_is_compatible("rockchip,rk3568") || + of_machine_is_compatible("rockchip,rk3566")) + gfp_flags |= GFP_DMA32; + page = alloc_pages_node(its->numa_node, gfp_flags, get_order(baser->psz)); if (!page) return false; @@ -3372,6 +3410,7 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id, int nr_lpis; int nr_ites; int sz; + gfp_t gfp_flags; if (!its_alloc_device_table(its, dev_id)) return NULL; @@ -3387,7 +3426,11 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id, nr_ites = max(2, nvecs); sz = nr_ites * (FIELD_GET(GITS_TYPER_ITT_ENTRY_SIZE, its->typer) + 1); sz = max(sz, ITS_ITT_ALIGN) + ITS_ITT_ALIGN - 1; - itt = kzalloc_node(sz, GFP_KERNEL, its->numa_node); + gfp_flags = GFP_KERNEL; + if (of_machine_is_compatible("rockchip,rk3568") || + of_machine_is_compatible("rockchip,rk3566")) + gfp_flags |= GFP_DMA32; + itt = kzalloc_node(sz, gfp_flags, its->numa_node); if (alloc_lpis) { lpi_map = its_lpi_alloc(nvecs, &lpi_base, &nr_lpis); if (lpi_map) @@ -5011,6 +5054,7 @@ static int __init its_probe_one(struct resource *res, struct page *page; u32 ctlr; int err; + gfp_t gfp_flags; its_base = its_map_one(res, &err); if (!its_base) @@ -5064,7 +5108,11 @@ static int __init its_probe_one(struct resource *res, its->numa_node = numa_node; - page = alloc_pages_node(its->numa_node, GFP_KERNEL | __GFP_ZERO, + gfp_flags = GFP_KERNEL | __GFP_ZERO; + if (of_machine_is_compatible("rockchip,rk3568") || + of_machine_is_compatible("rockchip,rk3566")) + gfp_flags |= GFP_DMA32; + page = alloc_pages_node(its->numa_node, gfp_flags, get_order(ITS_CMD_QUEUE_SZ)); if (!page) { err = -ENOMEM; @@ -5095,6 +5143,12 @@ static int __init its_probe_one(struct resource *res, gits_write_cbaser(baser, its->base + GITS_CBASER); tmp = gits_read_cbaser(its->base + GITS_CBASER); + /* note: should not be used in Android GKI */ + if (of_machine_is_compatible("rockchip,rk3568") || + of_machine_is_compatible("rockchip,rk3566") || + of_machine_is_compatible("rockchip,rk3588")) + tmp &= ~GITS_CBASER_SHAREABILITY_MASK; + if ((tmp ^ baser) & GITS_CBASER_SHAREABILITY_MASK) { if (!(tmp & GITS_CBASER_SHAREABILITY_MASK)) { /*