From b13c4c9c6dd03be473ff047dcac34066930e95c9 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Sun, 22 Aug 2021 20:49:13 +0000 Subject: [PATCH] i8254x: Improved interrupt handling. git-svn-id: svn://kolibrios.org@9147 a494cfbc-eb01-0410-851d-a64ba20cac60 --- drivers/ethernet/ar81xx.asm | 2 +- drivers/ethernet/i8254x.asm | 50 ++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/drivers/ethernet/ar81xx.asm b/drivers/ethernet/ar81xx.asm index 2232951264..88f1fdd63e 100644 --- a/drivers/ethernet/ar81xx.asm +++ b/drivers/ethernet/ar81xx.asm @@ -480,7 +480,7 @@ proc transmit stdcall bufferptr add dword[ebx + device.bytes_tx], eax adc dword[ebx + device.bytes_tx + 4], 0 - popf + spin_unlock_irqrestore xor eax, eax ret diff --git a/drivers/ethernet/i8254x.asm b/drivers/ethernet/i8254x.asm index f733186ad9..b1380d4882 100644 --- a/drivers/ethernet/i8254x.asm +++ b/drivers/ethernet/i8254x.asm @@ -1,6 +1,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; -;; Copyright (C) KolibriOS team 2004-2018. All rights reserved. ;; +;; Copyright (C) KolibriOS team 2004-2021. All rights reserved. ;; ;; Distributed under terms of the GNU General Public License ;; ;; ;; ;; i8254x driver for KolibriOS ;; @@ -749,11 +749,10 @@ link_status: ;; Out: eax = 0 on success ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - +align 16 proc transmit stdcall bufferptr - pushf - cli + spin_lock_irqsave mov esi, [bufferptr] DEBUGF 1,"Transmitting packet, buffer:%x, size:%u\n", [bufferptr], [esi + NET_BUFF.length] @@ -801,7 +800,7 @@ proc transmit stdcall bufferptr call clean_tx - popf + spin_unlock_irqrestore xor eax, eax ret @@ -810,7 +809,7 @@ proc transmit stdcall bufferptr DEBUGF 2,"Send failed\n" invoke NetFree, [bufferptr] - popf + spin_unlock_irqrestore or eax, -1 ret @@ -822,38 +821,24 @@ endp ;; Interrupt handler ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;; - -align 4 +align 16 int_handler: push ebx esi edi - DEBUGF 1,"INT\n" -;------------------------------------------- -; Find pointer of device wich made IRQ occur + mov ebx, [esp+4*4] + DEBUGF 1,"INT for 0x%x\n", ebx + +; TODO? if we are paranoid, we can check that the value from ebx is present in the current device_list - mov ecx, [devices] - test ecx, ecx - jz .nothing - mov esi, device_list - .nextdevice: - mov ebx, [esi] mov edi, [ebx + device.mmio_addr] mov eax, [edi + REG_ICR] + cmp eax, 0xffffffff ; if so, hardware is no longer present + je .nothing ; test eax, eax - jnz .got_it - .continue: - add esi, 4 - dec ecx - jnz .nextdevice - .nothing: - pop edi esi ebx - xor eax, eax + jz .nothing - ret - - .got_it: - DEBUGF 1,"Device: %x Status: %x\n", ebx, eax + DEBUGF 1,"Status: %x\n", eax ;--------- ; RX done? @@ -943,11 +928,18 @@ int_handler: ; call clean_tx .no_tx: + pop edi esi ebx xor eax, eax inc eax ret + .nothing: + pop edi esi ebx + xor eax, eax + + ret + clean_tx: