Util code moved back to its original location

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5990 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2004-01-08 09:05:58 +00:00
parent d8b4d83df2
commit 0be4037053
3 changed files with 30 additions and 37 deletions
@@ -49,8 +49,6 @@ char * names[NUM_CARDS*20+1];
extern device_hooks multi_hooks;
uint32 round_to_pagesize(uint32 size);
area_id map_mem(void **log, void *phy, size_t size, const char *name);
int32 echo_int(void *arg);
status_t init_hardware(void);
status_t init_driver(void);
@@ -327,39 +325,6 @@ echo_stream_delete(echo_stream *stream)
}
uint32 round_to_pagesize(uint32 size)
{
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
}
/* This is not the most advanced method to map physical memory for io access.
* Perhaps using B_ANY_KERNEL_ADDRESS instead of B_ANY_KERNEL_BLOCK_ADDRESS
* makes the whole offset calculation and relocation obsolete. But the code
* below does work, and I can't test if using B_ANY_KERNEL_ADDRESS also works.
*/
area_id
map_mem(void **log, void *phy, size_t size, const char *name)
{
uint32 offset;
void *phyadr;
void *mapadr;
area_id area;
LOG(("mapping physical address %p with %#x bytes for %s\n",phy,size,name));
offset = (uint32)phy & (B_PAGE_SIZE - 1);
phyadr = (void*)((uint32)phy - offset);
size = round_to_pagesize(size + offset);
area = map_physical_memory(name, phyadr, size, B_ANY_KERNEL_BLOCK_ADDRESS, B_READ_AREA | B_WRITE_AREA, &mapadr);
*log = (void*) ((uint32)mapadr + offset);
LOG(("physical = %p, logical = %p, offset = %#x, phyadr = %p, mapadr = %p, size = %#x, area = %#x\n",
phy, *log, offset, phyadr, mapadr, size, area));
return area;
}
/* Echo interrupt */
int32 echo_int(void *arg)
@@ -86,3 +86,31 @@ area_id alloc_mem(void **phy, void **log, size_t size, const char *name)
return areaid;
}
/* This is not the most advanced method to map physical memory for io access.
* Perhaps using B_ANY_KERNEL_ADDRESS instead of B_ANY_KERNEL_BLOCK_ADDRESS
* makes the whole offset calculation and relocation obsolete. But the code
* below does work, and I can't test if using B_ANY_KERNEL_ADDRESS also works.
*/
area_id
map_mem(void **log, void *phy, size_t size, const char *name)
{
uint32 offset;
void *phyadr;
void *mapadr;
area_id area;
LOG(("mapping physical address %p with %#x bytes for %s\n",phy,size,name));
offset = (uint32)phy & (B_PAGE_SIZE - 1);
phyadr = (void*)((uint32)phy - offset);
size = round_to_pagesize(size + offset);
area = map_physical_memory(name, phyadr, size, B_ANY_KERNEL_BLOCK_ADDRESS, B_READ_AREA | B_WRITE_AREA, &mapadr);
*log = (void*) ((uint32)mapadr + offset);
LOG(("physical = %p, logical = %p, offset = %#x, phyadr = %p, mapadr = %p, size = %#x, area = %#x\n",
phy, *log, offset, phyadr, mapadr, size, area));
return area;
}
+2 -2
View File
@@ -34,8 +34,6 @@ extern "C" {
#include <KernelExport.h>
area_id alloc_mem(void **phy, void **log, size_t size, const char *name);
cpu_status lock(void);
@@ -43,6 +41,8 @@ void unlock(cpu_status status);
extern spinlock slock;
area_id map_mem(void **log, void *phy, size_t size, const char *name);
#ifdef __cplusplus
}
#endif