Changeset View
Changeset View
Standalone View
Standalone View
sys/contrib/libfdt/fdt_addresses.c
/* | /* | ||||
* libfdt - Flat Device Tree manipulation | * libfdt - Flat Device Tree manipulation | ||||
* Copyright (C) 2014 David Gibson <david@gibson.dropbear.id.au> | * Copyright (C) 2014 David Gibson <david@gibson.dropbear.id.au> | ||||
* Copyright (C) 2018 embedded brains GmbH | |||||
* | * | ||||
* libfdt is dual licensed: you can use it either under the terms of | * libfdt is dual licensed: you can use it either under the terms of | ||||
* the GPL, or the BSD license, at your option. | * the GPL, or the BSD license, at your option. | ||||
* | * | ||||
* a) This library is free software; you can redistribute it and/or | * a) This library is free software; you can redistribute it and/or | ||||
* modify it under the terms of the GNU General Public License as | * modify it under the terms of the GNU General Public License as | ||||
* published by the Free Software Foundation; either version 2 of the | * published by the Free Software Foundation; either version 2 of the | ||||
* License, or (at your option) any later version. | * License, or (at your option) any later version. | ||||
Show All 38 Lines | |||||
*/ | */ | ||||
#include "libfdt_env.h" | #include "libfdt_env.h" | ||||
#include <fdt.h> | #include <fdt.h> | ||||
#include <libfdt.h> | #include <libfdt.h> | ||||
#include "libfdt_internal.h" | #include "libfdt_internal.h" | ||||
int fdt_address_cells(const void *fdt, int nodeoffset) | static int fdt_cells(const void *fdt, int nodeoffset, const char *name) | ||||
{ | { | ||||
const fdt32_t *ac; | const fdt32_t *c; | ||||
int val; | int val; | ||||
int len; | int len; | ||||
ac = fdt_getprop(fdt, nodeoffset, "#address-cells", &len); | c = fdt_getprop(fdt, nodeoffset, name, &len); | ||||
if (!ac) | if (!c) | ||||
return 2; | return len; | ||||
if (len != sizeof(*ac)) | if (len != sizeof(*c)) | ||||
return -FDT_ERR_BADNCELLS; | return -FDT_ERR_BADNCELLS; | ||||
val = fdt32_to_cpu(*ac); | val = fdt32_to_cpu(*c); | ||||
if ((val <= 0) || (val > FDT_MAX_NCELLS)) | if ((val <= 0) || (val > FDT_MAX_NCELLS)) | ||||
return -FDT_ERR_BADNCELLS; | return -FDT_ERR_BADNCELLS; | ||||
return val; | return val; | ||||
} | } | ||||
int fdt_size_cells(const void *fdt, int nodeoffset) | int fdt_address_cells(const void *fdt, int nodeoffset) | ||||
{ | { | ||||
const fdt32_t *sc; | |||||
int val; | int val; | ||||
int len; | |||||
sc = fdt_getprop(fdt, nodeoffset, "#size-cells", &len); | val = fdt_cells(fdt, nodeoffset, "#address-cells"); | ||||
if (!sc) | if (val == -FDT_ERR_NOTFOUND) | ||||
return 2; | return 2; | ||||
return val; | |||||
} | |||||
if (len != sizeof(*sc)) | int fdt_size_cells(const void *fdt, int nodeoffset) | ||||
return -FDT_ERR_BADNCELLS; | { | ||||
int val; | |||||
val = fdt32_to_cpu(*sc); | val = fdt_cells(fdt, nodeoffset, "#size-cells"); | ||||
if ((val < 0) || (val > FDT_MAX_NCELLS)) | if (val == -FDT_ERR_NOTFOUND) | ||||
return -FDT_ERR_BADNCELLS; | return 1; | ||||
return val; | return val; | ||||
} | } |