From a24875d50b0a9aa8002d25e371429e9a998c8e8f Mon Sep 17 00:00:00 2001 From: "Sergey Semyonov (Serge)" Date: Sat, 16 Feb 2008 08:46:57 +0000 Subject: [PATCH] kernel: map_io_mem git-svn-id: svn://kolibrios.org@741 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/core/exports.inc | 2 ++ kernel/trunk/core/memory.inc | 42 +++++++++++++++++++++++++++++++- kernel/trunk/core/peload.inc | 1 + kernel/trunk/drivers/ati2d.asm | 35 ++++---------------------- kernel/trunk/drivers/imports.inc | 1 + kernel/trunk/drivers/sound.asm | 22 ++++------------- 6 files changed, 55 insertions(+), 48 deletions(-) diff --git a/kernel/trunk/core/exports.inc b/kernel/trunk/core/exports.inc index c92b043b76..e843a83db4 100644 --- a/kernel/trunk/core/exports.inc +++ b/kernel/trunk/core/exports.inc @@ -33,6 +33,7 @@ iglobal szGetPgAddr db 'GetPgAddr',0 szMapPage db 'MapPage',0 szMapSpace db 'MapSpace',0 + szMapIoMem db 'MapIoMem',0 szCommitPages db 'CommitPages',0 szReleasePages db 'ReleasePages',0 @@ -101,6 +102,7 @@ kernel_export: dd szFreePage , free_page dd szMapPage , map_page ;stdcall dd szMapSpace , map_space + dd szMapIoMem , map_io_mem ;stdcall dd szGetPgAddr , get_pg_addr dd szCommitPages , commit_pages ;not implemented dd szReleasePages , release_pages diff --git a/kernel/trunk/core/memory.inc b/kernel/trunk/core/memory.inc index 6d38fabc3a..9c55163fe9 100644 --- a/kernel/trunk/core/memory.inc +++ b/kernel/trunk/core/memory.inc @@ -143,6 +143,45 @@ proc free_page ret endp +proc map_io_mem stdcall, base:dword, size:dword, flags:dword + + push ebx + push edi + mov eax, [size] + add eax, 4095 + and eax, -4096 + mov [size], eax + stdcall alloc_kernel_space, eax + test eax, eax + jz .fail + push eax + + mov edi, 0x1000 + mov ebx, eax + mov ecx,[size] + mov edx, [base] + shr eax, 12 + shr ecx, 12 + and edx, -4096 + or edx, [flags] +@@: + mov [page_tabs+eax*4], edx + invlpg [ebx] + inc eax + add ebx, edi + add edx, edi + loop @B + + pop eax + mov edx, [base] + and edx, 4095 + add eax, edx +.fail: + pop edi + pop ebx + ret +endp + ; param ; eax= page base + page flags ; ebx= liear address @@ -150,7 +189,7 @@ endp align 4 commit_pages: - + push edi test ecx, ecx jz .fail @@ -171,6 +210,7 @@ commit_pages: jnz @B mov [pg_data.pg_mutex],ecx .fail: + pop edi ret diff --git a/kernel/trunk/core/peload.inc b/kernel/trunk/core/peload.inc index e373b7e46f..cecbb22bf0 100644 --- a/kernel/trunk/core/peload.inc +++ b/kernel/trunk/core/peload.inc @@ -275,6 +275,7 @@ __exports: free_kernel_space, 'FreeKernelSpace', \ ; stdcall kernel_alloc, 'KernelAlloc', \ ; stdcall kernel_free, 'KernelFree', \ ; stdcall + map_io_mem, 'MapIoMem', \ ; stdcall pci_api, 'PciApi', \ pci_read32, 'PciRead32', \ ; stdcall reg_service, 'RegService', \ diff --git a/kernel/trunk/drivers/ati2d.asm b/kernel/trunk/drivers/ati2d.asm index b63755ec7d..01aee8d361 100644 --- a/kernel/trunk/drivers/ati2d.asm +++ b/kernel/trunk/drivers/ati2d.asm @@ -344,27 +344,14 @@ endp align 4 proc init_r200 - - stdcall AllocKernelSpace, dword 0x10000 + stdcall PciRead32, [bus], [devfn], dword 0x18 + stdcall MapIoMem,eax,0x10000,(PG_SW+PG_NOCACHE) test eax, eax jz .fail mov [ati_io], eax + mov edi, eax - stdcall PciRead32, [bus], [devfn], dword 0x18 - and eax, 0xFFFF0000 - mov esi, eax - - mov edi, [ati_io] - mov edx, 16 -@@: - stdcall MapPage,edi,esi,PG_SW+PG_NOCACHE - add edi, 0x1000 - add esi, 0x1000 - dec edx - jnz @B - - mov edi, [ati_io] mov dword [edi+RD_RB3D_CNTL], 0 call engRestore @@ -397,25 +384,13 @@ end if align 4 proc init_r500 - stdcall AllocKernelSpace, dword 0x10000 + stdcall PciRead32, [bus], [devfn], dword 0x18 + stdcall MapIoMem,eax,0x10000,(PG_SW+PG_NOCACHE) test eax, eax jz .fail mov [ati_io], eax - stdcall PciRead32, [bus], [devfn], dword 0x18 - and eax, 0xFFFF0000 - mov esi, eax - - mov edi, [ati_io] - mov edx, 16 -@@: - stdcall MapPage,edi,esi,PG_SW+PG_NOCACHE - add edi, 0x1000 - add esi, 0x1000 - dec edx - jnz @B - mov [fnSelect], r500_SelectCursor mov [fnSet], r500_SetCursor diff --git a/kernel/trunk/drivers/imports.inc b/kernel/trunk/drivers/imports.inc index 75c9d03ace..c0196d4a98 100644 --- a/kernel/trunk/drivers/imports.inc +++ b/kernel/trunk/drivers/imports.inc @@ -35,6 +35,7 @@ kernel_export \ FreePage,\ MapPage,\ MapSpace,\ + MapIoMem,\ GetPgAddr,\ CommitPages,\ ReleasePages,\ diff --git a/kernel/trunk/drivers/sound.asm b/kernel/trunk/drivers/sound.asm index 35850f8e5b..2248cf4262 100644 --- a/kernel/trunk/drivers/sound.asm +++ b/kernel/trunk/drivers/sound.asm @@ -802,24 +802,12 @@ PG_NOCACHE equ 0x018 align 4 proc set_ICH4 - stdcall AllocKernelSpace, dword 0x2000 - mov edi, eax - mov ebx, [ctrl.codec_mem_base] - and ebx, -4096 - stdcall MapPage, edi,ebx,PG_SW+PG_NOCACHE - mov ebx, [ctrl.codec_mem_base] - and ebx, 4095 - add ebx, edi - mov [ctrl.codec_mem_base], ebx - add edi, 0x1000 - mov ebx, [ctrl.ctrl_mem_base] - and ebx, -4096 - stdcall MapPage, edi, ebx,PG_SW+PG_NOCACHE - mov ebx, [ctrl.ctrl_mem_base] - and ebx, 4095 - add ebx, edi - mov [ctrl.ctrl_mem_base], ebx + stdcall MapIoMem,[ctrl.codec_mem_base],0x1000,PG_SW+PG_NOCACHE + mov [ctrl.codec_mem_base], eax + + stdcall MapIoMem,[ctrl.ctrl_mem_base],0x1000,PG_SW+PG_NOCACHE + mov [ctrl.ctrl_mem_base], eax mov [ctrl.codec_read16], codec_mem_r16 ;virtual mov [ctrl.codec_write16], codec_mem_w16 ;virtual