WIP: Test code to detect VirtIO devices #373
Draft
YVishere
wants to merge 10 commits from
YVishere/kolibrios:detect_virtio into main
pull from: YVishere/kolibrios:detect_virtio
merge into: KolibriOS:main
KolibriOS:main
KolibriOS:wolf3d-launcher
KolibriOS:kterm-upload
KolibriOS:app/socketdbg_fix1
KolibriOS:hdaudio-add-ring-buffer-for-unsolicied-events
KolibriOS:workflow-fuse
KolibriOS:add-license-file-header-to-guide
KolibriOS:blocks-add-models
KolibriOS:shell-improve-cpuid
KolibriOS:rewrite_ide_drv
KolibriOS:qrcodegen
KolibriOS:ci/update
KolibriOS:laser-tank-fix-win-height
KolibriOS:improvement/commit-and-branch-styles
KolibriOS:docs/libs
Labels
Clear labels
C
Category/Applications
Category/Drivers
Category/General
Category/Kernel
Category/Libraries
Eolite
FASM
FS
GSoC
HardwareTested
HLL
Influence/Settings
Influence/Text/TYPO
IRCC
Kernel
Pay for the code
This issue in GSoC program
Kind
Breaking
Breaking change that won't be backward compatible
Kind
Bug
Something is not working
Kind
Build
Kind
Documentation
Documentation changes
Kind
Enhancement
Improve existing functionality
Kind
Feature
New functionality
Kind
Security
This is security issue
Kind
Testing
Issue or pull request related to testing
Paid task
PR
Conflicts
PR conflicts with main
PR
Dependent
This PR is dependent on another PR
Priority
Critical
The priority is critical
Priority
High
The priority is high
Priority
Low
The priority is low
Priority
Medium
The priority is medium
PR
Ready to merge
Pull request is ready for merge
PR
Request changes
Changes requested in pull request
PR
Review required
Reviewed
Confirmed
Issue has been confirmed
Reviewed
Duplicate
This issue or pull request already exists
Reviewed
Invalid
Invalid issue
Reviewed
Won't Fix
This issue won't be fixed
Status
Abandoned
Somebody has started to work on this but abandoned work
Status
Blocked
Something is blocking this issue or pull request
Status
Need More Info
Feedback is required to reproduce issue or to continue work
No Label
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: KolibriOS/kolibrios#373
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "YVishere/kolibrios:detect_virtio"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Compares Vendor IDs listed in qemu's website with IDs extracted from PCIList to determine whether the driver is VirtIO or not
@@ -0,0 +50,4 @@push ebxinvoke GetPCIListtest eax, eaxIt is safe to remove this check: GetPCIList returns a pointer to a statically allocated object which is never zero.
@@ -0,0 +57,4 @@.next_dev:mov eax, [eax+PCIDEV.fd]test eax, eaxI'm not sure this can be zero too
@@ -0,0 +64,4 @@jz .finishmov edx, [eax+PCIDEV.vendor_device_id]test edx, edxCan a PCI device have both vendor_id and device_id zeroed?
@@ -0,0 +77,4 @@jmp @F.isVirt:mov esi, msgVirtIOYou can move this to the line 69 and remove the jmp one line above
@@ -0,0 +80,4 @@mov esi, msgVirtIO@@:DEBUGF 1, "I: %s %x\n", esi, edxPlease, log vendor_id and device_id separately like 1234:5678
@@ -0,0 +95,4 @@retendpproc service_proc stdcall, ioctl:dwordIs this proc needed?
I added this when I couldn't get my driver to work. I thought maybe having this would solve the issue but I just verified it works without this and the
invoke RegService, my_service, service_procline@YVishere, detection of VirtIO devices seems to work, good job! Since you plan to work on specific VirtIO devices, could you, please, add detection of those now? I.e. not just vendor id's but also device id's. Let's say, for block devices, gpus, network devices.
ab87edf417to3c8782552d@@ -0,0 +11,4 @@; Returns pointer to the device id stored in data; clears and returns value in esiif used PCI_find_devIs this 'if' needed?
I assumed it helps in memory optimization like an #ifdef in c. I noticed in another .inc file I was looking at so I thought to add it as a good practice.
If a file can be included into several other files within one project, then such a logic can take place, indeed. For example, macros.inc includes struct.inc, some other file includes struct.inc. It might make sense to put some guard into struct.inc to be included just once. In your case device_table.inc is always included only one time by virt_io_det.asm. You can build the driver with this 'if' and without it and see no difference.
Oh ok that makes sense
@@ -0,0 +21,4 @@mov esi, ven2_arraycmp [ven_id], VirtVendorID2jnz @F ;unknown vendor idAnonymous labels are convenient when jumping for a few lines for an obvious reason. Here you are jumping quite far over several named labels. Please, make this label named too.
@@ -0,0 +24,4 @@jnz @F ;unknown vendor id.pre_loop:push edxYou push/pop edx in several places. It will be easier to push just once at the begin of the function and pop at the end
Yeah I came up with this so that there would be fewer memory accesses. Maybe the branches could minimize the benefits though
@@ -0,0 +26,4 @@.pre_loop:push edx.loop:'.loop' is a faceless name, use something more descriptive like '.check_next_device', '.next_dev', or similar
@@ -0,0 +35,4 @@cmp edx, [dev_id]jz .foundadd esi, VEN_STRIDEIf you move this addition a few lines above, you can replace these two branches
with just one
jnz .loop@@ -0,0 +13,4 @@__DEBUG__ equ 1__DEBUG_LEVEL__ equ 1API_VERSION equ 0 ;debugNot used
@@ -0,0 +15,4 @@API_VERSION equ 0 ;debugSTRIDE equ 4 ;size of row in devices tableNot used
@@ -0,0 +17,4 @@STRIDE equ 4 ;size of row in devices tableSRV_GETVERSION equ 0Not used
@@ -0,0 +62,4 @@shr ecx, 16 ;cx upper half - device id, dx lower half - vendor id;prepare regs for find dev procmovzx ecx, cxThe upper half of ecx is already 0 because of 'shr' above
@@ -0,0 +76,4 @@jmp .next_dev.finish:xor eax, eaxCode style: https://board.kolibrios.org/viewtopic.php?t=1950
@YVishere, looks good to me. You can consider your test task done.
Feel free to start writing a real VirtIO driver based on this code, if you wish. Formally you don't have to, of course.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.