[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 08/10] RISC-V: Add auxiliary files
From: |
Daniel Kiper |
Subject: |
Re: [PATCH v4 08/10] RISC-V: Add auxiliary files |
Date: |
Thu, 17 Jan 2019 13:47:05 +0100 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Mon, Nov 26, 2018 at 12:38:13AM +0100, Alexander Graf wrote:
> To support a new architecture we need to provide a few helper functions
> for memory, cache, timer, etc support.
>
> This patch adds the remainders of those. Some bits are still disabled,
> as I couldn't guarantee that we're always running on models / in modes
> where the respective hardware is available.
>
> Signed-off-by: Alexander Graf <address@hidden>
>
> ---
>
> v2 -> v3:
>
> - Fix riscv32 target
>
> v3 -> v4:
>
> - Change copyright from 2013 to 2018
> - Fix coding style
> - Resurrect time reading code
> - Add fence.i for icache flush
> ---
> grub-core/kern/riscv/cache.c | 64 +++++++++++++++++++++++++++++++
> grub-core/kern/riscv/cache_flush.S | 44 ++++++++++++++++++++++
> grub-core/kern/riscv/efi/init.c | 77
> ++++++++++++++++++++++++++++++++++++++
> include/grub/riscv32/efi/memory.h | 6 +++
> include/grub/riscv32/time.h | 28 ++++++++++++++
> include/grub/riscv32/types.h | 34 +++++++++++++++++
> include/grub/riscv64/efi/memory.h | 6 +++
> include/grub/riscv64/time.h | 28 ++++++++++++++
> include/grub/riscv64/types.h | 34 +++++++++++++++++
> 9 files changed, 321 insertions(+)
> create mode 100644 grub-core/kern/riscv/cache.c
> create mode 100644 grub-core/kern/riscv/cache_flush.S
> create mode 100644 grub-core/kern/riscv/efi/init.c
> create mode 100644 include/grub/riscv32/efi/memory.h
> create mode 100644 include/grub/riscv32/time.h
> create mode 100644 include/grub/riscv32/types.h
> create mode 100644 include/grub/riscv64/efi/memory.h
> create mode 100644 include/grub/riscv64/time.h
> create mode 100644 include/grub/riscv64/types.h
>
> diff --git a/grub-core/kern/riscv/cache.c b/grub-core/kern/riscv/cache.c
> new file mode 100644
> index 000000000..7e04d2e06
> --- /dev/null
> +++ b/grub-core/kern/riscv/cache.c
> @@ -0,0 +1,64 @@
> +/*
> + * GRUB -- GRand Unified Bootloader
> + * Copyright (C) 2018 Free Software Foundation, Inc.
> + *
> + * GRUB 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 3 of the License, or
> + * (at your option) any later version.
> + *
> + * GRUB 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.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <grub/cache.h>
> +#include <grub/misc.h>
> +
> +static grub_int64_t dlinesz;
> +static grub_int64_t ilinesz;
> +
> +/* Prototypes for asm functions. */
> +void grub_arch_clean_dcache_range (grub_addr_t beg, grub_addr_t end,
> + grub_size_t line_size);
> +void grub_arch_invalidate_icache_range (grub_addr_t beg, grub_addr_t end,
> + grub_size_t line_size);
> +
> +static void
> +probe_caches (void)
> +{
> + /* TODO */
> + dlinesz = 32;
> + ilinesz = 32;
> +}
> +
> +void
> +grub_arch_sync_caches (void *address, grub_size_t len)
> +{
> + grub_size_t start, end, max_align;
> +
> + if (dlinesz == 0)
> + probe_caches();
> + if (dlinesz == 0)
> + grub_fatal ("Unknown cache line size!");
> +
> + max_align = dlinesz > ilinesz ? dlinesz : ilinesz;
> +
> + start = ALIGN_DOWN ((grub_size_t) address, max_align);
> + end = ALIGN_UP ((grub_size_t) address + len, max_align);
> +
> + grub_arch_clean_dcache_range (start, end, dlinesz);
> + grub_arch_invalidate_icache_range (start, end, ilinesz);
> +}
> +
> +void
> +grub_arch_sync_dma_caches (volatile void *address, grub_size_t len)
grub_arch_sync_dma_caches (volatile void *address __attribute__((unused)),
grub_size_t len __attribute__((unused)))
> +{
> + /* DMA incoherent devices not supported yet */
> + if (address || len || 1)
> + return;
And please drop this code. Comment may stay as is if needed.
> +}
> diff --git a/grub-core/kern/riscv/cache_flush.S
> b/grub-core/kern/riscv/cache_flush.S
> new file mode 100644
> index 000000000..41de6e411
> --- /dev/null
> +++ b/grub-core/kern/riscv/cache_flush.S
> @@ -0,0 +1,44 @@
> +/*
> + * GRUB -- GRand Unified Bootloader
> + * Copyright (C) 2018 Free Software Foundation, Inc.
> + *
> + * GRUB 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 3 of the License, or
> + * (at your option) any later version.
> + *
> + * GRUB 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.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <grub/symbol.h>
> +
> + .file "cache_flush.S"
> + .text
> +
> +/*
> + * Simple cache maintenance functions
> + */
> +
> +/*
> + * a0 - *beg (inclusive)
> + * a1 - *end (exclusive)
> + * a2 - line size
> +*/
> +FUNCTION(grub_arch_clean_dcache_range)
> + /* TODO */
> + ret
> +
> +/*
> + * a0 - *beg (inclusive)
> + * a1 - *end (exclusive)
> + * a2 - line size
> + */
> +FUNCTION(grub_arch_invalidate_icache_range)
> + fence.i
> + ret
> diff --git a/grub-core/kern/riscv/efi/init.c b/grub-core/kern/riscv/efi/init.c
> new file mode 100644
> index 000000000..81a724155
> --- /dev/null
> +++ b/grub-core/kern/riscv/efi/init.c
> @@ -0,0 +1,77 @@
> +/* init.c - initialize a riscv-based EFI system */
> +/*
> + * GRUB -- GRand Unified Bootloader
> + * Copyright (C) 2018 Free Software Foundation, Inc.
> + *
> + * GRUB 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 3 of the License, or
> + * (at your option) any later version.
> + *
> + * GRUB 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.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <grub/env.h>
> +#include <grub/kernel.h>
> +#include <grub/misc.h>
> +#include <grub/mm.h>
> +#include <grub/time.h>
> +#include <grub/efi/efi.h>
> +#include <grub/loader.h>
> +
> +static grub_uint64_t timer_frequency_in_khz;
> +
> +static grub_uint64_t
> +grub_efi_get_time_ms (void)
> +{
> + grub_uint64_t tmr;
> +
> +#if __riscv_xlen == 64
> + asm volatile ("rdcycle %0" : "=r" (tmr));
> +#else
> + grub_uint32_t lo, hi, tmp;
> + asm volatile (
> + "1:\n"
> + "rdcycleh %0\n"
> + "rdcycle %1\n"
> + "rdcycleh %2\n"
> + "bne %0, %2, 1b"
> + : "=&r" (hi), "=&r" (lo), "=&r" (tmp));
> + tmr = ((u64)hi << 32) | lo;
> +#endif
> +
> + return tmr / timer_frequency_in_khz;
> +}
> +
> +
Please drop this extra empty line.
Daniel
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [PATCH v4 08/10] RISC-V: Add auxiliary files,
Daniel Kiper <=