2 * Copyright 2013, Jérôme Duval, korli@users.berlios.de.
3 * Distributed under the terms of the MIT License.
7 #include "VirtioRNGPrivate.h"
14 #define VIRTIO_RNG_CONTROLLER_PRETTY_NAME "Virtio RNG Device"
16 #define VIRTIO_RNG_DRIVER_MODULE_NAME "busses/random/virtio_rng/driver_v1"
17 #define VIRTIO_RNG_DEVICE_MODULE_NAME "busses/random/virtio_rng/device_v1"
20 device_manager_info
*gDeviceManager
;
21 random_for_controller_interface
*gRandom
;
24 // #pragma mark - Random module interface
28 sim_init_bus(device_node
*node
, void **_cookie
)
32 VirtioRNGDevice
*device
= new(std::nothrow
)
33 VirtioRNGDevice(node
);
36 status_t status
= device
->InitCheck();
48 sim_uninit_bus(void *cookie
)
51 VirtioRNGDevice
*device
= (VirtioRNGDevice
*)cookie
;
58 sim_read(void* cookie
, void *_buffer
, size_t *_numBytes
)
60 VirtioRNGDevice
*device
= (VirtioRNGDevice
*)cookie
;
61 return device
->Read(_buffer
, _numBytes
);
65 // #pragma mark - Driver module interface
69 virtio_rng_supports_device(device_node
*parent
)
74 // make sure parent is really the Virtio bus manager
75 if (gDeviceManager
->get_attr_string(parent
, B_DEVICE_BUS
, &bus
, false))
78 if (strcmp(bus
, "virtio"))
81 // check whether it's really a Virtio Entropy Device
82 if (gDeviceManager
->get_attr_uint16(parent
, VIRTIO_DEVICE_TYPE_ITEM
,
83 &deviceType
, true) != B_OK
|| deviceType
!= VIRTIO_DEVICE_ID_ENTROPY
)
86 TRACE("Virtio RNG device found!\n");
93 virtio_rng_register_device(device_node
*parent
)
97 device_attr attrs
[] = {
101 return gDeviceManager
->register_node(parent
, VIRTIO_RNG_DRIVER_MODULE_NAME
,
107 virtio_rng_init_driver(device_node
*node
, void **_cookie
)
116 virtio_rng_register_child_devices(void *cookie
)
119 device_node
*node
= (device_node
*)cookie
;
121 device_attr attrs
[] = {
122 { B_DEVICE_FIXED_CHILD
, B_STRING_TYPE
,
123 { string
: RANDOM_FOR_CONTROLLER_MODULE_NAME
}},
124 { B_DEVICE_PRETTY_NAME
, B_STRING_TYPE
,
125 { string
: VIRTIO_RNG_CONTROLLER_PRETTY_NAME
}},
129 return gDeviceManager
->register_node(node
,
130 VIRTIO_RNG_DEVICE_MODULE_NAME
, attrs
, NULL
, NULL
);
135 std_ops(int32 op
, ...)
139 case B_MODULE_UNINIT
:
148 static random_module_info sVirtioRNGDeviceInterface
= {
151 VIRTIO_RNG_DEVICE_MODULE_NAME
,
155 NULL
, // supported devices
156 NULL
, // register node
159 NULL
, // register child devices
170 static driver_module_info sVirtioRNGDriver
= {
172 VIRTIO_RNG_DRIVER_MODULE_NAME
,
176 virtio_rng_supports_device
,
177 virtio_rng_register_device
,
178 virtio_rng_init_driver
,
179 NULL
, // uninit_driver,
180 virtio_rng_register_child_devices
,
182 NULL
, // device_removed
186 module_dependency module_dependencies
[] = {
187 { B_DEVICE_MANAGER_MODULE_NAME
, (module_info
**)&gDeviceManager
},
188 { RANDOM_FOR_CONTROLLER_MODULE_NAME
, (module_info
**)&gRandom
},
193 module_info
*modules
[] = {
194 (module_info
*)&sVirtioRNGDriver
,
195 (module_info
*)&sVirtioRNGDeviceInterface
,