Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
osv
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Verlässliche Systemsoftware
projects
osv
Commits
9d0943ec
Commit
9d0943ec
authored
12 years ago
by
Dor Laor
Browse files
Options
Downloads
Patches
Plain Diff
Add virtio config space access functions according to the spec
parent
9506b15e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
drivers/virtio.cc
+53
-0
53 additions, 0 deletions
drivers/virtio.cc
drivers/virtio.hh
+8
-0
8 additions, 0 deletions
drivers/virtio.hh
with
61 additions
and
0 deletions
drivers/virtio.cc
+
53
−
0
View file @
9d0943ec
...
...
@@ -35,6 +35,12 @@ Virtio::Init(Device* dev) {
_bars
[
0
]
->
write
(
VIRTIO_PCI_STATUS
,
(
u8
)(
VIRTIO_CONFIG_S_ACKNOWLEDGE
|
VIRTIO_CONFIG_S_DRIVER
));
probe_virt_queues
();
for
(
int
i
=
0
;
i
<
32
;
i
++
)
debug
(
fmt
(
"%d:%d "
)
%
i
%
get_device_feature_bit
(
i
),
false
);
debug
(
fmt
(
"
\n
"
),
false
);
_bars
[
0
]
->
write
(
VIRTIO_PCI_STATUS
,
(
u8
)(
VIRTIO_CONFIG_S_DRIVER_OK
));
return
true
;
...
...
@@ -75,3 +81,50 @@ Virtio::vring_need_event(u16 event_idx, u16 new_idx, u16 old) {
return
(
u16
)(
new_idx
-
event_idx
-
1
)
<
(
u16
)(
new_idx
-
old
);
}
bool
Virtio
::
get_device_feature_bit
(
int
bit
)
{
u32
features
=
_bars
[
0
]
->
read
(
VIRTIO_PCI_HOST_FEATURES
);
return
bool
(
features
&
(
1
<<
bit
));
}
void
Virtio
::
set_guest_feature_bit
(
int
bit
,
bool
on
)
{
u32
features
=
_bars
[
0
]
->
read
(
VIRTIO_PCI_GUEST_FEATURES
);
features
=
(
on
)
?
features
|
(
1
<<
bit
)
:
features
&
~
(
1
<<
bit
);
_bars
[
0
]
->
write
(
VIRTIO_PCI_GUEST_FEATURES
,
features
);
}
void
Virtio
::
set_guest_features
(
u32
features
)
{
_bars
[
0
]
->
write
(
VIRTIO_PCI_GUEST_FEATURES
,
features
);
}
void
Virtio
::
pci_conf_write
(
int
offset
,
void
*
buf
,
int
length
)
{
u8
*
ptr
=
reinterpret_cast
<
u8
*>
(
buf
);
for
(
int
i
=
0
;
i
<
length
;
i
++
)
_bars
[
0
]
->
write
(
offset
,
ptr
[
i
]);
}
void
Virtio
::
pci_conf_read
(
int
offset
,
void
*
buf
,
int
length
)
{
unsigned
char
*
ptr
=
reinterpret_cast
<
unsigned
char
*>
(
buf
);
for
(
int
i
=
0
;
i
<
length
;
i
++
)
ptr
[
i
]
=
_bars
[
0
]
->
readb
(
offset
);
}
void
Virtio
::
probe_virt_queues
()
{
u16
queuesel
=
0
;
u16
qsize
;
do
{
pci_conf_write
(
VIRTIO_PCI_QUEUE_SEL
,
&
queuesel
,
sizeof
(
queuesel
));
pci_conf_read
(
VIRTIO_PCI_QUEUE_NUM
,
&
qsize
,
sizeof
(
qsize
));
debug
(
fmt
(
"queue %d, size %d"
)
%
queuesel
%
qsize
);
if
(
!
qsize
)
break
;
queuesel
++
;
}
while
(
1
);
}
This diff is collapsed.
Click to expand it.
drivers/virtio.hh
+
8
−
0
View file @
9d0943ec
...
...
@@ -194,6 +194,14 @@ protected:
unsigned
vring_size
(
unsigned
int
num
,
unsigned
long
align
);
int
vring_need_event
(
u16
event_idx
,
u16
new_idx
,
u16
old
);
virtual
bool
get_device_feature_bit
(
int
bit
);
virtual
void
set_guest_feature_bit
(
int
bit
,
bool
on
);
virtual
void
set_guest_features
(
u32
features
);
void
pci_conf_read
(
int
offset
,
void
*
buf
,
int
length
);
void
pci_conf_write
(
int
offset
,
void
*
buf
,
int
length
);
void
probe_virt_queues
();
private
:
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment