From 234022fe7ba16b5542d6f9a4be574988413ca6a7 Mon Sep 17 00:00:00 2001 From: davem Date: Mon, 13 Apr 2009 07:06:09 +0000 Subject: [PATCH] * kern/sparc64/ieee1275/ieee1275.c: New file. * include/grub/sparc64/ieee1275/ieee1275.h (IEEE1275_MAP_WRITE, IEEE1275_MAP_READ, IEEE1275_MAP_EXEC, IEEE1275_MAP_LOCKED, IEEE1275_MAP_CACHED, IEEE1275_MAP_SE, IEEE1275_MAP_GLOBAL, IEEE1275_MAP_IE, IEEE1275_MAP_DEFAULT): Define. (grub_ieee1275_map_physical, grub_ieee1275_claim_vaddr, grub_ieee1275_alloc_physmem): Declare new exported functions. --- ChangeLog | 10 ++ DISTLIST | 1 + include/grub/sparc64/ieee1275/ieee1275.h | 22 ++++ kern/sparc64/ieee1275/ieee1275.c | 124 +++++++++++++++++++++++ 4 files changed, 157 insertions(+) create mode 100644 kern/sparc64/ieee1275/ieee1275.c diff --git a/ChangeLog b/ChangeLog index 90864f5cf..0c222adda 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-04-13 David S. Miller + + * kern/sparc64/ieee1275/ieee1275.c: New file. + * include/grub/sparc64/ieee1275/ieee1275.h (IEEE1275_MAP_WRITE, + IEEE1275_MAP_READ, IEEE1275_MAP_EXEC, IEEE1275_MAP_LOCKED, + IEEE1275_MAP_CACHED, IEEE1275_MAP_SE, IEEE1275_MAP_GLOBAL, + IEEE1275_MAP_IE, IEEE1275_MAP_DEFAULT): Define. + (grub_ieee1275_map_physical, grub_ieee1275_claim_vaddr, + grub_ieee1275_alloc_physmem): Declare new exported functions. + 2009-04-12 David S. Miller * kern/misc.c (grub_ltoa): Fix cast when handling negative diff --git a/DISTLIST b/DISTLIST index 1eceb8e48..461600fcf 100644 --- a/DISTLIST +++ b/DISTLIST @@ -380,6 +380,7 @@ kern/powerpc/ieee1275/startup.S kern/sparc64/cache.S kern/sparc64/dl.c kern/sparc64/ieee1275/crt0.S +kern/sparc64/ieee1275/ieee1275.c kern/sparc64/ieee1275/openfw.c kern/x86_64/dl.c kern/x86_64/efi/callwrap.S diff --git a/include/grub/sparc64/ieee1275/ieee1275.h b/include/grub/sparc64/ieee1275/ieee1275.h index 1ef95f91a..7626e93c1 100644 --- a/include/grub/sparc64/ieee1275/ieee1275.h +++ b/include/grub/sparc64/ieee1275/ieee1275.h @@ -24,4 +24,26 @@ typedef grub_uint64_t grub_ieee1275_cell_t; +/* Encoding of 'mode' argument to grub_ieee1275_map_physical() */ +#define IEEE1275_MAP_WRITE 0x0001 /* Writable */ +#define IEEE1275_MAP_READ 0x0002 /* Readable */ +#define IEEE1275_MAP_EXEC 0x0004 /* Executable */ +#define IEEE1275_MAP_LOCKED 0x0010 /* Locked in TLB */ +#define IEEE1275_MAP_CACHED 0x0020 /* Cacheable */ +#define IEEE1275_MAP_SE 0x0040 /* Side-effects */ +#define IEEE1275_MAP_GLOBAL 0x0080 /* Global */ +#define IEEE1275_MAP_IE 0x0100 /* Invert Endianness */ +#define IEEE1275_MAP_DEFAULT (IEEE1275_MAP_WRITE | IEEE1275_MAP_READ | \ + IEEE1275_MAP_EXEC | IEEE1275_MAP_CACHED) + +extern int EXPORT_FUNC(grub_ieee1275_map_physical) (grub_addr_t paddr, + grub_addr_t vaddr, + grub_size_t size, + grub_uint32_t mode); +extern int EXPORT_FUNC(grub_ieee1275_claim_vaddr) (grub_addr_t vaddr, + grub_size_t size); +extern int EXPORT_FUNC(grub_ieee1275_alloc_physmem) (grub_addr_t *paddr, + grub_size_t size, + grub_uint32_t align); + #endif /* ! GRUB_IEEE1275_MACHINE_HEADER */ diff --git a/kern/sparc64/ieee1275/ieee1275.c b/kern/sparc64/ieee1275/ieee1275.c new file mode 100644 index 000000000..438a171ca --- /dev/null +++ b/kern/sparc64/ieee1275/ieee1275.c @@ -0,0 +1,124 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2009 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 + +/* Sun specific ieee1275 interfaces used by GRUB. */ + +int +grub_ieee1275_map_physical (grub_addr_t paddr, grub_addr_t vaddr, + grub_size_t size, grub_uint32_t mode) +{ + struct map_physical_args + { + struct grub_ieee1275_common_hdr common; + grub_ieee1275_cell_t method; + grub_ieee1275_cell_t ihandle; + grub_ieee1275_cell_t mode; + grub_ieee1275_cell_t size; + grub_ieee1275_cell_t virt; + grub_ieee1275_cell_t phys_high; + grub_ieee1275_cell_t phys_low; + grub_ieee1275_cell_t catch_result; + } + args; + + INIT_IEEE1275_COMMON (&args.common, "call-method", 7, 1); + args.method = (grub_ieee1275_cell_t) "map"; + args.ihandle = grub_ieee1275_mmu; + args.mode = mode; + args.size = size; + args.virt = vaddr; + args.phys_high = 0; + args.phys_low = paddr; + args.catch_result = (grub_ieee1275_cell_t) -1; + + if (IEEE1275_CALL_ENTRY_FN (&args) == -1) + return -1; + return args.catch_result; +} + +int +grub_ieee1275_claim_vaddr (grub_addr_t vaddr, grub_size_t size) +{ + struct claim_vaddr_args + { + struct grub_ieee1275_common_hdr common; + grub_ieee1275_cell_t method; + grub_ieee1275_cell_t ihandle; + grub_ieee1275_cell_t align; + grub_ieee1275_cell_t size; + grub_ieee1275_cell_t virt; + grub_ieee1275_cell_t catch_result; + } + args; + + INIT_IEEE1275_COMMON (&args.common, "call-method", 5, 2); + args.method = (grub_ieee1275_cell_t) "claim"; + args.ihandle = grub_ieee1275_mmu; + args.align = 0; + args.size = size; + args.virt = vaddr; + args.catch_result = (grub_ieee1275_cell_t) -1; + + if (IEEE1275_CALL_ENTRY_FN (&args) == -1) + return -1; + return args.catch_result; +} + +int +grub_ieee1275_alloc_physmem (grub_addr_t *paddr, grub_size_t size, + grub_uint32_t align) +{ + grub_uint32_t memory_ihandle; + struct alloc_physmem_args + { + struct grub_ieee1275_common_hdr common; + grub_ieee1275_cell_t method; + grub_ieee1275_cell_t ihandle; + grub_ieee1275_cell_t align; + grub_ieee1275_cell_t size; + grub_ieee1275_cell_t catch_result; + grub_ieee1275_cell_t phys_high; + grub_ieee1275_cell_t phys_low; + } + args; + grub_ssize_t actual = 0; + + grub_ieee1275_get_property (grub_ieee1275_chosen, "memory", + &memory_ihandle, sizeof (memory_ihandle), + &actual); + if (actual != sizeof (memory_ihandle)) + return -1; + + if (!align) + align = 1; + + INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 3); + args.method = (grub_ieee1275_cell_t) "claim"; + args.ihandle = memory_ihandle; + args.align = (align ? align : 1); + args.size = size; + if (IEEE1275_CALL_ENTRY_FN (&args) == -1) + return -1; + + *paddr = args.phys_low; + + return args.catch_result; +}