From 3880bd732578d3d02492578241a55533e5034a9e Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Sat, 7 Jul 2007 07:25:17 +0000 Subject: [PATCH] 1)sound.asm: disable previous patch by default 2)uhci transfer descriptors git-svn-id: svn://kolibrios.org@567 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/data32.inc | 1 + kernel/trunk/drivers/infinity.asm | 14 ++- kernel/trunk/drivers/sound.asm | 19 ++-- kernel/trunk/drivers/usb/usb.asm | 158 +++++++++++++++++++++++++----- kernel/trunk/kernel.asm | 16 +-- 5 files changed, 167 insertions(+), 41 deletions(-) diff --git a/kernel/trunk/data32.inc b/kernel/trunk/data32.inc index 5efd876409..f4e74ff484 100644 --- a/kernel/trunk/data32.inc +++ b/kernel/trunk/data32.inc @@ -77,6 +77,7 @@ AMD_str db "AuthenticAMD",0 ;szInfinity db 'INFINITY',0 szHwMouse db 'ATI2D',0 szPS2MDriver db 'PS2MOUSE',0 +szUSB db 'USB',0 szSTART db 'START',0 szEXPORTS db 'EXPORTS',0 diff --git a/kernel/trunk/drivers/infinity.asm b/kernel/trunk/drivers/infinity.asm index dee64c18de..127fb05bb4 100644 --- a/kernel/trunk/drivers/infinity.asm +++ b/kernel/trunk/drivers/infinity.asm @@ -321,6 +321,8 @@ proc CreateBuffer stdcall, format:dword, size:dword test eax, PCM_RING jnz .test_ring ;staic + test eax, PCM_STATIC + jz .fail test eax, PCM_OUT+PCM_RING jnz .fail jmp .test_ok @@ -754,7 +756,15 @@ proc ResetBuffer stdcall, str:dword, flags:dword mov [edx+STREAM.in_wp], edi mov [edx+STREAM.in_rp], edi + test [edx+STREAM.flags], PCM_STATIC + jnz .static mov [edx+STREAM.in_count], 0 + jmp @F +.static: + mov eax, [edx+STREAM.in_size] + mov [edx+STREAM.in_count], eax +@@: + mov eax, [edx+STREAM.in_size] sub eax, 128 mov [edx+STREAM.in_free], eax @@ -807,6 +817,8 @@ proc GetBufferPos stdcall, str:dword jnz .fail mov ebx, [edx+STREAM.in_rp] + sub ebx, [edx+STREAM.in_base] + sub ebx, 128 xor eax, eax ret .fail: @@ -967,7 +979,7 @@ proc play_buffer stdcall, str:dword, flags:dword ret endp -; for static buffers only +; for static and ring buffers only align 4 proc stop_buffer stdcall, str:dword diff --git a/kernel/trunk/drivers/sound.asm b/kernel/trunk/drivers/sound.asm index 0db0bd9fae..e70a9b2a91 100644 --- a/kernel/trunk/drivers/sound.asm +++ b/kernel/trunk/drivers/sound.asm @@ -343,19 +343,19 @@ proc START stdcall, state:dword in al, 0x21 test ebx, ebx jz .skip - bts ax, bx + bts ax, bx ;mask old line .skip - bts ax, IRQ_LINE + bts ax, IRQ_LINE ;mask new ine out 0x21, al mov al, ah out 0xA1, al - + ;remap IRQ stdcall PciWrite8, 0, 0xF8, 0x61, IRQ_LINE - mov dx, 0x4d0 + mov dx, 0x4d0 ;8259 ELCR1 in al, dx bts ax, IRQ_LINE - out dx, al + out dx, al ;set level-triggered mode mov [ctrl.int_line], IRQ_LINE popf mov esi, msgRemap @@ -642,7 +642,6 @@ proc detect_controller je .found add edi, 12 jmp @B - .next: inc [devfn] cmp [devfn], 256 @@ -749,6 +748,8 @@ proc init_controller call dword2str call SysMsgBoardStr +if 0 + ;;patch for some ugly BIOS cmp [ctrl.vendor], VID_INTEL jne .default @@ -763,6 +764,8 @@ proc init_controller jnc @F xor eax, eax jmp @F +end if + .default: stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x3C and eax, 0xFF @@ -1446,13 +1449,12 @@ msgInvIRQ db 'IRQ line not assigned or invalid', 13,10, 0 msgPlay db 'start play', 13,10,0 msgStop db 'stop play', 13,10,0 ;msgNotify db 'call notify',13,10,0 - msgIRQ db 'AC97 IRQ', 13,10,0 +msgIRQ db 'AC97 IRQ', 13,10,0 msgInitCtrl db 'init controller',13,10,0 ;msgInitCodec db 'init codec',13,10,0 msgPrimBuff db 'create primary buffer ...',0 msgDone db 'done',13,10,0 msgRemap db 'Remap IRQ',13,10,0 -msgIrqMap db 'irq remap ',0 ;msgReg db 'set service handler',13,10,0 msgOk db 'service installed',13,10,0 msgCold db 'cold reset',13,10,0 @@ -1469,6 +1471,7 @@ msgCtrlIsaIo db 'controller io base ',0 msgMixIsaIo db 'codec io base ',0 msgCtrlMMIo db 'controller mmio base ',0 msgMixMMIo db 'codec mmio base ',0 +msgIrqMap db 'AC97 irq map as ',0 section '.data' data readable writable align 16 diff --git a/kernel/trunk/drivers/usb/usb.asm b/kernel/trunk/drivers/usb/usb.asm index 6852af008d..a766082ad9 100644 --- a/kernel/trunk/drivers/usb/usb.asm +++ b/kernel/trunk/drivers/usb/usb.asm @@ -14,20 +14,25 @@ API_VERSION equ 0 ;debug include '../proc32.inc' include '../imports.inc' -OS_BASE equ 0x80000000 -SLOT_BASE equ OS_BASE+0x0080000 - struc UHCI { - .bus dd ? - .devfn dd ? - .io_base dd ? - .mm_base dd ? - .irq dd ? - .flags dd ? - .reset dd ? - .start dd ? - .stop dd ? + .bus dd ? + .devfn dd ? + .io_base dd ? + .mm_base dd ? + .irq dd ? + .flags dd ? + .reset dd ? + .start dd ? + .stop dd ? + + .port_c_suspend dd ? + .resuming_ports dd ? + .rh_state dd ? + .rh_numports dd ? + .is_stopped dd ? + .dead dd ? + .sizeof: } @@ -48,6 +53,24 @@ virtual at 0 IOCTL IOCTL end virtual +struc TD ;transfer descriptor +{ + .link dd ? + .status dd ? + .token dd ? + .buffer dd ? + + .addr dd ? + .frame dd ? + .fd dd ? + .bk dd ? + .sizeof: +} + +virtual at 0 + TD TD +end virtual + public START public service_proc public version @@ -187,7 +210,7 @@ proc detect ret endp -PCI_BASE equ 0x20 +PCI_BASE equ 0x20 USB_LEGKEY equ 0xC0 align 4 @@ -209,6 +232,7 @@ proc init stdcall uhci_reset, esi + stdcall finish_reset, [uhci] .fail: if DEBUG @@ -218,21 +242,39 @@ proc init ret endp -UHCI_USBINTR equ 4 ; interrupt register +UHCI_USBINTR equ 4 ; interrupt register -UHCI_USBLEGSUP_RWC equ 0x8f00 ; the R/WC bits -UHCI_USBLEGSUP_RO equ 0x5040 ; R/O and reserved bits +UHCI_USBLEGSUP_RWC equ 0x8f00 ; the R/WC bits +UHCI_USBLEGSUP_RO equ 0x5040 ; R/O and reserved bits -UHCI_USBCMD_RUN equ 0x0001 ; RUN/STOP bit -UHCI_USBCMD_HCRESET equ 0x0002 ; Host Controller reset -UHCI_USBCMD_EGSM equ 0x0008 ; Global Suspend Mode -UHCI_USBCMD_CONFIGURE equ 0x0040 ; Config Flag -UHCI_USBINTR_RESUME equ 0x0002 ; Resume interrupt enable +UHCI_USBCMD_RUN equ 0x0001 ; RUN/STOP bit +UHCI_USBCMD_HCRESET equ 0x0002 ; Host Controller reset +UHCI_USBCMD_EGSM equ 0x0008 ; Global Suspend Mode +UHCI_USBCMD_CONFIGURE equ 0x0040 ; Config Flag +UHCI_USBINTR_RESUME equ 0x0002 ; Resume interrupt enable +PORTSC0 equ 0x10 +PORTSC1 equ 0x12 + + +UHCI_RH_RESET equ 0 +UHCI_RH_SUSPENDED equ 1 +UHCI_RH_AUTO_STOPPED equ 2 +UHCI_RH_RESUMING equ 3 + +; In this state the HC changes from running to halted +; so it can legally appear either way. +UHCI_RH_SUSPENDING equ 4 + +; In the following states it's an error if the HC is halted. +; These two must come last. +UHCI_RH_RUNNING equ 5 ; The normal state +UHCI_RH_RUNNING_NODEVS equ 6 ; Running with no devices + +UHCI_IS_STOPPED equ 9999 align 4 proc uhci_reset stdcall, uhci:dword - mov esi, [uhci] stdcall PciRead16, [esi+UHCI.bus], [esi+UHCI.devfn], USB_LEGKEY test eax, not (UHCI_USBLEGSUP_RO or UHCI_USBLEGSUP_RWC) @@ -248,6 +290,11 @@ proc uhci_reset stdcall, uhci:dword test ax, UHCI_USBCMD_EGSM jz .reset + + add edx, UHCI_USBINTR + in ax, dx + test ax, not UHCI_USBINTR_RESUME + jnz .reset ret .reset: stdcall PciWrite16, [esi+UHCI.bus], [esi+UHCI.devfn], USB_LEGKEY, UHCI_USBLEGSUP_RWC @@ -263,16 +310,77 @@ proc uhci_reset stdcall, uhci:dword ret endp +proc finish_reset stdcall, uhci:dword -DEVICE_ID equ 0x8086; pci device id -VENDOR_ID equ 0x24D4; device vendor id + mov esi, [uhci] + mov edx, [esi+UHCI.io_base] + add edx, PORTSC0 + xor eax, eax + out dx, ax + add edx, (PORTSC1-PORTSC0) + out dx, ax + mov [esi+UHCI.port_c_suspend], eax + mov [esi+UHCI.resuming_ports], eax + mov [esi+UHCI.rh_state], UHCI_RH_RESET + mov [esi+UHCI.rh_numports], 2 + + mov [esi+UHCI.is_stopped], UHCI_IS_STOPPED + ; mov [ uhci_to_hcd(uhci)->state = HC_STATE_HALT; + ; uhci_to_hcd(uhci)->poll_rh = 0; + + mov [esi+UHCI.dead], eax ; Full reset resurrects the controller + + ret +endp + +proc insert_td stdcall, td:dword, frame:dword + + mov edi, [td] + mov eax, [frame] + and eax, -1024 + mov [edi+TD.frame], eax + + mov ebx, [framelist] + mov edx, [dma_framelist] + shl eax, 5 + + mov ecx, [eax+ebx] + test ecx, ecx + jz .empty + + mov ecx, [ecx+TD.bk] ;last TD + + mov edx, [ecx+TD.fd] + mov [edi+TD.fd], edx + mov [edi+TD.bk], ecx + mov [ecx+TD.fd], edi + mov [edx+TD.bk], edi + + mov eax, [ecx+TD.link] + mov [edi+TD.link], eax + mov ebx, [edi+TD.addr] + mov [ecx+TD.link], ebx + ret +.empty: + mov ecx, [eax+edx] + mov [edi+TD.link], ecx + mov [ebx+eax], edi + mov ecx, [edi+TD.addr] + mov [eax+edx], ecx + ret +endp + +DEVICE_ID equ 0x24D2 ; pci device id +VENDOR_ID equ 0x8086 ; device vendor id +QEMU_USB equ 0x7020 ;all initialized data place here align 4 devices dd (DEVICE_ID shl 16)+VENDOR_ID - dd 0 ;terminator + dd (QEMU_USB shl 16)+VENDOR_ID + dd 0 ;terminator version dd (5 shl 16) or (API_VERSION and 0xFFFF) diff --git a/kernel/trunk/kernel.asm b/kernel/trunk/kernel.asm index e5b50e1ee7..8d1693ef27 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/kernel.asm @@ -610,6 +610,9 @@ no_lib_load: mov esi,boot_devices call boot_log + + mov [pci_access_enabled],1 + call detect_devices stdcall load_driver, szPS2MDriver @@ -630,7 +633,6 @@ no_lib_load: call boot_log call setmouse - mov [pci_access_enabled],1 ; SET PRELIMINARY WINDOW STACK AND POSITIONS @@ -2960,7 +2962,7 @@ sys_drawwindow: cmp edi,4 ; type V - skinned window not sized! {not_sized_skin_window} jne nosyswV draw_skin_window: - + ; parameter for drawwindow_IV push 0 mov edi, [TASK_COUNT] @@ -3003,7 +3005,7 @@ draw_window_caption: je .draw_caption_style_3 ;{for 3 and 4 style write caption} cmp bl,4 je .draw_caption_style_3 - + jmp .not_style_3 .draw_caption_style_3: @@ -3042,9 +3044,9 @@ draw_window_caption: je .skinned cmp al,4 je .skinned - + jmp .not_skinned - .skinned: + .skinned: mov ebp,[edi+window_data+WDATA.box.left-2] mov bp,word[edi+window_data+WDATA.box.top] movzx eax,word[edi+window_data+WDATA.box.width] @@ -3201,8 +3203,8 @@ sys_set_window: je set_APPDATA_wnd_caption cmp cl,4 ; {SPraid.simba} je set_APPDATA_wnd_caption - - jmp @f + + jmp @f set_APPDATA_wnd_caption: mov [edi+APPDATA.wnd_caption],esi @@: mov esi,[esp+0]