mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-10 23:24:38 +00:00
dm: core: add functions to get/remap I/O addresses by name
This functions allow us to get and remap I/O addresses by name, which is useful when there are multiple reg addresses indexed by reg-names property. This is needed in bmips dma/eth patch series, but can also be used on many other drivers. Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com> Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
bb48470df2
commit
7959882049
6 changed files with 160 additions and 2 deletions
|
@ -690,6 +690,7 @@
|
||||||
dev@0,0 {
|
dev@0,0 {
|
||||||
compatible = "denx,u-boot-fdt-dummy";
|
compatible = "denx,u-boot-fdt-dummy";
|
||||||
reg = <0 0x0 0x1000>;
|
reg = <0 0x0 0x1000>;
|
||||||
|
reg-names = "sandbox-dummy-0";
|
||||||
};
|
};
|
||||||
|
|
||||||
dev@1,100 {
|
dev@1,100 {
|
||||||
|
|
|
@ -146,6 +146,16 @@ void *devfdt_remap_addr_index(struct udevice *dev, int index)
|
||||||
return map_physmem(addr, 0, MAP_NOCACHE);
|
return map_physmem(addr, 0, MAP_NOCACHE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *devfdt_remap_addr_name(struct udevice *dev, const char *name)
|
||||||
|
{
|
||||||
|
fdt_addr_t addr = devfdt_get_addr_name(dev, name);
|
||||||
|
|
||||||
|
if (addr == FDT_ADDR_T_NONE)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return map_physmem(addr, 0, MAP_NOCACHE);
|
||||||
|
}
|
||||||
|
|
||||||
void *devfdt_remap_addr(struct udevice *dev)
|
void *devfdt_remap_addr(struct udevice *dev)
|
||||||
{
|
{
|
||||||
return devfdt_remap_addr_index(dev, 0);
|
return devfdt_remap_addr_index(dev, 0);
|
||||||
|
|
|
@ -69,6 +69,26 @@ void *dev_remap_addr_index(struct udevice *dev, int index)
|
||||||
return map_physmem(addr, 0, MAP_NOCACHE);
|
return map_physmem(addr, 0, MAP_NOCACHE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fdt_addr_t dev_read_addr_name(struct udevice *dev, const char *name)
|
||||||
|
{
|
||||||
|
int index = dev_read_stringlist_search(dev, "reg-names", name);
|
||||||
|
|
||||||
|
if (index < 0)
|
||||||
|
return FDT_ADDR_T_NONE;
|
||||||
|
else
|
||||||
|
return dev_read_addr_index(dev, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *dev_remap_addr_name(struct udevice *dev, const char *name)
|
||||||
|
{
|
||||||
|
fdt_addr_t addr = dev_read_addr_name(dev, name);
|
||||||
|
|
||||||
|
if (addr == FDT_ADDR_T_NONE)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return map_physmem(addr, 0, MAP_NOCACHE);
|
||||||
|
}
|
||||||
|
|
||||||
fdt_addr_t dev_read_addr(struct udevice *dev)
|
fdt_addr_t dev_read_addr(struct udevice *dev)
|
||||||
{
|
{
|
||||||
return dev_read_addr_index(dev, 0);
|
return dev_read_addr_index(dev, 0);
|
||||||
|
|
|
@ -55,6 +55,19 @@ void *devfdt_remap_addr(struct udevice *dev);
|
||||||
*/
|
*/
|
||||||
void *devfdt_remap_addr_index(struct udevice *dev, int index);
|
void *devfdt_remap_addr_index(struct udevice *dev, int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* devfdt_remap_addr_name() - Get the reg property of a device, indexed by
|
||||||
|
* name, as a memory-mapped I/O pointer
|
||||||
|
* @name: the 'reg' property can hold a list of <addr, size> pairs, with the
|
||||||
|
* 'reg-names' property providing named-based identification. @index
|
||||||
|
* indicates the value to search for in 'reg-names'.
|
||||||
|
*
|
||||||
|
* @dev: Pointer to a device
|
||||||
|
*
|
||||||
|
* @return Pointer to addr, or NULL if there is no such property
|
||||||
|
*/
|
||||||
|
void *devfdt_remap_addr_name(struct udevice *dev, const char *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* devfdt_map_physmem() - Read device address from reg property of the
|
* devfdt_map_physmem() - Read device address from reg property of the
|
||||||
* device node and map the address into CPU address
|
* device node and map the address into CPU address
|
||||||
|
|
|
@ -124,6 +124,31 @@ fdt_addr_t dev_read_addr_index(struct udevice *dev, int index);
|
||||||
*/
|
*/
|
||||||
void *dev_remap_addr_index(struct udevice *dev, int index);
|
void *dev_remap_addr_index(struct udevice *dev, int index);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dev_read_addr_name() - Get the reg property of a device, indexed by name
|
||||||
|
*
|
||||||
|
* @dev: Device to read from
|
||||||
|
* @name: the 'reg' property can hold a list of <addr, size> pairs, with the
|
||||||
|
* 'reg-names' property providing named-based identification. @index
|
||||||
|
* indicates the value to search for in 'reg-names'.
|
||||||
|
*
|
||||||
|
* @return address or FDT_ADDR_T_NONE if not found
|
||||||
|
*/
|
||||||
|
fdt_addr_t dev_read_addr_name(struct udevice *dev, const char* name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dev_remap_addr_name() - Get the reg property of a device, indexed by name,
|
||||||
|
* as a memory-mapped I/O pointer
|
||||||
|
*
|
||||||
|
* @dev: Device to read from
|
||||||
|
* @name: the 'reg' property can hold a list of <addr, size> pairs, with the
|
||||||
|
* 'reg-names' property providing named-based identification. @index
|
||||||
|
* indicates the value to search for in 'reg-names'.
|
||||||
|
*
|
||||||
|
* @return pointer or NULL if not found
|
||||||
|
*/
|
||||||
|
void *dev_remap_addr_name(struct udevice *dev, const char* name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dev_read_addr() - Get the reg property of a device
|
* dev_read_addr() - Get the reg property of a device
|
||||||
*
|
*
|
||||||
|
@ -494,6 +519,12 @@ static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
|
||||||
return devfdt_get_addr_index(dev, index);
|
return devfdt_get_addr_index(dev, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline fdt_addr_t dev_read_addr_name(struct udevice *dev,
|
||||||
|
const char *name)
|
||||||
|
{
|
||||||
|
return devfdt_get_addr_name(dev, name);
|
||||||
|
}
|
||||||
|
|
||||||
static inline fdt_addr_t dev_read_addr(struct udevice *dev)
|
static inline fdt_addr_t dev_read_addr(struct udevice *dev)
|
||||||
{
|
{
|
||||||
return devfdt_get_addr(dev);
|
return devfdt_get_addr(dev);
|
||||||
|
@ -514,6 +545,11 @@ static inline void *dev_remap_addr_index(struct udevice *dev, int index)
|
||||||
return devfdt_remap_addr_index(dev, index);
|
return devfdt_remap_addr_index(dev, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void *dev_remap_addr_name(struct udevice *dev, const char *name)
|
||||||
|
{
|
||||||
|
return devfdt_remap_addr_name(dev, name);
|
||||||
|
}
|
||||||
|
|
||||||
static inline fdt_addr_t dev_read_addr_size(struct udevice *dev,
|
static inline fdt_addr_t dev_read_addr_size(struct udevice *dev,
|
||||||
const char *propname,
|
const char *propname,
|
||||||
fdt_size_t *sizep)
|
fdt_size_t *sizep)
|
||||||
|
|
|
@ -490,7 +490,6 @@ static int dm_test_fdt_translation(struct unit_test_state *uts)
|
||||||
}
|
}
|
||||||
DM_TEST(dm_test_fdt_translation, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
|
DM_TEST(dm_test_fdt_translation, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
|
||||||
|
|
||||||
/* Test devfdt_remap_addr_index() */
|
|
||||||
static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts)
|
static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts)
|
||||||
{
|
{
|
||||||
struct udevice *dev;
|
struct udevice *dev;
|
||||||
|
@ -511,7 +510,46 @@ static int dm_test_fdt_remap_addr_flat(struct unit_test_state *uts)
|
||||||
DM_TEST(dm_test_fdt_remap_addr_flat,
|
DM_TEST(dm_test_fdt_remap_addr_flat,
|
||||||
DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
|
DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
|
||||||
|
|
||||||
/* Test dev_remap_addr_index() */
|
static int dm_test_fdt_remap_addr_index_flat(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
struct udevice *dev;
|
||||||
|
fdt_addr_t addr;
|
||||||
|
void *paddr;
|
||||||
|
|
||||||
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
|
||||||
|
|
||||||
|
addr = devfdt_get_addr_index(dev, 0);
|
||||||
|
ut_asserteq(0x8000, addr);
|
||||||
|
|
||||||
|
paddr = map_physmem(addr, 0, MAP_NOCACHE);
|
||||||
|
ut_assertnonnull(paddr);
|
||||||
|
ut_asserteq_ptr(paddr, devfdt_remap_addr_index(dev, 0));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
DM_TEST(dm_test_fdt_remap_addr_index_flat,
|
||||||
|
DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
|
||||||
|
|
||||||
|
static int dm_test_fdt_remap_addr_name_flat(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
struct udevice *dev;
|
||||||
|
fdt_addr_t addr;
|
||||||
|
void *paddr;
|
||||||
|
|
||||||
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
|
||||||
|
|
||||||
|
addr = devfdt_get_addr_name(dev, "sandbox-dummy-0");
|
||||||
|
ut_asserteq(0x8000, addr);
|
||||||
|
|
||||||
|
paddr = map_physmem(addr, 0, MAP_NOCACHE);
|
||||||
|
ut_assertnonnull(paddr);
|
||||||
|
ut_asserteq_ptr(paddr, devfdt_remap_addr_name(dev, "sandbox-dummy-0"));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
DM_TEST(dm_test_fdt_remap_addr_name_flat,
|
||||||
|
DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
|
||||||
|
|
||||||
static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts)
|
static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts)
|
||||||
{
|
{
|
||||||
struct udevice *dev;
|
struct udevice *dev;
|
||||||
|
@ -532,6 +570,46 @@ static int dm_test_fdt_remap_addr_live(struct unit_test_state *uts)
|
||||||
DM_TEST(dm_test_fdt_remap_addr_live,
|
DM_TEST(dm_test_fdt_remap_addr_live,
|
||||||
DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
|
DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
|
||||||
|
|
||||||
|
static int dm_test_fdt_remap_addr_index_live(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
struct udevice *dev;
|
||||||
|
fdt_addr_t addr;
|
||||||
|
void *paddr;
|
||||||
|
|
||||||
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
|
||||||
|
|
||||||
|
addr = dev_read_addr_index(dev, 0);
|
||||||
|
ut_asserteq(0x8000, addr);
|
||||||
|
|
||||||
|
paddr = map_physmem(addr, 0, MAP_NOCACHE);
|
||||||
|
ut_assertnonnull(paddr);
|
||||||
|
ut_asserteq_ptr(paddr, dev_remap_addr_index(dev, 0));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
DM_TEST(dm_test_fdt_remap_addr_index_live,
|
||||||
|
DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
|
||||||
|
|
||||||
|
static int dm_test_fdt_remap_addr_name_live(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
struct udevice *dev;
|
||||||
|
fdt_addr_t addr;
|
||||||
|
void *paddr;
|
||||||
|
|
||||||
|
ut_assertok(uclass_find_device_by_seq(UCLASS_TEST_DUMMY, 0, true, &dev));
|
||||||
|
|
||||||
|
addr = dev_read_addr_name(dev, "sandbox-dummy-0");
|
||||||
|
ut_asserteq(0x8000, addr);
|
||||||
|
|
||||||
|
paddr = map_physmem(addr, 0, MAP_NOCACHE);
|
||||||
|
ut_assertnonnull(paddr);
|
||||||
|
ut_asserteq_ptr(paddr, dev_remap_addr_name(dev, "sandbox-dummy-0"));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
DM_TEST(dm_test_fdt_remap_addr_name_live,
|
||||||
|
DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
|
||||||
|
|
||||||
static int dm_test_fdt_livetree_writing(struct unit_test_state *uts)
|
static int dm_test_fdt_livetree_writing(struct unit_test_state *uts)
|
||||||
{
|
{
|
||||||
struct udevice *dev;
|
struct udevice *dev;
|
||||||
|
|
Loading…
Reference in a new issue