mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Trent Piepho <tpiepho@kymetacorp.com>
To: "thepusherpushes@gmail.com" <thepusherpushes@gmail.com>
Cc: "barebox@lists.infradead.org" <barebox@lists.infradead.org>
Subject: Re: [PATCH] Add new command fs2bridge for socfpga
Date: Thu, 27 Jul 2017 18:14:46 +0000	[thread overview]
Message-ID: <1501179286.5146.463.camel@kymetacorp.com> (raw)
In-Reply-To: <CAArhposKY9Ai1OFPX+w2f4ajuw_D8jRTc2tttdiJcO8djj01eg@mail.gmail.com>

On Thu, 2017-07-27 at 18:20 +0200, Mabcded Babcde wrote:
> Hi,
> this patch adds a new command to barebox. It is used to enable or
> disable the fpga-to-sdram bridges on socfpgas. The patch is based on a
> manual from altera

I wonder if this might be better as a settable parameter of the fpga
device?

> +
> +#define SOCFPGA_SYSMGR_ADDRESS    0xFFD08000
> +#define SOCFPGA_SDR_ADDRESS    0xFFC20000
> +
> +#define SDR_CTRLGRP_FPGAPORTRST_ADDRESS    0x5080
> +#define SDR_CTRLGRP_STATICCFG_ADDRESS    0x505C
> +#define SDR_CTRLGRP_STATICCFG_APPLYCFG_MASK    0x00000008
> +
> +#define SYSMGR_FPGAINTF_MODULE    (SOCFPGA_SYSMGR_ADDRESS + 0x28)

You should be able to get these addresses from socfpga-regs.h and
system-manager.h

> +
> +
> +static void socfpga_sdram_apply_staticcfg(void)
> +{
> +    const uint32_t staticcfg = SOCFPGA_SDR_ADDRESS +
> SDR_CTRLGRP_STATICCFG_ADDRESS;
> +    const uint32_t applymask = SDR_CTRLGRP_STATICCFG_APPLYCFG_MASK;
> +    uint32_t val = readl(staticcfg) | applymask;
> +
> +    /*
> +     * SDRAM staticcfg register specific:
> +     * When applying the register setting, the CPU must not access
> +     * SDRAM. Luckily for us, we can abuse i-cache here to help us
> +     * circumvent the SDRAM access issue. The idea is to make sure
> +     * that the code is in one full i-cache line by branching past
> +     * it and back. Once it is in the i-cache, we execute the core
> +     * of the code and apply the register settings.
> +     *
> +     * The code below uses 7 instructions, while the Cortex-A9 has
> +     * 32-byte cachelines, thus the limit is 8 instructions total.
> +     */
> +    asm volatile(
> +        ".align    5            \n"
> +        "    b    2f        \n"
> +        "1:    str    %0,    [%1]    \n"
> +        "    dsb            \n"
> +        "    isb            \n"
> +        "    b    3f        \n"
> +        "2:    b    1b        \n"
> +        "3:    nop            \n"
> +    : : "r"(val), "r"(staticcfg) : "memory", "cc");
> +}
> +
> +
> +int do_f2sbridge(int argc, char *argv[])
> +{
> +    if (argc != 2)
> +        return COMMAND_ERROR_USAGE;
> +
> +    switch (*argv[1]) {
> +    case 'e':    // Enable
> +        // hps peripheral controller to fpga
> +        iowrite32(0, SYSMGR_FPGAINTF_MODULE);

Why disable FPGA access to the emacs?  Is that required too?

> +        socfpga_sdram_apply_staticcfg();
> +        // enable all fpga2sdram bridge ports
> +        iowrite32(0x3fff, SOCFPGA_SDR_ADDRESS +
> SDR_CTRLGRP_FPGAPORTRST_ADDRESS);
> +
> +        break;
> +    case 'd':    // Disable
> +        iowrite32(0, SYSMGR_FPGAINTF_MODULE);
> +        iowrite32(0, SOCFPGA_SDR_ADDRESS + SDR_CTRLGRP_FPGAPORTRST_ADDRESS);
> +        socfpga_sdram_apply_staticcfg();
> +
> +        break;
> +    default:
> +        return COMMAND_ERROR_USAGE;
> +    }
> +
> +    return 0;
> +}
> +
> +
> +BAREBOX_CMD_HELP_START(f2sbridge)
> +BAREBOX_CMD_HELP_TEXT("Options:")
> +BAREBOX_CMD_HELP_OPT ("-e \t",  "enable f2s bridge")
> +BAREBOX_CMD_HELP_OPT ("-d \t",  "disable f2s bridge")
> +BAREBOX_CMD_HELP_END
> +
> +BAREBOX_CMD_START(f2sbridge)
> +    .cmd        = do_f2sbridge,
> +    BAREBOX_CMD_DESC("Enables or disables the fpga2sdram bridge.")
> +    BAREBOX_CMD_GROUP(CMD_GRP_MISC)
> +    BAREBOX_CMD_HELP(cmd_f2sbridge_help)
> +BAREBOX_CMD_END

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2017-07-27 18:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-27 16:20 Mabcded Babcde
2017-07-27 18:14 ` Trent Piepho [this message]
2017-07-28 13:21   ` Mabcded Babcde
2017-07-27 18:49 ` Andrey Smirnov
2017-07-28 13:24   ` Mabcded Babcde
2017-07-28 13:42     ` Andrey Smirnov
2017-07-30 21:17       ` Mabcded Babcde
2017-07-31 16:47         ` Andrey Smirnov
2017-08-01  9:13           ` Steffen Trumtrar
2017-08-01 14:30             ` Mabcded Babcde
2017-08-04 13:13             ` Mabcded Babcde
2017-08-10 15:32               ` Mabcded Babcde
2017-08-17 11:07                 ` Steffen Trumtrar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1501179286.5146.463.camel@kymetacorp.com \
    --to=tpiepho@kymetacorp.com \
    --cc=barebox@lists.infradead.org \
    --cc=thepusherpushes@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox