mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-27 16:01:27 +00:00
rng: detect RISC-V Zkr RNG device in bind method
The existence of devices should be checked in the bind method and not in
the probe method. Adjust the RISC-V Zkr RNG driver accordingly.
Use ENOENT (and not ENODEV) to signal that the device is not available.
Fixes: ceec977ba1
("rng: Provide a RNG based on the RISC-V Zkr ISA extension")
Reported-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
This commit is contained in:
parent
badef4cd4a
commit
1351cd3b4b
1 changed files with 26 additions and 8 deletions
|
@ -55,7 +55,7 @@ static int riscv_zkr_read(struct udevice *dev, void *data, size_t len)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DEAD:
|
case DEAD:
|
||||||
return -ENODEV;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,16 +63,16 @@ static int riscv_zkr_read(struct udevice *dev, void *data, size_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* riscv_zkr_probe() - check if the seed register is available
|
* riscv_zkr_bind() - check if the seed register is available
|
||||||
*
|
*
|
||||||
* If the SBI software has not set mseccfg.sseed=1 or the Zkr
|
* If the SBI software has not set mseccfg.sseed=1 or the Zkr extension is not
|
||||||
* extension is not available this probe function will result
|
* available, reading the seed register will result in an exception from which
|
||||||
* in an exception. Currently we cannot recover from this.
|
* this function safely resumes.
|
||||||
*
|
*
|
||||||
* @dev: RNG device
|
* @dev: RNG device
|
||||||
* Return: 0 if successfully probed
|
* Return: 0 if successfully probed
|
||||||
*/
|
*/
|
||||||
static int riscv_zkr_probe(struct udevice *dev)
|
static int riscv_zkr_bind(struct udevice *dev)
|
||||||
{
|
{
|
||||||
struct resume_data resume;
|
struct resume_data resume;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -87,7 +87,24 @@ static int riscv_zkr_probe(struct udevice *dev)
|
||||||
val = read_seed();
|
val = read_seed();
|
||||||
set_resume(NULL);
|
set_resume(NULL);
|
||||||
if (ret)
|
if (ret)
|
||||||
return -ENODEV;
|
return -ENOENT;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* riscv_zkr_probe() - check if entropy is available
|
||||||
|
*
|
||||||
|
* The bind method already checked that the seed register can be read without
|
||||||
|
* excpetiong. Here we wait for the self test to finish and entropy becoming
|
||||||
|
* available.
|
||||||
|
*
|
||||||
|
* @dev: RNG device
|
||||||
|
* Return: 0 if successfully probed
|
||||||
|
*/
|
||||||
|
static int riscv_zkr_probe(struct udevice *dev)
|
||||||
|
{
|
||||||
|
u32 val;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
val = read_seed();
|
val = read_seed();
|
||||||
|
@ -95,7 +112,7 @@ static int riscv_zkr_probe(struct udevice *dev)
|
||||||
} while (val == BIST || val == WAIT);
|
} while (val == BIST || val == WAIT);
|
||||||
|
|
||||||
if (val == DEAD)
|
if (val == DEAD)
|
||||||
return -ENODEV;
|
return -ENOENT;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -108,6 +125,7 @@ U_BOOT_DRIVER(riscv_zkr) = {
|
||||||
.name = DRIVER_NAME,
|
.name = DRIVER_NAME,
|
||||||
.id = UCLASS_RNG,
|
.id = UCLASS_RNG,
|
||||||
.ops = &riscv_zkr_ops,
|
.ops = &riscv_zkr_ops,
|
||||||
|
.bind = riscv_zkr_bind,
|
||||||
.probe = riscv_zkr_probe,
|
.probe = riscv_zkr_probe,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue