Message ID | 20181114172739.51640-9-agraf@suse.de |
---|---|
State | Superseded |
Headers | show |
Series | Add RISC-V support | expand |
On Wed, 2018-11-14 at 18:27 +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 <agraf@suse.de> > > --- > > v2 -> v3: > > - Fix riscv32 target > --- > grub-core/kern/riscv/cache.c | 64 > +++++++++++++++++++++++++++++ > grub-core/kern/riscv/cache_flush.S | 40 +++++++++++++++++++ > grub-core/kern/riscv/efi/init.c | 82 > ++++++++++++++++++++++++++++++++++++++ > 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, 322 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..15dbe6927 > --- /dev/null > +++ b/grub-core/kern/riscv/cache.c > @@ -0,0 +1,64 @@ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2013 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) > +{ > + /* DMA incoherent devices not supported yet */ > + if (address || len || 1) > + return; > +} > diff --git a/grub-core/kern/riscv/cache_flush.S b/grub- > core/kern/riscv/cache_flush.S > new file mode 100644 > index 000000000..033a8aac3 > --- /dev/null > +++ b/grub-core/kern/riscv/cache_flush.S > @@ -0,0 +1,40 @@ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2013 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) > + // TODO > + ret You can use fence.i here to synchronize writes to instruction memory with instruction fetches. Essentially a instruction cache flush, but different processors may choose different implementations for it. Lukas > diff --git a/grub-core/kern/riscv/efi/init.c b/grub- > core/kern/riscv/efi/init.c > new file mode 100644 > index 000000000..199de08a7 > --- /dev/null > +++ b/grub-core/kern/riscv/efi/init.c > @@ -0,0 +1,82 @@ > +/* init.c - initialize a riscv-based EFI system */ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2013 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 0 > +#if __riscv_xlen == 64 > + asm volatile ("rdtime %0" : "=r" (tmr)); > +#else > + grub_uint32_t lo, hi, tmp; > + asm volatile ( > + "1:\n" > + "rdtimeh %0\n" > + "rdtime %1\n" > + "rdtimeh %2\n" > + "bne %0, %2, 1b" > + : "=&r" (hi), "=&r" (lo), "=&r" (tmp)); > + tmr = ((u64)hi << 32) | lo; > +#endif > +#else > + static grub_uint64_t val; > + tmr = val++; > +#endif > + > + return tmr / timer_frequency_in_khz; > +} > + > + > +void > +grub_machine_init (void) > +{ > + grub_uint64_t time_before, time_after; > + > + grub_efi_init (); > + > + /* Calculate timer frequency */ > + timer_frequency_in_khz = 1; > + time_before = grub_efi_get_time_ms(); > + grub_efi_stall(1000); > + time_after = grub_efi_get_time_ms(); > + timer_frequency_in_khz = time_after - time_before; > + > + grub_install_get_time_ms (grub_efi_get_time_ms); > +} > + > +void > +grub_machine_fini (int flags) > +{ > + if (!(flags & GRUB_LOADER_FLAG_NORETURN)) > + return; > + > + grub_efi_fini (); > +} > diff --git a/include/grub/riscv32/efi/memory.h > b/include/grub/riscv32/efi/memory.h > new file mode 100644 > index 000000000..e61c474ff > --- /dev/null > +++ b/include/grub/riscv32/efi/memory.h > @@ -0,0 +1,6 @@ > +#ifndef GRUB_MEMORY_CPU_HEADER > +#include <grub/efi/memory.h> > + > +#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffUL > + > +#endif /* ! GRUB_MEMORY_CPU_HEADER */ > diff --git a/include/grub/riscv32/time.h > b/include/grub/riscv32/time.h > new file mode 100644 > index 000000000..f9546ec0e > --- /dev/null > +++ b/include/grub/riscv32/time.h > @@ -0,0 +1,28 @@ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2013 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/>. > + */ > + > +#ifndef KERNEL_CPU_TIME_HEADER > +#define KERNEL_CPU_TIME_HEADER 1 > + > +static __inline void > +grub_cpu_idle (void) > +{ > + /* TODO */ > +} > + > +#endif /* ! KERNEL_CPU_TIME_HEADER */ > diff --git a/include/grub/riscv32/types.h > b/include/grub/riscv32/types.h > new file mode 100644 > index 000000000..8c90ce2ec > --- /dev/null > +++ b/include/grub/riscv32/types.h > @@ -0,0 +1,34 @@ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2013 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/>. > + */ > + > +#ifndef GRUB_TYPES_CPU_HEADER > +#define GRUB_TYPES_CPU_HEADER 1 > + > +/* The size of void *. */ > +#define GRUB_TARGET_SIZEOF_VOID_P 4 > + > +/* The size of long. */ > +#define GRUB_TARGET_SIZEOF_LONG 4 > + > +/* currently only support little-endian. */ > +#undef GRUB_TARGET_WORDS_BIGENDIAN > + > +/* Unaligned accesses can be very slow, so avoid them */ > +#undef GRUB_HAVE_UNALIGNED_ACCESS > + > +#endif /* ! GRUB_TYPES_CPU_HEADER */ > diff --git a/include/grub/riscv64/efi/memory.h > b/include/grub/riscv64/efi/memory.h > new file mode 100644 > index 000000000..c6cb32417 > --- /dev/null > +++ b/include/grub/riscv64/efi/memory.h > @@ -0,0 +1,6 @@ > +#ifndef GRUB_MEMORY_CPU_HEADER > +#include <grub/efi/memory.h> > + > +#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL > + > +#endif /* ! GRUB_MEMORY_CPU_HEADER */ > diff --git a/include/grub/riscv64/time.h > b/include/grub/riscv64/time.h > new file mode 100644 > index 000000000..f9546ec0e > --- /dev/null > +++ b/include/grub/riscv64/time.h > @@ -0,0 +1,28 @@ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2013 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/>. > + */ > + > +#ifndef KERNEL_CPU_TIME_HEADER > +#define KERNEL_CPU_TIME_HEADER 1 > + > +static __inline void > +grub_cpu_idle (void) > +{ > + /* TODO */ > +} > + > +#endif /* ! KERNEL_CPU_TIME_HEADER */ > diff --git a/include/grub/riscv64/types.h > b/include/grub/riscv64/types.h > new file mode 100644 > index 000000000..8823bc7d8 > --- /dev/null > +++ b/include/grub/riscv64/types.h > @@ -0,0 +1,34 @@ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2013 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/>. > + */ > + > +#ifndef GRUB_TYPES_CPU_HEADER > +#define GRUB_TYPES_CPU_HEADER 1 > + > +/* The size of void *. */ > +#define GRUB_TARGET_SIZEOF_VOID_P 8 > + > +/* The size of long. */ > +#define GRUB_TARGET_SIZEOF_LONG 8 > + > +/* currently only support little-endian. */ > +#undef GRUB_TARGET_WORDS_BIGENDIAN > + > +/* Unaligned accesses can be very slow, so avoid them */ > +#undef GRUB_HAVE_UNALIGNED_ACCESS > + > +#endif /* ! GRUB_TYPES_CPU_HEADER */ _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
On Wed, Nov 14, 2018 at 06:27:37PM +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 <agraf@suse.de> > > --- > > v2 -> v3: > > - Fix riscv32 target > --- > grub-core/kern/riscv/cache.c | 64 +++++++++++++++++++++++++++++ > grub-core/kern/riscv/cache_flush.S | 40 +++++++++++++++++++ > grub-core/kern/riscv/efi/init.c | 82 ++++++++++++++++++++++++++++++++++++++ > 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, 322 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..15dbe6927 > --- /dev/null > +++ b/grub-core/kern/riscv/cache.c > @@ -0,0 +1,64 @@ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2013 Free Software Foundation, Inc. s/2013/2018/ > + * > + * 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) > +{ > + /* DMA incoherent devices not supported yet */ > + if (address || len || 1) > + return; I think that you can drop the code and leave the comment here. > +} > diff --git a/grub-core/kern/riscv/cache_flush.S b/grub-core/kern/riscv/cache_flush.S > new file mode 100644 > index 000000000..033a8aac3 > --- /dev/null > +++ b/grub-core/kern/riscv/cache_flush.S > @@ -0,0 +1,40 @@ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2013 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 Please do not use "//" for comments. > +FUNCTION(grub_arch_clean_dcache_range) > + // TODO > + ret > + > +// a0 - *beg (inclusive) > +// a1 - *end (exclusive) > +// a2 - line size Ditto. > +FUNCTION(grub_arch_invalidate_icache_range) > + // TODO Ditto. > + 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..199de08a7 > --- /dev/null > +++ b/grub-core/kern/riscv/efi/init.c > @@ -0,0 +1,82 @@ > +/* init.c - initialize a riscv-based EFI system */ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2013 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 0 > +#if __riscv_xlen == 64 > + asm volatile ("rdtime %0" : "=r" (tmr)); > +#else > + grub_uint32_t lo, hi, tmp; > + asm volatile ( > + "1:\n" > + "rdtimeh %0\n" > + "rdtime %1\n" > + "rdtimeh %2\n" > + "bne %0, %2, 1b" > + : "=&r" (hi), "=&r" (lo), "=&r" (tmp)); > + tmr = ((u64)hi << 32) | lo; > +#endif I would drop this piece of dead code. > +#else > + static grub_uint64_t val; > + tmr = val++; > +#endif > + > + return tmr / timer_frequency_in_khz; Could not you use val instead of tmr here? Daniel _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
On 21.11.18 17:02, Daniel Kiper wrote: > On Wed, Nov 14, 2018 at 06:27:37PM +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 <agraf@suse.de> >> >> --- >> >> v2 -> v3: >> >> - Fix riscv32 target >> --- >> grub-core/kern/riscv/cache.c | 64 +++++++++++++++++++++++++++++ >> grub-core/kern/riscv/cache_flush.S | 40 +++++++++++++++++++ >> grub-core/kern/riscv/efi/init.c | 82 ++++++++++++++++++++++++++++++++++++++ >> 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, 322 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..15dbe6927 >> --- /dev/null >> +++ b/grub-core/kern/riscv/cache.c >> @@ -0,0 +1,64 @@ >> +/* >> + * GRUB -- GRand Unified Bootloader >> + * Copyright (C) 2013 Free Software Foundation, Inc. > > s/2013/2018/ > >> + * >> + * 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) >> +{ >> + /* DMA incoherent devices not supported yet */ >> + if (address || len || 1) >> + return; > > I think that you can drop the code and leave the comment here. IIRC I had issues with some gcc versions that complained about unused arguments in that case. > >> +} >> diff --git a/grub-core/kern/riscv/cache_flush.S b/grub-core/kern/riscv/cache_flush.S >> new file mode 100644 >> index 000000000..033a8aac3 >> --- /dev/null >> +++ b/grub-core/kern/riscv/cache_flush.S >> @@ -0,0 +1,40 @@ >> +/* >> + * GRUB -- GRand Unified Bootloader >> + * Copyright (C) 2013 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 > > Please do not use "//" for comments. Ok. > >> +FUNCTION(grub_arch_clean_dcache_range) >> + // TODO >> + ret >> + >> +// a0 - *beg (inclusive) >> +// a1 - *end (exclusive) >> +// a2 - line size > > Ditto. > >> +FUNCTION(grub_arch_invalidate_icache_range) >> + // TODO > > Ditto. > >> + 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..199de08a7 >> --- /dev/null >> +++ b/grub-core/kern/riscv/efi/init.c >> @@ -0,0 +1,82 @@ >> +/* init.c - initialize a riscv-based EFI system */ >> +/* >> + * GRUB -- GRand Unified Bootloader >> + * Copyright (C) 2013 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 0 >> +#if __riscv_xlen == 64 >> + asm volatile ("rdtime %0" : "=r" (tmr)); >> +#else >> + grub_uint32_t lo, hi, tmp; >> + asm volatile ( >> + "1:\n" >> + "rdtimeh %0\n" >> + "rdtime %1\n" >> + "rdtimeh %2\n" >> + "bne %0, %2, 1b" >> + : "=&r" (hi), "=&r" (lo), "=&r" (tmp)); >> + tmr = ((u64)hi << 32) | lo; >> +#endif > > I would drop this piece of dead code. I'd much rather revive the dead code and drop the hack :). Thanks for spotting it! Alex _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
On 17.11.18 23:51, Auer, Lukas wrote: > On Wed, 2018-11-14 at 18:27 +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 <agraf@suse.de> >> >> --- >> >> v2 -> v3: >> >> - Fix riscv32 target >> --- >> grub-core/kern/riscv/cache.c | 64 >> +++++++++++++++++++++++++++++ >> grub-core/kern/riscv/cache_flush.S | 40 +++++++++++++++++++ >> grub-core/kern/riscv/efi/init.c | 82 >> ++++++++++++++++++++++++++++++++++++++ >> 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, 322 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..15dbe6927 >> --- /dev/null >> +++ b/grub-core/kern/riscv/cache.c >> @@ -0,0 +1,64 @@ >> +/* >> + * GRUB -- GRand Unified Bootloader >> + * Copyright (C) 2013 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) >> +{ >> + /* DMA incoherent devices not supported yet */ >> + if (address || len || 1) >> + return; >> +} >> diff --git a/grub-core/kern/riscv/cache_flush.S b/grub- >> core/kern/riscv/cache_flush.S >> new file mode 100644 >> index 000000000..033a8aac3 >> --- /dev/null >> +++ b/grub-core/kern/riscv/cache_flush.S >> @@ -0,0 +1,40 @@ >> +/* >> + * GRUB -- GRand Unified Bootloader >> + * Copyright (C) 2013 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) >> + // TODO >> + ret > > You can use fence.i here to synchronize writes to instruction memory > with instruction fetches. Essentially a instruction cache flush, but > different processors may choose different implementations for it. I suppose that one is implemented by every reasonable core? I'll add it then :). Thanks! Alex _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
On Mon, 2018-11-26 at 00:01 +0100, Alexander Graf wrote: > > On 17.11.18 23:51, Auer, Lukas wrote: > > On Wed, 2018-11-14 at 18:27 +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 <agraf@suse.de> > > > > > > --- > > > > > > v2 -> v3: > > > > > > - Fix riscv32 target > > > --- > > > grub-core/kern/riscv/cache.c | 64 > > > +++++++++++++++++++++++++++++ > > > grub-core/kern/riscv/cache_flush.S | 40 +++++++++++++++++++ > > > grub-core/kern/riscv/efi/init.c | 82 > > > ++++++++++++++++++++++++++++++++++++++ > > > 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, 322 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..15dbe6927 > > > --- /dev/null > > > +++ b/grub-core/kern/riscv/cache.c > > > @@ -0,0 +1,64 @@ > > > +/* > > > + * GRUB -- GRand Unified Bootloader > > > + * Copyright (C) 2013 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) > > > +{ > > > + /* DMA incoherent devices not supported yet */ > > > + if (address || len || 1) > > > + return; > > > +} > > > diff --git a/grub-core/kern/riscv/cache_flush.S b/grub- > > > core/kern/riscv/cache_flush.S > > > new file mode 100644 > > > index 000000000..033a8aac3 > > > --- /dev/null > > > +++ b/grub-core/kern/riscv/cache_flush.S > > > @@ -0,0 +1,40 @@ > > > +/* > > > + * GRUB -- GRand Unified Bootloader > > > + * Copyright (C) 2013 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) > > > + // TODO > > > + ret > > > > You can use fence.i here to synchronize writes to instruction > > memory > > with instruction fetches. Essentially a instruction cache flush, > > but > > different processors may choose different implementations for it. > > I suppose that one is implemented by every reasonable core? I'll add > it > then :). > > > Thanks! > > Alex Yes definitely, the RISC-V Linux kernel would not work without it. Lukas _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel
diff --git a/grub-core/kern/riscv/cache.c b/grub-core/kern/riscv/cache.c new file mode 100644 index 000000000..15dbe6927 --- /dev/null +++ b/grub-core/kern/riscv/cache.c @@ -0,0 +1,64 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2013 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) +{ + /* DMA incoherent devices not supported yet */ + if (address || len || 1) + return; +} diff --git a/grub-core/kern/riscv/cache_flush.S b/grub-core/kern/riscv/cache_flush.S new file mode 100644 index 000000000..033a8aac3 --- /dev/null +++ b/grub-core/kern/riscv/cache_flush.S @@ -0,0 +1,40 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2013 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) + // TODO + 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..199de08a7 --- /dev/null +++ b/grub-core/kern/riscv/efi/init.c @@ -0,0 +1,82 @@ +/* init.c - initialize a riscv-based EFI system */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2013 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 0 +#if __riscv_xlen == 64 + asm volatile ("rdtime %0" : "=r" (tmr)); +#else + grub_uint32_t lo, hi, tmp; + asm volatile ( + "1:\n" + "rdtimeh %0\n" + "rdtime %1\n" + "rdtimeh %2\n" + "bne %0, %2, 1b" + : "=&r" (hi), "=&r" (lo), "=&r" (tmp)); + tmr = ((u64)hi << 32) | lo; +#endif +#else + static grub_uint64_t val; + tmr = val++; +#endif + + return tmr / timer_frequency_in_khz; +} + + +void +grub_machine_init (void) +{ + grub_uint64_t time_before, time_after; + + grub_efi_init (); + + /* Calculate timer frequency */ + timer_frequency_in_khz = 1; + time_before = grub_efi_get_time_ms(); + grub_efi_stall(1000); + time_after = grub_efi_get_time_ms(); + timer_frequency_in_khz = time_after - time_before; + + grub_install_get_time_ms (grub_efi_get_time_ms); +} + +void +grub_machine_fini (int flags) +{ + if (!(flags & GRUB_LOADER_FLAG_NORETURN)) + return; + + grub_efi_fini (); +} diff --git a/include/grub/riscv32/efi/memory.h b/include/grub/riscv32/efi/memory.h new file mode 100644 index 000000000..e61c474ff --- /dev/null +++ b/include/grub/riscv32/efi/memory.h @@ -0,0 +1,6 @@ +#ifndef GRUB_MEMORY_CPU_HEADER +#include <grub/efi/memory.h> + +#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffUL + +#endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/include/grub/riscv32/time.h b/include/grub/riscv32/time.h new file mode 100644 index 000000000..f9546ec0e --- /dev/null +++ b/include/grub/riscv32/time.h @@ -0,0 +1,28 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2013 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/>. + */ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inline void +grub_cpu_idle (void) +{ + /* TODO */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */ diff --git a/include/grub/riscv32/types.h b/include/grub/riscv32/types.h new file mode 100644 index 000000000..8c90ce2ec --- /dev/null +++ b/include/grub/riscv32/types.h @@ -0,0 +1,34 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2013 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/>. + */ + +#ifndef GRUB_TYPES_CPU_HEADER +#define GRUB_TYPES_CPU_HEADER 1 + +/* The size of void *. */ +#define GRUB_TARGET_SIZEOF_VOID_P 4 + +/* The size of long. */ +#define GRUB_TARGET_SIZEOF_LONG 4 + +/* currently only support little-endian. */ +#undef GRUB_TARGET_WORDS_BIGENDIAN + +/* Unaligned accesses can be very slow, so avoid them */ +#undef GRUB_HAVE_UNALIGNED_ACCESS + +#endif /* ! GRUB_TYPES_CPU_HEADER */ diff --git a/include/grub/riscv64/efi/memory.h b/include/grub/riscv64/efi/memory.h new file mode 100644 index 000000000..c6cb32417 --- /dev/null +++ b/include/grub/riscv64/efi/memory.h @@ -0,0 +1,6 @@ +#ifndef GRUB_MEMORY_CPU_HEADER +#include <grub/efi/memory.h> + +#define GRUB_EFI_MAX_USABLE_ADDRESS 0xffffffffffffULL + +#endif /* ! GRUB_MEMORY_CPU_HEADER */ diff --git a/include/grub/riscv64/time.h b/include/grub/riscv64/time.h new file mode 100644 index 000000000..f9546ec0e --- /dev/null +++ b/include/grub/riscv64/time.h @@ -0,0 +1,28 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2013 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/>. + */ + +#ifndef KERNEL_CPU_TIME_HEADER +#define KERNEL_CPU_TIME_HEADER 1 + +static __inline void +grub_cpu_idle (void) +{ + /* TODO */ +} + +#endif /* ! KERNEL_CPU_TIME_HEADER */ diff --git a/include/grub/riscv64/types.h b/include/grub/riscv64/types.h new file mode 100644 index 000000000..8823bc7d8 --- /dev/null +++ b/include/grub/riscv64/types.h @@ -0,0 +1,34 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2013 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/>. + */ + +#ifndef GRUB_TYPES_CPU_HEADER +#define GRUB_TYPES_CPU_HEADER 1 + +/* The size of void *. */ +#define GRUB_TARGET_SIZEOF_VOID_P 8 + +/* The size of long. */ +#define GRUB_TARGET_SIZEOF_LONG 8 + +/* currently only support little-endian. */ +#undef GRUB_TARGET_WORDS_BIGENDIAN + +/* Unaligned accesses can be very slow, so avoid them */ +#undef GRUB_HAVE_UNALIGNED_ACCESS + +#endif /* ! GRUB_TYPES_CPU_HEADER */
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 <agraf@suse.de> --- v2 -> v3: - Fix riscv32 target --- grub-core/kern/riscv/cache.c | 64 +++++++++++++++++++++++++++++ grub-core/kern/riscv/cache_flush.S | 40 +++++++++++++++++++ grub-core/kern/riscv/efi/init.c | 82 ++++++++++++++++++++++++++++++++++++++ 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, 322 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 -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel