~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/dtc/libfdt/fdt_addresses.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
  2 /*
  3  * libfdt - Flat Device Tree manipulation
  4  * Copyright (C) 2014 David Gibson <david@gibson.dropbear.id.au>
  5  * Copyright (C) 2018 embedded brains GmbH
  6  */
  7 #include "libfdt_env.h"
  8 
  9 #include <fdt.h>
 10 #include <libfdt.h>
 11 
 12 #include "libfdt_internal.h"
 13 
 14 static int fdt_cells(const void *fdt, int nodeoffset, const char *name)
 15 {
 16         const fdt32_t *c;
 17         uint32_t val;
 18         int len;
 19 
 20         c = fdt_getprop(fdt, nodeoffset, name, &len);
 21         if (!c)
 22                 return len;
 23 
 24         if (len != sizeof(*c))
 25                 return -FDT_ERR_BADNCELLS;
 26 
 27         val = fdt32_to_cpu(*c);
 28         if (val > FDT_MAX_NCELLS)
 29                 return -FDT_ERR_BADNCELLS;
 30 
 31         return (int)val;
 32 }
 33 
 34 int fdt_address_cells(const void *fdt, int nodeoffset)
 35 {
 36         int val;
 37 
 38         val = fdt_cells(fdt, nodeoffset, "#address-cells");
 39         if (val == 0)
 40                 return -FDT_ERR_BADNCELLS;
 41         if (val == -FDT_ERR_NOTFOUND)
 42                 return 2;
 43         return val;
 44 }
 45 
 46 int fdt_size_cells(const void *fdt, int nodeoffset)
 47 {
 48         int val;
 49 
 50         val = fdt_cells(fdt, nodeoffset, "#size-cells");
 51         if (val == -FDT_ERR_NOTFOUND)
 52                 return 1;
 53         return val;
 54 }
 55 
 56 /* This function assumes that [address|size]_cells is 1 or 2 */
 57 int fdt_appendprop_addrrange(void *fdt, int parent, int nodeoffset,
 58                              const char *name, uint64_t addr, uint64_t size)
 59 {
 60         int addr_cells, size_cells, ret;
 61         uint8_t data[sizeof(fdt64_t) * 2], *prop;
 62 
 63         ret = fdt_address_cells(fdt, parent);
 64         if (ret < 0)
 65                 return ret;
 66         addr_cells = ret;
 67 
 68         ret = fdt_size_cells(fdt, parent);
 69         if (ret < 0)
 70                 return ret;
 71         size_cells = ret;
 72 
 73         /* check validity of address */
 74         prop = data;
 75         if (addr_cells == 1) {
 76                 if ((addr > UINT32_MAX) || (((uint64_t) UINT32_MAX + 1 - addr) < size))
 77                         return -FDT_ERR_BADVALUE;
 78 
 79                 fdt32_st(prop, (uint32_t)addr);
 80         } else if (addr_cells == 2) {
 81                 fdt64_st(prop, addr);
 82         } else {
 83                 return -FDT_ERR_BADNCELLS;
 84         }
 85 
 86         /* check validity of size */
 87         prop += addr_cells * sizeof(fdt32_t);
 88         if (size_cells == 1) {
 89                 if (size > UINT32_MAX)
 90                         return -FDT_ERR_BADVALUE;
 91 
 92                 fdt32_st(prop, (uint32_t)size);
 93         } else if (size_cells == 2) {
 94                 fdt64_st(prop, size);
 95         } else {
 96                 return -FDT_ERR_BADNCELLS;
 97         }
 98 
 99         return fdt_appendprop(fdt, nodeoffset, name, data,
100                               (addr_cells + size_cells) * sizeof(fdt32_t));
101 }
102 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php