Skip to content

Instantly share code, notes, and snippets.

@pdp7
Last active May 20, 2023 18:55
Show Gist options
  • Save pdp7/581c9e8415da94a29d34ae6d7cc14669 to your computer and use it in GitHub Desktop.
Save pdp7/581c9e8415da94a29d34ae6d7cc14669 to your computer and use it in GitHub Desktop.
linux-riscv reference: 'git diff' against 3335068f8721 ("riscv: Use PUD/P4D/PGD pages for the linear mapping")
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index f5a668736c79..b066215bbbf2 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -11,6 +11,7 @@
#include <linux/memory.h>
#include <linux/stop_machine.h>
#include "bpf_jit.h"
+#include <asm/patch.h>
#define RV_REG_TCC RV_REG_A6
#define RV_REG_TCC_SAVED RV_REG_S6 /* Store A6 in S6 if program do calls */
diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c
index d1490469184b..b37e69b881ea 100644
--- a/drivers/mmc/host/sdhci-of-dwcmshc.c
+++ b/drivers/mmc/host/sdhci-of-dwcmshc.c
@@ -330,6 +330,11 @@ static void rk35xx_sdhci_reset(struct sdhci_host *host, u8 mask)
sdhci_reset(host, mask);
}
+static void mysoc1_sdhci_reset(struct sdhci_host *host, u8 mask)
+{
+ return;
+}
+
static const struct sdhci_ops sdhci_dwcmshc_ops = {
.set_clock = sdhci_set_clock,
.set_bus_width = sdhci_set_bus_width,
@@ -339,6 +344,15 @@ static const struct sdhci_ops sdhci_dwcmshc_ops = {
.adma_write_desc = dwcmshc_adma_write_desc,
};
+static const struct sdhci_ops sdhci_dwcmshc_mysoc1_ops = {
+ .set_clock = sdhci_set_clock,
+ .set_bus_width = sdhci_set_bus_width,
+ .set_uhs_signaling = dwcmshc_set_uhs_signaling,
+ .get_max_clock = dwcmshc_get_max_clock,
+ .reset = mysoc1_sdhci_reset,
+ .adma_write_desc = dwcmshc_adma_write_desc,
+};
+
static const struct sdhci_ops sdhci_dwcmshc_rk35xx_ops = {
.set_clock = dwcmshc_rk3568_set_clock,
.set_bus_width = sdhci_set_bus_width,
@@ -363,6 +377,13 @@ static const struct sdhci_pltfm_data sdhci_dwcmshc_bf3_pdata = {
};
#endif
+static const struct sdhci_pltfm_data sdhci_dwcmshc_mysoc1_pdata = {
+ .ops = &sdhci_dwcmshc_mysoc1_ops,
+ .quirks = SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN |
+ SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_BROKEN_DMA,
+ .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
+};
+
static const struct sdhci_pltfm_data sdhci_dwcmshc_rk35xx_pdata = {
.ops = &sdhci_dwcmshc_rk35xx_ops,
.quirks = SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN |
@@ -427,6 +448,10 @@ static void dwcmshc_rk35xx_postinit(struct sdhci_host *host, struct dwcmshc_priv
}
static const struct of_device_id sdhci_dwcmshc_dt_ids[] = {
+ {
+ .compatible = "mycorp,mysoc1-dwcmshc",
+ .data = &sdhci_dwcmshc_mysoc1_pdata,
+ },
{
.compatible = "rockchip,rk3588-dwcmshc",
.data = &sdhci_dwcmshc_rk35xx_pdata,
@@ -539,6 +564,9 @@ static int dwcmshc_probe(struct platform_device *pdev)
sdhci_enable_v4_mode(host);
#endif
+ if (pltfm_data == &sdhci_dwcmshc_mysoc1_pdata)
+ sdhci_enable_v4_mode(host);
+
host->mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
err = sdhci_setup_host(host);
@pdp7
Copy link
Author

pdp7 commented May 20, 2023

commit 3335068f87217ea59d08f462187dc856652eea15 (HEAD)
Author: Alexandre Ghiti <alexghiti@rivosinc.com>
Date:   Fri Mar 24 16:54:21 2023 +0100

    riscv: Use PUD/P4D/PGD pages for the linear mapping
    
    During the early page table creation, we used to set the mapping for
    PAGE_OFFSET to the kernel load address: but the kernel load address is
    always offseted by PMD_SIZE which makes it impossible to use PUD/P4D/PGD
    pages as this physical address is not aligned on PUD/P4D/PGD size (whereas
    PAGE_OFFSET is).
    
    But actually we don't have to establish this mapping (ie set va_pa_offset)
    that early in the boot process because:
    
    - first, setup_vm installs a temporary kernel mapping and among other
      things, discovers the system memory,
    - then, setup_vm_final creates the final kernel mapping and takes
      advantage of the discovered system memory to create the linear
      mapping.
    
    During the first phase, we don't know the start of the system memory and
    then until the second phase is finished, we can't use the linear mapping at
    all and phys_to_virt/virt_to_phys translations must not be used because it
    would result in a different translation from the 'real' one once the final
    mapping is installed.
    
    So here we simply delay the initialization of va_pa_offset to after the
    system memory discovery. But to make sure noone uses the linear mapping
    before, we add some guard in the DEBUG_VIRTUAL config.
    
    Finally we can use PUD/P4D/PGD hugepages when possible, which will result
    in a better TLB utilization.
    
    Note that:
    - this does not apply to rv32 as the kernel mapping lies in the linear
      mapping.
    - we rely on the firmware to protect itself using PMP.
    
    Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
    Acked-by: Rob Herring <robh@kernel.org> # DT bits
    Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
    Reviewed-by: Anup Patel <anup@brainfault.org>
    Tested-by: Anup Patel <anup@brainfault.org>
    Link: https://lore.kernel.org/r/20230324155421.271544-4-alexghiti@rivosinc.com
    Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>

@pdp7
Copy link
Author

pdp7 commented May 20, 2023

dfustini@server:~/gitlab/linux$ git status
Refresh index: 100% (79706/79706), done.
HEAD detached at 3335068f8721
You are currently bisecting, started from branch 'b5d68f84f4c6'.
  (use "git bisect reset" to get back to the original branch)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   arch/riscv/net/bpf_jit_comp64.c
	modified:   drivers/mmc/host/sdhci-of-dwcmshc.c

Untracked files:
  (use "git add <file>..." to include in what will be committed)
<snip>


It took 3.11 seconds to enumerate untracked files. 'status -uno'
may speed it up, but you have to be careful not to forget to add
new files yourself (see 'git help status').
no changes added to commit (use "git add" and/or "git commit -a")

@pdp7
Copy link
Author

pdp7 commented May 20, 2023

dfustini@server:~/gitlab/linux$ git diff
diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index f5a668736c79..b066215bbbf2 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -11,6 +11,7 @@
 #include <linux/memory.h>
 #include <linux/stop_machine.h>
 #include "bpf_jit.h"
+#include <asm/patch.h>
 
 #define RV_REG_TCC RV_REG_A6
 #define RV_REG_TCC_SAVED RV_REG_S6 /* Store A6 in S6 if program do calls */
diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c
index d1490469184b..b37e69b881ea 100644
--- a/drivers/mmc/host/sdhci-of-dwcmshc.c
+++ b/drivers/mmc/host/sdhci-of-dwcmshc.c
@@ -330,6 +330,11 @@ static void rk35xx_sdhci_reset(struct sdhci_host *host, u8 mask)
        sdhci_reset(host, mask);
 }
 
+static void mysoc1_sdhci_reset(struct sdhci_host *host, u8 mask)
+{
+       return;
+}
+
 static const struct sdhci_ops sdhci_dwcmshc_ops = {
        .set_clock              = sdhci_set_clock,
        .set_bus_width          = sdhci_set_bus_width,
@@ -339,6 +344,15 @@ static const struct sdhci_ops sdhci_dwcmshc_ops = {
        .adma_write_desc        = dwcmshc_adma_write_desc,
 };
 
+static const struct sdhci_ops sdhci_dwcmshc_mysoc1_ops = {
+       .set_clock              = sdhci_set_clock,
+       .set_bus_width          = sdhci_set_bus_width,
+       .set_uhs_signaling      = dwcmshc_set_uhs_signaling,
+       .get_max_clock          = dwcmshc_get_max_clock,
+       .reset                  = mysoc1_sdhci_reset,
+       .adma_write_desc        = dwcmshc_adma_write_desc,
+};
+
 static const struct sdhci_ops sdhci_dwcmshc_rk35xx_ops = {
        .set_clock              = dwcmshc_rk3568_set_clock,
        .set_bus_width          = sdhci_set_bus_width,
@@ -363,6 +377,13 @@ static const struct sdhci_pltfm_data sdhci_dwcmshc_bf3_pdata = {
 };
 #endif
 
+static const struct sdhci_pltfm_data sdhci_dwcmshc_mysoc1_pdata = {
+       .ops = &sdhci_dwcmshc_mysoc1_ops,
+       .quirks = SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN |
+                 SDHCI_QUIRK_BROKEN_ADMA | SDHCI_QUIRK_BROKEN_DMA,
+       .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
+};
+
 static const struct sdhci_pltfm_data sdhci_dwcmshc_rk35xx_pdata = {
        .ops = &sdhci_dwcmshc_rk35xx_ops,
        .quirks = SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN |
@@ -427,6 +448,10 @@ static void dwcmshc_rk35xx_postinit(struct sdhci_host *host, struct dwcmshc_priv
 }
 
 static const struct of_device_id sdhci_dwcmshc_dt_ids[] = {
+       {
+               .compatible = "mycorp,mysoc1-dwcmshc",
+               .data = &sdhci_dwcmshc_mysoc1_pdata,
+       },
        {
                .compatible = "rockchip,rk3588-dwcmshc",
                .data = &sdhci_dwcmshc_rk35xx_pdata,
@@ -539,6 +564,9 @@ static int dwcmshc_probe(struct platform_device *pdev)
                sdhci_enable_v4_mode(host);
 #endif
 
+       if (pltfm_data == &sdhci_dwcmshc_mysoc1_pdata)
+               sdhci_enable_v4_mode(host);
+
        host->mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
 
        err = sdhci_setup_host(host);
dfustini@server:~/gitlab/linux$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment