Skip to content

Commit a624bde

Browse files
author
Ian Seyler
committed
NVS reorg and Virtio-SCSI driver start
1 parent b8799bc commit a624bde

File tree

8 files changed

+677
-50
lines changed

8 files changed

+677
-50
lines changed

src/drivers.asm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
%include "drivers/nvs/ahci.asm"
3232
%endif
3333
%ifndef NO_VIRTIO
34+
%include "drivers/nvs/virtio.asm"
3435
%include "drivers/nvs/virtio-blk.asm"
36+
%include "drivers/nvs/virtio-scsi.asm"
3537
%endif
3638

3739
; Network

src/drivers/nvs/ahci.asm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
; -----------------------------------------------------------------------------
10-
ahci_init:
10+
nvs_ahci_init:
1111
push rsi ; Used in init_storage
1212
push rdx ; RDX should already point to a supported device for os_bus_read/write
1313

@@ -176,9 +176,9 @@ ahci_init_search_ports_done:
176176
ahci_init_done:
177177
bts word [os_nvsVar], 1 ; Set the bit flag that AHCI has been initialized
178178
mov rdi, os_nvs_io
179-
mov eax, ahci_io
179+
mov eax, nvs_ahci_io
180180
stosq
181-
mov eax, ahci_id
181+
mov eax, nvs_ahci_id
182182
stosq
183183
pop rdx
184184
pop rsi
@@ -203,7 +203,7 @@ ahci_init_error:
203203
; RDI = memory location used for reading/writing data from/to device
204204
; OUT: Nothing
205205
; All other registers preserved
206-
ahci_io:
206+
nvs_ahci_io:
207207
push r8
208208
push rdx
209209
push rbx
@@ -354,7 +354,7 @@ achi_io_error:
354354
; IN: RDX = Port # to query
355355
; RDI = memory location to store details (512 bytes)
356356
; OUT: Nothing, all registers preserved
357-
ahci_id:
357+
nvs_ahci_id:
358358
push rdi
359359
push rsi
360360
push rdx

src/drivers/nvs/nvme.asm

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
; -----------------------------------------------------------------------------
10-
nvme_init:
10+
nvs_nvme_init:
1111
push rsi ; Used in init_storage
1212
push rdx ; RDX should already point to a supported device for os_bus_read/write
1313

@@ -174,9 +174,9 @@ nvme_init_LBA_end:
174174
nvme_init_done:
175175
bts word [os_nvsVar], 0 ; Set the bit flag that NVMe has been initialized
176176
mov rdi, os_nvs_io
177-
mov eax, nvme_io
177+
mov eax, nvs_nvme_io
178178
stosq
179-
mov eax, nvme_id
179+
mov eax, nvs_nvme_id
180180
stosq
181181
pop rdx
182182
pop rsi
@@ -193,15 +193,15 @@ nvme_init_error:
193193

194194

195195
; -----------------------------------------------------------------------------
196-
; nvme_admin -- Perform an Admin operation on a NVMe controller
196+
; nvs_nvme_admin -- Perform an Admin operation on a NVMe controller
197197
; IN: EAX = CDW0
198198
; EBX = CDW1
199199
; ECX = CDW10
200200
; EDX = CDW11
201201
; RDI = CDW6-7
202202
; OUT: Nothing
203203
; All other registers preserved
204-
nvme_admin:
204+
nvs_nvme_admin:
205205
push r9
206206
push rdi
207207
push rdx
@@ -278,15 +278,15 @@ nvme_admin_wait:
278278

279279

280280
; -----------------------------------------------------------------------------
281-
; nvme_io -- Perform an I/O operation on a NVMe device
281+
; nvs_nvme_io -- Perform an I/O operation on a NVMe device
282282
; IN: RAX = starting sector #
283283
; RBX = I/O Opcode
284284
; RCX = number of sectors
285285
; RDX = drive #
286286
; RDI = memory location used for reading/writing data from/to device
287287
; OUT: Nothing
288288
; All other registers preserved
289-
nvme_io:
289+
nvs_nvme_io:
290290
push rdi
291291
push rcx
292292
push rbx
@@ -417,12 +417,12 @@ nvme_io_error:
417417

