Lines Matching refs:rng
74 static int hwrng_init(struct hwrng *rng);
77 static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
85 static void add_early_randomness(struct hwrng *rng) in add_early_randomness() argument
91 bytes_read = rng_get_data(rng, rng_buffer, size, 0); in add_early_randomness()
99 struct hwrng *rng = container_of(kref, struct hwrng, ref); in cleanup_rng() local
101 if (rng->cleanup) in cleanup_rng()
102 rng->cleanup(rng); in cleanup_rng()
104 complete(&rng->cleanup_done); in cleanup_rng()
107 static int set_current_rng(struct hwrng *rng) in set_current_rng() argument
113 err = hwrng_init(rng); in set_current_rng()
118 current_rng = rng; in set_current_rng()
137 struct hwrng *rng; in get_current_rng() local
142 rng = current_rng; in get_current_rng()
143 if (rng) in get_current_rng()
144 kref_get(&rng->ref); in get_current_rng()
147 return rng; in get_current_rng()
150 static void put_rng(struct hwrng *rng) in put_rng() argument
157 if (rng) in put_rng()
158 kref_put(&rng->ref, cleanup_rng); in put_rng()
162 static int hwrng_init(struct hwrng *rng) in hwrng_init() argument
164 if (kref_get_unless_zero(&rng->ref)) in hwrng_init()
167 if (rng->init) { in hwrng_init()
170 ret = rng->init(rng); in hwrng_init()
175 kref_init(&rng->ref); in hwrng_init()
176 reinit_completion(&rng->cleanup_done); in hwrng_init()
179 add_early_randomness(rng); in hwrng_init()
181 current_quality = rng->quality ? : default_quality; in hwrng_init()
203 static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size, in rng_get_data() argument
208 if (rng->read) in rng_get_data()
209 return rng->read(rng, (void *)buffer, size, wait); in rng_get_data()
211 if (rng->data_present) in rng_get_data()
212 present = rng->data_present(rng, wait); in rng_get_data()
217 return rng->data_read(rng, (u32 *)buffer); in rng_get_data()
228 struct hwrng *rng; in rng_dev_read() local
231 rng = get_current_rng(); in rng_dev_read()
232 if (IS_ERR(rng)) { in rng_dev_read()
233 err = PTR_ERR(rng); in rng_dev_read()
236 if (!rng) { in rng_dev_read()
246 bytes_read = rng_get_data(rng, rng_buffer, in rng_dev_read()
279 put_rng(rng); in rng_dev_read()
295 put_rng(rng); in rng_dev_read()
323 struct hwrng *rng; in hwrng_attr_current_store() local
329 list_for_each_entry(rng, &rng_list, list) { in hwrng_attr_current_store()
330 if (sysfs_streq(rng->name, buf)) { in hwrng_attr_current_store()
332 if (rng != current_rng) in hwrng_attr_current_store()
333 err = set_current_rng(rng); in hwrng_attr_current_store()
347 struct hwrng *rng; in hwrng_attr_current_show() local
349 rng = get_current_rng(); in hwrng_attr_current_show()
350 if (IS_ERR(rng)) in hwrng_attr_current_show()
351 return PTR_ERR(rng); in hwrng_attr_current_show()
353 ret = snprintf(buf, PAGE_SIZE, "%s\n", rng ? rng->name : "none"); in hwrng_attr_current_show()
354 put_rng(rng); in hwrng_attr_current_show()
364 struct hwrng *rng; in hwrng_attr_available_show() local
370 list_for_each_entry(rng, &rng_list, list) { in hwrng_attr_available_show()
371 strlcat(buf, rng->name, PAGE_SIZE); in hwrng_attr_available_show()
410 struct hwrng *rng; in hwrng_fillfn() local
412 rng = get_current_rng(); in hwrng_fillfn()
413 if (IS_ERR(rng) || !rng) in hwrng_fillfn()
416 rc = rng_get_data(rng, rng_fillbuf, in hwrng_fillfn()
419 put_rng(rng); in hwrng_fillfn()
442 int hwrng_register(struct hwrng *rng) in hwrng_register() argument
447 if (rng->name == NULL || in hwrng_register()
448 (rng->data_read == NULL && rng->read == NULL)) in hwrng_register()
471 if (strcmp(tmp->name, rng->name) == 0) in hwrng_register()
475 init_completion(&rng->cleanup_done); in hwrng_register()
476 complete(&rng->cleanup_done); in hwrng_register()
481 err = set_current_rng(rng); in hwrng_register()
485 list_add_tail(&rng->list, &rng_list); in hwrng_register()
487 if (old_rng && !rng->init) { in hwrng_register()
495 add_early_randomness(rng); in hwrng_register()
505 void hwrng_unregister(struct hwrng *rng) in hwrng_unregister() argument
509 list_del(&rng->list); in hwrng_unregister()
510 if (current_rng == rng) { in hwrng_unregister()
528 wait_for_completion(&rng->cleanup_done); in hwrng_unregister()
547 int devm_hwrng_register(struct device *dev, struct hwrng *rng) in devm_hwrng_register() argument
556 error = hwrng_register(rng); in devm_hwrng_register()
562 *ptr = rng; in devm_hwrng_register()
568 void devm_hwrng_unregister(struct device *dev, struct hwrng *rng) in devm_hwrng_unregister() argument
570 devres_release(dev, devm_hwrng_release, devm_hwrng_match, rng); in devm_hwrng_unregister()