From patchwork Tue Nov 6 17:58:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 150334 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp4206268ljp; Tue, 6 Nov 2018 10:10:51 -0800 (PST) X-Google-Smtp-Source: AJdET5cCJzdCHL08T7C6JRGWEdRIJa6hnDXp/X6Fgu2E/6/DdKiDfIWQCO9OYAa6bodij/udkqk7 X-Received: by 2002:a0c:9e05:: with SMTP id p5mr26594822qve.246.1541527851776; Tue, 06 Nov 2018 10:10:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541527851; cv=none; d=google.com; s=arc-20160816; b=mfUTXYJ7UhuKwrIuKjQNKUKxiFpY5woSiCwy47SJrp1Owi+bVcNuPt4zud7XjUkOtg nNHuNIplO8kytfySMLdk1WGCTdtEePqC42Za81tWtLnDZAowKa0YRQNklZH0WqcJg6XY IkIHGOJkdONpdzeESkN7iXdusbn7FSWqYuql25bpRexWrAS4CRPkMe50gKZbBRdAdrEy +3HKR4Oo7AM+T1G3KdvfOf7qVtlxzfuJTi20xMdl06mVjG6N7x0ZNZlCdZr0ZWoKPilV DKLrLNIhyQbmdYVeZ00RnxOguIO7LGInffgtsdV0lSrJA0DyaheLzi28LiYgsRs2aXiq wdZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=U3hUQh3M+uVcETfYhR6szmBefbRd1Ewx32wqXTRAAmg=; b=rYuumAJXEA3B0Ri6kCnfLGVE7u9+yBBB8qBZUyechdVAJpYQwTirxGlMyT08ZIa4A3 Hm6n2a6UmcTAFMQC9WDCioX/Ovb8USVbE92AtQmYAIbtOg/evfwaTyN2PAWygufmDA8E N61Zy9m9Cew2KjgXkzjn2k7/pY8Brk0ngdJ+ViIShZRhGmlY3cpLHDQHtHv/s5ItcbFz kEjiQ7VRrQ1blteewWEcRdO7fu1f72F2oPvhXu793SNFQ0yKXKFs+06QRxHlCJ9axYO2 tl1vb9YUjqPuuKSWimzkIpJnLRpHa2+fqcZxN4aApv8RghfXp4cdXl2ym5E8L2rBvV/o OMeA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g16si700390qvj.149.2018.11.06.10.10.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 06 Nov 2018 10:10:51 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([::1]:42446 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK5oQ-0000TJ-Q5 for patch@linaro.org; Tue, 06 Nov 2018 13:10:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38816) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK5nc-0007zJ-RJ for grub-devel@gnu.org; Tue, 06 Nov 2018 13:10:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gK5cu-0003Uy-5r for grub-devel@gnu.org; Tue, 06 Nov 2018 12:58:58 -0500 Received: from mx2.suse.de ([195.135.220.15]:38208 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gK5cr-0003Q1-W8 for grub-devel@gnu.org; Tue, 06 Nov 2018 12:58:54 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 99C8BAE77; Tue, 6 Nov 2018 17:58:39 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH 8/9] RISC-V: Add auxiliary files Date: Tue, 6 Nov 2018 18:58:36 +0100 Message-Id: <20181106175837.9083-9-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20181106175837.9083-1-agraf@suse.de> References: <20181106175837.9083-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" 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 --- 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 diff --git a/grub-core/kern/riscv/cache.c b/grub-core/kern/riscv/cache.c new file mode 100644 index 000000000..5157fef10 --- /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 . + */ + +#include +#include + +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_uint64_t line_size); +void grub_arch_invalidate_icache_range (grub_addr_t beg, grub_addr_t end, + grub_uint64_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_uint64_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_uint64_t) address, max_align); + end = ALIGN_UP ((grub_uint64_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 . + */ + +#include + + .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 . + */ + +#include +#include +#include +#include +#include +#include +#include + +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 + +#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 . + */ + +#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 . + */ + +#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 + +#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 . + */ + +#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 . + */ + +#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 */