418418

419419
; -----------------------------------------------------------------------------
420-
; nvme_id -- Identify a NVMe device
420+
; nvs_nvme_id -- Identify a NVMe device
421421
; IN: RBX = NameSpace ID
422422
; RDI = memory location to store data
423423
; OUT: Nothing
424424
; All other registers preserved
425-
nvme_id:
425+
nvs_nvme_id:
426426
ret
427427
; -----------------------------------------------------------------------------
428428

src/drivers/nvs/virtio-blk.asm

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,12 @@
77

88

99
; -----------------------------------------------------------------------------
10-
virtio_blk_init:
10+
nvs_virtio_blk_init:
1111
push rsi
1212
push rdx ; RDX should already point to a supported device for os_bus_read/write
1313
push rbx
1414
push rax
1515

16-
; Verify this driver supports the Vendor
17-
mov eax, [rsi+4] ; Offset to Vendor/Device ID in the Bus Table
18-
mov rsi, virtio_blk_driverid
19-
mov bx, [rsi] ; Load the Vendor (0x1AF4)
20-
cmp ax, bx
21-
jne virtio_blk_init_error ; Bail out if it wasn't a match
22-
23-
; Verify this driver support the Device
24-
shr eax, 16 ; Move Device ID into AX
25-
virtio_blk_init_next_dev:
26-
add rsi, 2
27-
mov bx, [rsi] ; Load the Device
28-
cmp bx, 0 ; End of list?
29-
je virtio_blk_init_error ; If so, bail out
30-
cmp ax, bx ; Check against the list
31-
jne virtio_blk_init_next_dev ; No match? Try next entry
32-
3316
; Grab the Base I/O Address of the device
3417
mov al, 4 ; Read BAR4
3518
call os_bus_read_bar
@@ -202,9 +185,9 @@ virtio_blk_init_pop:
202185
virtio_blk_init_done:
203186
bts word [os_nvsVar], 3 ; Set the bit flag that Virtio Block has been initialized
204187
mov rdi, os_nvs_io ; Write over the storage function addresses
205-
mov eax, virtio_blk_io
188+
mov eax, nvs_virtio_blk_io
206189
stosq
207-
mov eax, virtio_blk_id
190+
mov eax, nvs_virtio_blk_id
208191
stosq
209192
pop rax
210193
pop rbx
@@ -225,15 +208,15 @@ virtio_blk_init_error:
225208

226209

227210
; -----------------------------------------------------------------------------
228-
; virtio_blk_io -- Perform an I/O operation on a VIRTIO Block device
211+
; nvs_virtio_blk_io -- Perform an I/O operation on a VIRTIO Block device
229212
; IN: RAX = starting sector #
230213
; RBX = I/O Opcode
231214
; RCX = number of sectors
232215
; RDX = drive #
233216
; RDI = memory location used for reading/writing data from/to device
234217
; OUT: Nothing
235218
; All other registers preserved
236-
virtio_blk_io:
219+
nvs_virtio_blk_io:
237220
push r9
238221
push rdi
239222
push rdx
@@ -331,15 +314,15 @@ virtio_blk_io_wait:
331314

332315

333316
; -----------------------------------------------------------------------------
334-
; virtio_blk_id --
317+
; nvs_virtio_blk_id --
335318
; IN: EAX = CDW0
336319
; EBX = CDW1
337320
; ECX = CDW10
338321
; EDX = CDW11
339322
; RDI = CDW6-7
340323
; OUT: Nothing
341324
; All other registers preserved
342-
virtio_blk_id:
325+
nvs_virtio_blk_id:
343326
ret
344327
; -----------------------------------------------------------------------------
345328

@@ -349,13 +332,6 @@ notify_offset_multiplier: dq 0
349332
descindex: dw 0
350333
availindex: dw 1
351334

352-
; Driver
353-
virtio_blk_driverid:
354-
dw 0x1AF4 ; Vendor ID
355-
dw 0x1001 ; Device ID - legacy
356-
dw 0x1042 ; Device ID - v1.0
357-
dw 0x0000 ; End of list
358-
359335
align 16
360336
footer:
361337
db 0x00

0 commit comments

Comments
 (0)