mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-06 09:21:49 +00:00
os: remove conversion warnings/errors from virtio
The read_config and write_config functions in the generic virtio headers used by all drivers lead to compiler warnings resp. errors if effective-c++ switch is enabled. Moreover, the functions require to define the access width as parameter. We can better turn them into template functions using the value type to read resp. write to derive the access width. Ref genodelabs/genode#4344
This commit is contained in:
parent
ac69189e23
commit
adc594a7e6
@ -86,9 +86,9 @@ class Virtio::Device : Platform::Device::Mmio
|
|||||||
* VIRTIO 1.0 spec 64 bit wide registers are supposed to be read as
|
* VIRTIO 1.0 spec 64 bit wide registers are supposed to be read as
|
||||||
* two 32 bit values.
|
* two 32 bit values.
|
||||||
*/
|
*/
|
||||||
struct Config_8 : Register_array<0x100, 8, 256, 8> { };
|
template <typename T> class Config :
|
||||||
struct Config_16 : Register_array<0x100, 16, 128, 16> { };
|
public Register_array<0x100, sizeof(T)*8,
|
||||||
struct Config_32 : Register_array<0x100, 32, 64, 32> { };
|
256/sizeof(T), sizeof(T)*8> {};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Noncopyable
|
* Noncopyable
|
||||||
@ -141,23 +141,18 @@ class Virtio::Device : Platform::Device::Mmio
|
|||||||
return (uint16_t)read<QueueNumMax>();
|
return (uint16_t)read<QueueNumMax>();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t read_config(uint8_t offset, Access_size size)
|
template <typename T>
|
||||||
|
T read_config(const uint8_t offset)
|
||||||
{
|
{
|
||||||
switch (size) {
|
static_assert(sizeof(T) <= 4);
|
||||||
case ACCESS_8BIT: return read<Config_8>(offset);
|
return read<Config<T>>(offset >> log2(sizeof(T)));
|
||||||
case ACCESS_16BIT: return read<Config_16>(offset >> 1);
|
|
||||||
case ACCESS_32BIT: return read<Config_32>(offset >> 2);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_config(uint8_t offset, Access_size size, uint32_t value)
|
template <typename T>
|
||||||
|
void write_config(const uint8_t offset, const T value)
|
||||||
{
|
{
|
||||||
switch (size) {
|
static_assert(sizeof(T) <= 4);
|
||||||
case ACCESS_8BIT: write<Config_8> ((uint8_t) value, offset); break;
|
write<Config<T>>(value, (offset >> log2(sizeof(T))));
|
||||||
case ACCESS_16BIT: write<Config_16>((uint16_t)value, (offset >> 1)); break;
|
|
||||||
case ACCESS_32BIT: write<Config_32>(value, (offset >> 2)); break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool configure_queue(uint16_t queue_index,
|
bool configure_queue(uint16_t queue_index,
|
||||||
|
@ -45,9 +45,9 @@ struct Virtio::Device_mmio : public Genode::Mmio
|
|||||||
struct QueueUsedLow : Register<0x30, 32> { };
|
struct QueueUsedLow : Register<0x30, 32> { };
|
||||||
struct QueueUsedHigh : Register<0x34, 32> { };
|
struct QueueUsedHigh : Register<0x34, 32> { };
|
||||||
|
|
||||||
struct Config_8 : Register_array<0x0, 8, 256, 8> { };
|
template <typename T> class Config :
|
||||||
struct Config_16 : Register_array<0x0, 16, 128, 16> { };
|
public Register_array<0x0, sizeof(T)*8,
|
||||||
struct Config_32 : Register_array<0x0, 32, 64, 32> { };
|
256/sizeof(T), sizeof(T)*8> {};
|
||||||
|
|
||||||
struct IrqReason : Register<0x0, 32> { };
|
struct IrqReason : Register<0x0, 32> { };
|
||||||
|
|
||||||
@ -184,32 +184,19 @@ class Virtio::Device
|
|||||||
return _cfg_common.read<Device_mmio::QueueSize>();
|
return _cfg_common.read<Device_mmio::QueueSize>();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t read_config(uint8_t offset, Access_size size)
|
template <typename T>
|
||||||
|
T read_config(const uint8_t offset)
|
||||||
{
|
{
|
||||||
switch (size) {
|
static_assert(sizeof(T) <= 4);
|
||||||
case Device::ACCESS_8BIT:
|
return _dev_config.read<Device_mmio::Config<T>>(offset >> log2(sizeof(T)));
|
||||||
return _dev_config.read<Device_mmio::Config_8>(offset);
|
|
||||||
case Device::ACCESS_16BIT:
|
|
||||||
return _dev_config.read<Device_mmio::Config_16>(offset >> 1);
|
|
||||||
case Device::ACCESS_32BIT:
|
|
||||||
return _dev_config.read<Device_mmio::Config_32>(offset >> 2);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_config(uint8_t offset, Access_size size, uint32_t value)
|
template <typename T>
|
||||||
|
void write_config(const uint8_t offset, const T value)
|
||||||
{
|
{
|
||||||
switch (size) {
|
static_assert(sizeof(T) <= 4);
|
||||||
case Device::ACCESS_8BIT:
|
_dev_config.write<Device_mmio::Config<T>>(value,
|
||||||
_dev_config.write<Device_mmio::Config_8>(value, offset);
|
(offset >> log2(sizeof(T))));
|
||||||
break;
|
|
||||||
case Device::ACCESS_16BIT:
|
|
||||||
_dev_config.write<Device_mmio::Config_16>(value, offset >> 1);
|
|
||||||
break;
|
|
||||||
case Device::ACCESS_32BIT:
|
|
||||||
_dev_config.write<Device_mmio::Config_32>(value, offset >> 2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool configure_queue(uint16_t queue_index, Virtio::Queue_description desc)
|
bool configure_queue(uint16_t queue_index, Virtio::Queue_description desc)
|
||||||
|
@ -413,7 +413,7 @@ class Virtio::Queue
|
|||||||
static_assert(!TRAITS::device_write_only);
|
static_assert(!TRAITS::device_write_only);
|
||||||
static_assert(TRAITS::has_data_payload);
|
static_assert(TRAITS::has_data_payload);
|
||||||
|
|
||||||
int const req_desc_count = 1 + (sizeof(header) + data_size) / _buffers.buffer_size();
|
size_t const req_desc_count = 1UL + (sizeof(header) + data_size) / _buffers.buffer_size();
|
||||||
if (req_desc_count > _descriptors.available_capacity())
|
if (req_desc_count > _descriptors.available_capacity())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -226,8 +226,7 @@ class Virtio_fb::Driver
|
|||||||
uint32_t num_scanouts;
|
uint32_t num_scanouts;
|
||||||
uint32_t before = 0, after = 0;
|
uint32_t before = 0, after = 0;
|
||||||
do {
|
do {
|
||||||
num_scanouts = device.read_config(
|
num_scanouts = device.read_config<uint32_t>(Config::NUM_SCANOUTS);
|
||||||
Config::NUM_SCANOUTS, Virtio::Device::ACCESS_32BIT);
|
|
||||||
} while (after != before);
|
} while (after != before);
|
||||||
return num_scanouts;
|
return num_scanouts;
|
||||||
}
|
}
|
||||||
@ -237,12 +236,10 @@ class Virtio_fb::Driver
|
|||||||
uint32_t events;
|
uint32_t events;
|
||||||
uint32_t before = 0, after = 0;
|
uint32_t before = 0, after = 0;
|
||||||
do {
|
do {
|
||||||
events = _device.read_config(
|
events = _device.read_config<uint32_t>(Config::EVENTS_READ);
|
||||||
Config::EVENTS_READ, Virtio::Device::ACCESS_32BIT);
|
|
||||||
} while (after != before);
|
} while (after != before);
|
||||||
do {
|
do {
|
||||||
_device.write_config(
|
_device.write_config(Config::EVENTS_CLEAR, events);
|
||||||
Config::EVENTS_CLEAR, Virtio::Device::ACCESS_32BIT, events);
|
|
||||||
} while (after != before);
|
} while (after != before);
|
||||||
return events;
|
return events;
|
||||||
}
|
}
|
||||||
|
@ -252,9 +252,9 @@ class Virtio_input::Driver
|
|||||||
|
|
||||||
static size_t _cfg_select(Virtio::Device &device, Config_id sel, uint8_t subsel)
|
static size_t _cfg_select(Virtio::Device &device, Config_id sel, uint8_t subsel)
|
||||||
{
|
{
|
||||||
device.write_config(Config::SelectID, Virtio::Device::ACCESS_8BIT, sel);
|
device.write_config(Config::SelectID, sel);
|
||||||
device.write_config(Config::SelectSubID, Virtio::Device::ACCESS_8BIT, subsel);
|
device.write_config(Config::SelectSubID, subsel);
|
||||||
return device.read_config(Config::Data_size, Virtio::Device::ACCESS_8BIT);
|
return device.read_config<uint8_t>(Config::Data_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -265,14 +265,14 @@ class Virtio_input::Driver
|
|||||||
|
|
||||||
auto size = _cfg_select(device, Config_id::Abs_info, Event::Code::Abs_x);
|
auto size = _cfg_select(device, Config_id::Abs_info, Event::Code::Abs_x);
|
||||||
if (size >= sizeof(cfg.x)) {
|
if (size >= sizeof(cfg.x)) {
|
||||||
cfg.x.min = device.read_config(Config::Data, Virtio::Device::ACCESS_32BIT);
|
cfg.x.min = device.read_config<uint32_t>(Config::Data);
|
||||||
cfg.x.max = device.read_config(Config::Data + 4, Virtio::Device::ACCESS_32BIT);
|
cfg.x.max = device.read_config<uint32_t>(Config::Data + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
size = _cfg_select(device, Config_id::Abs_info, Event::Code::Abs_y);
|
size = _cfg_select(device, Config_id::Abs_info, Event::Code::Abs_y);
|
||||||
if (size >= sizeof(cfg.y)) {
|
if (size >= sizeof(cfg.y)) {
|
||||||
cfg.y.min = device.read_config(Config::Data, Virtio::Device::ACCESS_32BIT);
|
cfg.y.min = device.read_config<uint32_t>(Config::Data);
|
||||||
cfg.y.max = device.read_config(Config::Data + 4, Virtio::Device::ACCESS_32BIT);
|
cfg.y.max = device.read_config<uint32_t>(Config::Data + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.width = config.attribute_value("width", cfg.x.max);
|
cfg.width = config.attribute_value("width", cfg.x.max);
|
||||||
@ -292,10 +292,10 @@ class Virtio_input::Driver
|
|||||||
throw Device_init_failed();
|
throw Device_init_failed();
|
||||||
}
|
}
|
||||||
|
|
||||||
device_id.bus_type = (uint16_t)device.read_config(Config::Data + 0, Virtio::Device::ACCESS_16BIT);
|
device_id.bus_type = device.read_config<uint16_t>(Config::Data + 0);
|
||||||
device_id.vendor = (uint16_t)device.read_config(Config::Data + 2, Virtio::Device::ACCESS_16BIT);
|
device_id.vendor = device.read_config<uint16_t>(Config::Data + 2);
|
||||||
device_id.product = (uint16_t)device.read_config(Config::Data + 4, Virtio::Device::ACCESS_16BIT);
|
device_id.product = device.read_config<uint16_t>(Config::Data + 4);
|
||||||
device_id.version = (uint16_t)device.read_config(Config::Data + 6, Virtio::Device::ACCESS_16BIT);
|
device_id.version = device.read_config<uint16_t>(Config::Data + 6);
|
||||||
|
|
||||||
return device_id;
|
return device_id;
|
||||||
}
|
}
|
||||||
@ -311,7 +311,7 @@ class Virtio_input::Driver
|
|||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
|
|
||||||
for (unsigned i = 0; i < size; ++i)
|
for (unsigned i = 0; i < size; ++i)
|
||||||
buf[i] = (uint8_t)device.read_config((uint8_t)(Config::Data + i), Virtio::Device::ACCESS_8BIT);
|
buf[i] = device.read_config<uint8_t>((uint8_t)(Config::Data + i));
|
||||||
|
|
||||||
return String<SZ>(buf);
|
return String<SZ>(buf);
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ class Virtio_nic::Device : Noncopyable
|
|||||||
/**
|
/**
|
||||||
* See section 5.1.4 of VirtIO 1.0 specification.
|
* See section 5.1.4 of VirtIO 1.0 specification.
|
||||||
*/
|
*/
|
||||||
enum { CONFIG_MAC_BASE = 0, CONFIG_STATUS = 6 };
|
enum Config : uint8_t { CONFIG_MAC_BASE = 0, CONFIG_STATUS = 6 };
|
||||||
enum { STATUS_LINK_UP = 1 << 0 };
|
enum { STATUS_LINK_UP = 1 << 0 };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -181,10 +181,9 @@ class Virtio_nic::Device : Noncopyable
|
|||||||
uint32_t before = 0, after = 0;
|
uint32_t before = 0, after = 0;
|
||||||
do {
|
do {
|
||||||
before = device.get_config_generation();
|
before = device.get_config_generation();
|
||||||
for (size_t idx = 0; idx < sizeof(mac.addr); ++idx) {
|
for (uint8_t idx = 0; idx < sizeof(mac.addr); ++idx)
|
||||||
mac.addr[idx] = device.read_config(
|
mac.addr[idx] =
|
||||||
CONFIG_MAC_BASE + idx, Virtio::Device::ACCESS_8BIT);
|
device.read_config<uint8_t>(CONFIG_MAC_BASE + idx);
|
||||||
}
|
|
||||||
after = device.get_config_generation();
|
after = device.get_config_generation();
|
||||||
} while (after != before);
|
} while (after != before);
|
||||||
|
|
||||||
@ -398,7 +397,7 @@ class Virtio_nic::Device : Noncopyable
|
|||||||
uint8_t status = 0;
|
uint8_t status = 0;
|
||||||
do {
|
do {
|
||||||
before = _device.get_config_generation();
|
before = _device.get_config_generation();
|
||||||
status = _device.read_config(CONFIG_STATUS, Virtio::Device::ACCESS_8BIT);
|
status = _device.read_config<uint8_t>(CONFIG_STATUS);
|
||||||
after = _device.get_config_generation();
|
after = _device.get_config_generation();
|
||||||
} while (after != before);
|
} while (after != before);
|
||||||
|
|
||||||
|
@ -6,5 +6,3 @@ INC_DIR = $(REP_DIR)/src/drivers/nic/virtio
|
|||||||
CONFIG_XSD = ../../config.xsd
|
CONFIG_XSD = ../../config.xsd
|
||||||
|
|
||||||
vpath % $(REP_DIR)/src/drivers/nic/virtio
|
vpath % $(REP_DIR)/src/drivers/nic/virtio
|
||||||
|
|
||||||
CC_CXX_WARN_STRICT_CONVERSION =
|
|
||||||
|
@ -5,5 +5,3 @@ INC_DIR = $(REP_DIR)/src/drivers/nic/virtio
|
|||||||
CONFIG_XSD = ../../config.xsd
|
CONFIG_XSD = ../../config.xsd
|
||||||
|
|
||||||
vpath % $(REP_DIR)/src/drivers/nic/virtio
|
vpath % $(REP_DIR)/src/drivers/nic/virtio
|
||||||
|
|
||||||
CC_CXX_WARN_STRICT_CONVERSION =
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user