From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Eric Snowberg Date: Mon, 26 Feb 2018 17:34:14 -0800 Subject: [PATCH] ieee1275: decode-unit command for 4 addr cell devs decode-unit ( addr len -- phys.lo ... phys.hi ) Convert text unit-string to physical address. Convert unit-string, the text string representation, to phys.lo ... phys.hi, the numerical representation of a physical address within the address space defined by this device node. The number of cells in the list phys.lo ... phys.hi is determined by the value of the #address-cells property of this node. This function is for devices with #address-cells == 4 Signed-off-by: Eric Snowberg Reviewed-by: Daniel Kiper --- grub-core/kern/ieee1275/ieee1275.c | 41 ++++++++++++++++++++++++++++++++++++++ include/grub/ieee1275/ieee1275.h | 7 ++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/grub-core/kern/ieee1275/ieee1275.c b/grub-core/kern/ieee1275/ieee1275.c index 98217029f45..b0ac6f9f9a8 100644 --- a/grub-core/kern/ieee1275/ieee1275.c +++ b/grub-core/kern/ieee1275/ieee1275.c @@ -482,6 +482,47 @@ grub_ieee1275_close (grub_ieee1275_ihandle_t ihandle) return 0; } +int +grub_ieee1275_decode_unit4 (grub_ieee1275_ihandle_t ihandle, + void *addr, grub_size_t size, + grub_uint32_t *phy_lo, grub_uint32_t *phy_hi, + grub_uint32_t *lun_lo, grub_uint32_t *lun_hi) +{ + struct decode_args + { + struct grub_ieee1275_common_hdr common; + grub_ieee1275_cell_t method; + grub_ieee1275_cell_t ihandle; + grub_ieee1275_cell_t size; + grub_ieee1275_cell_t addr; + grub_ieee1275_cell_t catch_result; + grub_ieee1275_cell_t tgt_h; + grub_ieee1275_cell_t tgt_l; + grub_ieee1275_cell_t lun_h; + grub_ieee1275_cell_t lun_l; + } + args; + + INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 5); + args.method = (grub_ieee1275_cell_t) "decode-unit"; + args.ihandle = ihandle; + args.size = size; + args.addr = (grub_ieee1275_cell_t) addr; + args.catch_result = 1; + + if ((IEEE1275_CALL_ENTRY_FN (&args) == -1) || (args.catch_result)) + { + grub_error (GRUB_ERR_OUT_OF_RANGE, "decode-unit failed\n"); + return -1; + } + + *phy_lo = args.tgt_l; + *phy_hi = args.tgt_h; + *lun_lo = args.lun_l; + *lun_hi = args.lun_h; + return 0; +} + int grub_ieee1275_claim (grub_addr_t addr, grub_size_t size, unsigned int align, grub_addr_t *result) diff --git a/include/grub/ieee1275/ieee1275.h b/include/grub/ieee1275/ieee1275.h index 8e425130327..534406458b2 100644 --- a/include/grub/ieee1275/ieee1275.h +++ b/include/grub/ieee1275/ieee1275.h @@ -210,7 +210,12 @@ int EXPORT_FUNC(grub_ieee1275_set_property) (grub_ieee1275_phandle_t phandle, int EXPORT_FUNC(grub_ieee1275_set_color) (grub_ieee1275_ihandle_t ihandle, int index, int r, int g, int b); int EXPORT_FUNC(grub_ieee1275_milliseconds) (grub_uint32_t *msecs); - +int EXPORT_FUNC(grub_ieee1275_decode_unit4) (grub_ieee1275_ihandle_t ihandle, + void *addr, grub_size_t size, + grub_uint32_t *phy_lo, + grub_uint32_t *phy_hi, + grub_uint32_t *lun_lo, + grub_uint32_t *lun_hi); grub_err_t EXPORT_FUNC(grub_claimmap) (grub_addr_t addr, grub_size_t size);