* Fixed a ton of wrong usages of B_CONTIGUOUS + B_FULL_LOCK.

* The use of B_{READ|WRITE}_AREA throughout the drivers is surely alarming.
  Defining these flags means that *every user* application can access these
  buffers read/write, it becomes visible in userspace like any other memory
  (just shared among all apps). I would like to ask each driver maintainer
  to see if that is really wished here. If you only need one app to be able
  to access it, cloning the area would be more appropriate.
* I came across the use of B_ANY_KERNEL_BLOCK_ADDRESS a number of times. This
  is almost completely useless for most usages, as it tries to align the
  virtual to a multiple of the size of the area. It just makes the allocation
  more likely to fail. Please only use where appropriate, and please review
  your code.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26858 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-08-07 13:00:36 +00:00
parent 9372d6969b
commit b0884f0cb8
29 changed files with 608 additions and 479 deletions
+25 -14
View File
@@ -25,31 +25,35 @@
#include "fwdebug.h" #include "fwdebug.h"
#include "util.h" #include "util.h"
static inline uint32 static inline uint32
round_to_pagesize(uint32 size) round_to_pagesize(uint32 size)
{ {
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
} }
area_id area_id
alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *name) alloc_mem(void **virt, void **phy, size_t size, uint32 protection,
const char *name)
{ {
physical_entry pe; physical_entry pe;
void * virtadr; void *virtadr;
area_id areaid; area_id area;
status_t rv; status_t rv;
TRACE("allocating %ld bytes for %s\n", size, name); TRACE("allocating %ld bytes for %s\n", size, name);
size = round_to_pagesize(size); size = round_to_pagesize(size);
areaid = create_area(name, &virtadr, B_ANY_KERNEL_ADDRESS, size, B_FULL_LOCK | B_CONTIGUOUS, protection); area = create_area(name, &virtadr, B_ANY_KERNEL_ADDRESS, size, B_CONTIGUOUS,
if (areaid < B_OK) { protection);
if (area < B_OK) {
ERROR("couldn't allocate area %s\n", name); ERROR("couldn't allocate area %s\n", name);
return B_ERROR; return B_ERROR;
} }
rv = get_memory_map(virtadr, size, &pe, 1); rv = get_memory_map(virtadr, size, &pe, 1);
if (rv < B_OK) { if (rv < B_OK) {
delete_area(areaid); delete_area(area);
ERROR("couldn't get mapping for %s\n", name); ERROR("couldn't get mapping for %s\n", name);
return B_ERROR; return B_ERROR;
} }
@@ -58,33 +62,40 @@ alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *n
*virt = virtadr; *virt = virtadr;
if (phy) if (phy)
*phy = pe.address; *phy = pe.address;
TRACE("area = %ld, size = %ld, virt = %p, phy = %p\n", areaid, size, virtadr, pe.address); TRACE("area = %ld, size = %ld, virt = %p, phy = %p\n", area, size, virtadr,
return areaid; pe.address);
return area;
} }
area_id area_id
map_mem(void **virt, void *phy, size_t size, uint32 protection, const char *name) map_mem(void **virt, void *phy, size_t size, uint32 protection,
const char *name)
{ {
uint32 offset; uint32 offset;
void *phyadr; void *phyadr;
void *mapadr; void *mapadr;
area_id area; area_id area;
TRACE("mapping physical address %p with %ld bytes for %s\n", phy, size, name); TRACE("mapping physical address %p with %ld bytes for %s\n", phy, size,
name);
offset = (uint32)phy & (B_PAGE_SIZE - 1); offset = (uint32)phy & (B_PAGE_SIZE - 1);
phyadr = (char *)phy - offset; phyadr = (char *)phy - offset;
size = round_to_pagesize(size + offset); size = round_to_pagesize(size + offset);
area = map_physical_memory(name, phyadr, size, B_ANY_KERNEL_BLOCK_ADDRESS, protection, &mapadr); area = map_physical_memory(name, phyadr, size, B_ANY_KERNEL_BLOCK_ADDRESS,
protection, &mapadr);
if (area < B_OK) { if (area < B_OK) {
ERROR("mapping '%s' failed, error 0x%lx (%s)\n", name, area, strerror(area)); ERROR("mapping '%s' failed, error 0x%lx (%s)\n", name, area,
strerror(area));
return area; return area;
} }
*virt = (char *)mapadr + offset; *virt = (char *)mapadr + offset;
TRACE("physical = %p, virtual = %p, offset = %ld, phyadr = %p, mapadr = %p, size = %ld, area = 0x%08lx\n", TRACE("physical = %p, virtual = %p, offset = %ld, phyadr = %p, mapadr = "
phy, *virt, offset, phyadr, mapadr, size, area); "%p, size = %ld, area = 0x%08lx\n", phy, *virt, offset, phyadr, mapadr,
size, area);
return area; return area;
} }
+1 -1
View File
@@ -99,7 +99,7 @@ scsi_init_ccb_alloc(scsi_bus_info *bus)
// the bus is not ready yet so the CCB cannot be initialized // the bus is not ready yet so the CCB cannot be initialized
// correctly // correctly
bus->ccb_pool = locked_pool->create(sizeof(scsi_ccb), sizeof(uint32) - 1, 0, bus->ccb_pool = locked_pool->create(sizeof(scsi_ccb), sizeof(uint32) - 1, 0,
CCB_CHUNK_SIZE, CCB_NUM_MAX, 0, "scsi_ccb_pool", B_FULL_LOCK | B_CONTIGUOUS, CCB_CHUNK_SIZE, CCB_NUM_MAX, 0, "scsi_ccb_pool", B_CONTIGUOUS,
ccb_low_alloc_hook, ccb_low_free_hook, bus); ccb_low_alloc_hook, ccb_low_free_hook, bus);
if (bus->ccb_pool == NULL) if (bus->ccb_pool == NULL)
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2007, Axel Dörfler, [email protected]. All rights reserved. * Copyright 2004-2008, Axel Dörfler, [email protected]. All rights reserved.
* Copyright 2002/03, Thomas Kurschel. All rights reserved. * Copyright 2002/03, Thomas Kurschel. All rights reserved.
* *
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
@@ -213,8 +213,7 @@ scsi_alloc_dma_buffer(dma_buffer *buffer, dma_params *dma_params, uint32 size)
buffer->area = create_area("DMA buffer", buffer->area = create_area("DMA buffer",
(void **)&dma_buffer_address_unaligned, (void **)&dma_buffer_address_unaligned,
B_ANY_KERNEL_ADDRESS, size, B_ANY_KERNEL_ADDRESS, size, B_CONTIGUOUS, 0);
B_FULL_LOCK | B_CONTIGUOUS, 0 );
if (buffer->area < 0) { if (buffer->area < 0) {
SHOW_ERROR(2, "Cannot create contignous DMA buffer of %d bytes", SHOW_ERROR(2, "Cannot create contignous DMA buffer of %d bytes",
(int)size); (int)size);
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2007, Haiku, Inc. All RightsReserved. * Copyright 2004-2008, Haiku, Inc. All RightsReserved.
* Copyright 2002-2003, Thomas Kurschel. All rights reserved. * Copyright 2002-2003, Thomas Kurschel. All rights reserved.
* *
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
@@ -174,8 +174,7 @@ init_temp_sg(void)
MAX_TEMP_SG_FRAGMENTS * sizeof(physical_entry), MAX_TEMP_SG_FRAGMENTS * sizeof(physical_entry),
sizeof(physical_entry) - 1, 0, sizeof(physical_entry) - 1, 0,
B_PAGE_SIZE, MAX_TEMP_SG_LISTS, 1, B_PAGE_SIZE, MAX_TEMP_SG_LISTS, 1,
"scsi_temp_sg_pool", B_FULL_LOCK | B_CONTIGUOUS, "scsi_temp_sg_pool", B_CONTIGUOUS, NULL, NULL, NULL);
NULL, NULL, NULL);
if (temp_sg_pool == NULL) if (temp_sg_pool == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -1,5 +1,5 @@
/* /*
* Copyright 2006, Haiku Inc. All rights reserved. * Copyright 2006-2008, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -69,7 +69,7 @@ PhysicalMemoryAllocator::PhysicalMemoryAllocator(const char *name,
roundedSize = (roundedSize + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); roundedSize = (roundedSize + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
fArea = create_area(fName, &fLogicalBase, B_ANY_KERNEL_ADDRESS, fArea = create_area(fName, &fLogicalBase, B_ANY_KERNEL_ADDRESS,
roundedSize, B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); roundedSize, B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
if (fArea < B_OK) { if (fArea < B_OK) {
TRACE_ERROR(("PMA: failed to create memory area\n")); TRACE_ERROR(("PMA: failed to create memory area\n"));
return; return;
@@ -1,5 +1,5 @@
/* /*
* Copyright 2003-2006, Haiku Inc. All rights reserved. * Copyright 2003-2008, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -282,7 +282,7 @@ Stack::AllocateArea(void **logicalAddress, void **physicalAddress, size_t size,
void *logAddress; void *logAddress;
size = (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); size = (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
area_id area = create_area(name, &logAddress, B_ANY_KERNEL_ADDRESS, size, area_id area = create_area(name, &logAddress, B_ANY_KERNEL_ADDRESS, size,
B_FULL_LOCK | B_CONTIGUOUS, 0); B_CONTIGUOUS, 0);
if (area < B_OK) { if (area < B_OK) {
TRACE_ERROR(("USB Stack: couldn't allocate area %s\n", name)); TRACE_ERROR(("USB Stack: couldn't allocate area %s\n", name));
@@ -456,7 +456,8 @@ channel_init(device_node *node, void **_channelCookie)
// PRDT must be contiguous, dword-aligned and must not cross 64K boundary // PRDT must be contiguous, dword-aligned and must not cross 64K boundary
prdtSize = (IDE_ADAPTER_MAX_SG_COUNT * sizeof(prd_entry) + (B_PAGE_SIZE - 1)) & ~(B_PAGE_SIZE - 1); prdtSize = (IDE_ADAPTER_MAX_SG_COUNT * sizeof(prd_entry) + (B_PAGE_SIZE - 1)) & ~(B_PAGE_SIZE - 1);
channel->prd_area = create_area("prd", (void **)&channel->prdt, B_ANY_KERNEL_ADDRESS, prdtSize, B_FULL_LOCK | B_CONTIGUOUS, 0); channel->prd_area = create_area("prd", (void **)&channel->prdt,
B_ANY_KERNEL_ADDRESS, prdtSize, B_CONTIGUOUS, 0);
if (channel->prd_area < B_OK) { if (channel->prd_area < B_OK) {
TRACE("creating prd_area failed\n"); TRACE("creating prd_area failed\n");
goto err; goto err;
+15 -6
View File
@@ -13,14 +13,17 @@
#define TRACE(a...) dprintf("\33[34mahci:\33[0m " a) #define TRACE(a...) dprintf("\33[34mahci:\33[0m " a)
#define ERROR(a...) dprintf("\33[34mahci:\33[0m " a) #define ERROR(a...) dprintf("\33[34mahci:\33[0m " a)
static inline uint32 static inline uint32
round_to_pagesize(uint32 size) round_to_pagesize(uint32 size)
{ {
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
} }
area_id area_id
alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *name) alloc_mem(void **virt, void **phy, size_t size, uint32 protection,
const char *name)
{ {
physical_entry pe; physical_entry pe;
void * virtadr; void * virtadr;
@@ -30,7 +33,8 @@ alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *n
TRACE("allocating %ld bytes for %s\n", size, name); TRACE("allocating %ld bytes for %s\n", size, name);
size = round_to_pagesize(size); size = round_to_pagesize(size);
areaid = create_area(name, &virtadr, B_ANY_KERNEL_ADDRESS, size, B_FULL_LOCK | B_CONTIGUOUS, protection); areaid = create_area(name, &virtadr, B_ANY_KERNEL_ADDRESS, size,
B_CONTIGUOUS, protection);
if (areaid < B_OK) { if (areaid < B_OK) {
ERROR("couldn't allocate area %s\n", name); ERROR("couldn't allocate area %s\n", name);
return B_ERROR; return B_ERROR;
@@ -49,8 +53,10 @@ alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *n
return areaid; return areaid;
} }
area_id area_id
map_mem(void **virt, void *phy, size_t size, uint32 protection, const char *name) map_mem(void **virt, void *phy, size_t size, uint32 protection,
const char *name)
{ {
uint32 offset; uint32 offset;
void *phyadr; void *phyadr;
@@ -62,7 +68,8 @@ map_mem(void **virt, void *phy, size_t size, uint32 protection, const char *name
offset = (uint32)phy & (B_PAGE_SIZE - 1); offset = (uint32)phy & (B_PAGE_SIZE - 1);
phyadr = (char *)phy - offset; phyadr = (char *)phy - offset;
size = round_to_pagesize(size + offset); size = round_to_pagesize(size + offset);
area = map_physical_memory(name, phyadr, size, B_ANY_KERNEL_BLOCK_ADDRESS, protection, &mapadr); area = map_physical_memory(name, phyadr, size, B_ANY_KERNEL_BLOCK_ADDRESS,
protection, &mapadr);
if (area < B_OK) { if (area < B_OK) {
ERROR("mapping '%s' failed, error 0x%lx (%s)\n", name, area, strerror(area)); ERROR("mapping '%s' failed, error 0x%lx (%s)\n", name, area, strerror(area));
return area; return area;
@@ -78,14 +85,16 @@ map_mem(void **virt, void *phy, size_t size, uint32 protection, const char *name
status_t status_t
sg_memcpy(const physical_entry *sgTable, int sgCount, const void *data, size_t dataSize) sg_memcpy(const physical_entry *sgTable, int sgCount, const void *data,
size_t dataSize)
{ {
int i; int i;
for (i = 0; i < sgCount && dataSize > 0; i++) { for (i = 0; i < sgCount && dataSize > 0; i++) {
size_t size = min_c(dataSize, sgTable[i].size); size_t size = min_c(dataSize, sgTable[i].size);
addr_t address; addr_t address;
if (vm_get_physical_page((addr_t)sgTable[i].address, &address, PHYSICAL_PAGE_CAN_WAIT) < B_OK) if (vm_get_physical_page((addr_t)sgTable[i].address, &address,
PHYSICAL_PAGE_CAN_WAIT) < B_OK)
return B_ERROR; return B_ERROR;
TRACE("sg_memcpy phyAddr %p, addr %p, size %lu\n", sgTable[i].address, (void *)address, size); TRACE("sg_memcpy phyAddr %p, addr %p, size %lu\n", sgTable[i].address, (void *)address, size);
@@ -38,60 +38,72 @@ spinlock slock = B_SPINLOCK_INITIALIZER;
uint32 round_to_pagesize(uint32 size); uint32 round_to_pagesize(uint32 size);
cpu_status lock(void)
cpu_status
lock(void)
{ {
cpu_status status = disable_interrupts(); cpu_status status = disable_interrupts();
acquire_spinlock(&slock); acquire_spinlock(&slock);
return status; return status;
} }
void unlock(cpu_status status)
void
unlock(cpu_status status)
{ {
release_spinlock(&slock); release_spinlock(&slock);
restore_interrupts(status); restore_interrupts(status);
} }
uint32 round_to_pagesize(uint32 size)
uint32
round_to_pagesize(uint32 size)
{ {
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
} }
area_id alloc_mem(void **phy, void **log, size_t size, const char *name)
area_id
alloc_mem(void **phy, void **log, size_t size, const char *name)
{ {
physical_entry pe; physical_entry pe;
void * logadr; void * logadr;
area_id areaid; area_id area;
status_t rv; status_t rv;
LOG(("allocating %d bytes for %s\n",size,name)); LOG(("allocating %d bytes for %s\n",size,name));
size = round_to_pagesize(size); size = round_to_pagesize(size);
areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS,size,B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); area = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS, size, B_CONTIGUOUS,
if (areaid < B_OK) { B_READ_AREA | B_WRITE_AREA);
PRINT(("couldn't allocate area %s\n",name)); if (area < B_OK) {
PRINT(("couldn't allocate area %s\n", name));
return B_ERROR; return B_ERROR;
} }
rv = get_memory_map(logadr,size,&pe,1); rv = get_memory_map(logadr, size, &pe, 1);
if (rv < B_OK) { if (rv < B_OK) {
delete_area(areaid); delete_area(area);
PRINT(("couldn't map %s\n",name)); PRINT(("couldn't map %s\n",name));
return B_ERROR; return B_ERROR;
} }
memset(logadr,0,size); memset(logadr, 0, size);
if (log) if (log)
*log = logadr; *log = logadr;
if (phy) if (phy)
*phy = pe.address; *phy = pe.address;
LOG(("area = %d, size = %d, log = %#08X, phy = %#08X\n",areaid,size,logadr,pe.address)); LOG(("area = %d, size = %d, log = %#08X, phy = %#08X\n", area, size, logadr,
return areaid; pe.address));
return area;
} }
/* This is not the most advanced method to map physical memory for io access. /* 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 * Perhaps using B_ANY_KERNEL_ADDRESS instead of B_ANY_KERNEL_BLOCK_ADDRESS
* makes the whole offset calculation and relocation obsolete. But the code * 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. * 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) area_id
map_mem(void **log, void *phy, size_t size, const char *name)
{ {
uint32 offset; uint32 offset;
void *phyadr; void *phyadr;
@@ -38,25 +38,33 @@ spinlock slock = B_SPINLOCK_INITIALIZER;
uint32 round_to_pagesize(uint32 size); uint32 round_to_pagesize(uint32 size);
cpu_status lock(void)
cpu_status
lock(void)
{ {
cpu_status status = disable_interrupts(); cpu_status status = disable_interrupts();
acquire_spinlock(&slock); acquire_spinlock(&slock);
return status; return status;
} }
void unlock(cpu_status status)
void
unlock(cpu_status status)
{ {
release_spinlock(&slock); release_spinlock(&slock);
restore_interrupts(status); restore_interrupts(status);
} }
uint32 round_to_pagesize(uint32 size)
uint32
round_to_pagesize(uint32 size)
{ {
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
} }
area_id alloc_mem(void **phy, void **log, size_t size, const char *name)
area_id
alloc_mem(void **phy, void **log, size_t size, const char *name)
{ {
physical_entry pe; physical_entry pe;
void * logadr; void * logadr;
@@ -66,7 +74,8 @@ area_id alloc_mem(void **phy, void **log, size_t size, const char *name)
LOG(("allocating %d bytes for %s\n",size,name)); LOG(("allocating %d bytes for %s\n",size,name));
size = round_to_pagesize(size); size = round_to_pagesize(size);
areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS,size,B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS, size,
B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
if (areaid < B_OK) { if (areaid < B_OK) {
PRINT(("couldn't allocate area %s\n",name)); PRINT(("couldn't allocate area %s\n",name));
return B_ERROR; return B_ERROR;
@@ -38,25 +38,33 @@ spinlock slock = 0;
uint32 round_to_pagesize(uint32 size); uint32 round_to_pagesize(uint32 size);
cpu_status lock(void)
cpu_status
lock(void)
{ {
cpu_status status = disable_interrupts(); cpu_status status = disable_interrupts();
acquire_spinlock(&slock); acquire_spinlock(&slock);
return status; return status;
} }
void unlock(cpu_status status)
void
unlock(cpu_status status)
{ {
release_spinlock(&slock); release_spinlock(&slock);
restore_interrupts(status); restore_interrupts(status);
} }
uint32 round_to_pagesize(uint32 size)
uint32
round_to_pagesize(uint32 size)
{ {
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
} }
area_id alloc_mem(void **phy, void **log, size_t size, const char *name)
area_id
alloc_mem(void **phy, void **log, size_t size, const char *name)
{ {
physical_entry pe; physical_entry pe;
void * logadr; void * logadr;
@@ -66,32 +74,36 @@ area_id alloc_mem(void **phy, void **log, size_t size, const char *name)
LOG(("allocating %d bytes for %s\n",size,name)); LOG(("allocating %d bytes for %s\n",size,name));
size = round_to_pagesize(size); size = round_to_pagesize(size);
areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS,size,B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS, size,
B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
if (areaid < B_OK) { if (areaid < B_OK) {
PRINT(("couldn't allocate area %s\n",name)); PRINT(("couldn't allocate area %s\n",name));
return B_ERROR; return B_ERROR;
} }
rv = get_memory_map(logadr,size,&pe,1); rv = get_memory_map(logadr, size, &pe, 1);
if (rv < B_OK) { if (rv < B_OK) {
delete_area(areaid); delete_area(areaid);
PRINT(("couldn't map %s\n",name)); PRINT(("couldn't map %s\n", name));
return B_ERROR; return B_ERROR;
} }
memset(logadr,0,size); memset(logadr, 0, size);
if (log) if (log)
*log = logadr; *log = logadr;
if (phy) if (phy)
*phy = pe.address; *phy = pe.address;
LOG(("area = %d, size = %d, log = %#08X, phy = %#08X\n",areaid,size,logadr,pe.address)); LOG(("area = %d, size = %d, log = %#08X, phy = %#08X\n", areaid, size,
logadr, pe.address));
return areaid; return areaid;
} }
/* This is not the most advanced method to map physical memory for io access. /* 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 * Perhaps using B_ANY_KERNEL_ADDRESS instead of B_ANY_KERNEL_BLOCK_ADDRESS
* makes the whole offset calculation and relocation obsolete. But the code * 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. * 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) area_id
map_mem(void **log, void *phy, size_t size, const char *name)
{ {
uint32 offset; uint32 offset;
void *phyadr; void *phyadr;
@@ -103,7 +115,8 @@ area_id map_mem(void **log, void *phy, size_t size, const char *name)
offset = (uint32)phy & (B_PAGE_SIZE - 1); offset = (uint32)phy & (B_PAGE_SIZE - 1);
phyadr = phy - offset; phyadr = phy - offset;
size = round_to_pagesize(size + 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); area = map_physical_memory(name, phyadr, size, B_ANY_KERNEL_BLOCK_ADDRESS,
B_READ_AREA | B_WRITE_AREA, &mapadr);
*log = mapadr + offset; *log = mapadr + offset;
LOG(("physical = %p, logical = %p, offset = %#x, phyadr = %p, mapadr = %p, size = %#x, area = %#x\n", LOG(("physical = %p, logical = %p, offset = %#x, phyadr = %p, mapadr = %p, size = %#x, area = %#x\n",
@@ -38,25 +38,33 @@ spinlock slock = 0;
uint32 round_to_pagesize(uint32 size); uint32 round_to_pagesize(uint32 size);
cpu_status lock(void)
cpu_status
lock(void)
{ {
cpu_status status = disable_interrupts(); cpu_status status = disable_interrupts();
acquire_spinlock(&slock); acquire_spinlock(&slock);
return status; return status;
} }
void unlock(cpu_status status)
void
unlock(cpu_status status)
{ {
release_spinlock(&slock); release_spinlock(&slock);
restore_interrupts(status); restore_interrupts(status);
} }
uint32 round_to_pagesize(uint32 size)
uint32
round_to_pagesize(uint32 size)
{ {
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
} }
area_id alloc_mem(void **log, void **phy, size_t size, const char *name)
area_id
alloc_mem(void **log, void **phy, size_t size, const char *name)
{ {
physical_entry pe; physical_entry pe;
void * logadr; void * logadr;
@@ -66,7 +74,8 @@ area_id alloc_mem(void **log, void **phy, size_t size, const char *name)
LOG(("allocating %d bytes for %s\n",size,name)); LOG(("allocating %d bytes for %s\n",size,name));
size = round_to_pagesize(size); size = round_to_pagesize(size);
areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS,size,B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS, size,
B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
if (areaid < B_OK) { if (areaid < B_OK) {
PRINT(("couldn't allocate area %s\n",name)); PRINT(("couldn't allocate area %s\n",name));
return B_ERROR; return B_ERROR;
@@ -86,12 +95,14 @@ area_id alloc_mem(void **log, void **phy, size_t size, const char *name)
return areaid; return areaid;
} }
/* This is not the most advanced method to map physical memory for io access. /* 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 * Perhaps using B_ANY_KERNEL_ADDRESS instead of B_ANY_KERNEL_BLOCK_ADDRESS
* makes the whole offset calculation and relocation obsolete. But the code * 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. * 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) area_id
map_mem(void **log, void *phy, size_t size, const char *name)
{ {
uint32 offset; uint32 offset;
void *phyadr; void *phyadr;
@@ -35,13 +35,17 @@
uint32 round_to_pagesize(uint32 size); uint32 round_to_pagesize(uint32 size);
uint32 round_to_pagesize(uint32 size)
uint32
round_to_pagesize(uint32 size)
{ {
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
} }
area_id area_id
alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *name) alloc_mem(void **virt, void **phy, size_t size, uint32 protection,
const char *name)
{ {
physical_entry pe; physical_entry pe;
void * virtadr; void * virtadr;
@@ -51,7 +55,8 @@ alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *n
LOG(("allocating %ld bytes for %s\n", size, name)); LOG(("allocating %ld bytes for %s\n", size, name));
size = round_to_pagesize(size); size = round_to_pagesize(size);
areaid = create_area(name, &virtadr, B_ANY_KERNEL_ADDRESS, size, B_FULL_LOCK | B_CONTIGUOUS, protection); areaid = create_area(name, &virtadr, B_ANY_KERNEL_ADDRESS, size,
B_CONTIGUOUS, protection);
if (areaid < B_OK) { if (areaid < B_OK) {
PRINT(("couldn't allocate area %s\n",name)); PRINT(("couldn't allocate area %s\n",name));
return B_ERROR; return B_ERROR;
@@ -71,6 +76,7 @@ alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *n
return areaid; return areaid;
} }
/* This is not the most advanced method to map physical memory for io access. /* 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 * Perhaps using B_ANY_KERNEL_ADDRESS instead of B_ANY_KERNEL_BLOCK_ADDRESS
* makes the whole offset calculation and relocation obsolete. But the code * makes the whole offset calculation and relocation obsolete. But the code
+22 -12
View File
@@ -38,51 +38,61 @@ spinlock slock = 0;
uint32 round_to_pagesize(uint32 size); uint32 round_to_pagesize(uint32 size);
cpu_status lock(void)
cpu_status
lock(void)
{ {
cpu_status status = disable_interrupts(); cpu_status status = disable_interrupts();
acquire_spinlock(&slock); acquire_spinlock(&slock);
return status; return status;
} }
void unlock(cpu_status status)
void
unlock(cpu_status status)
{ {
release_spinlock(&slock); release_spinlock(&slock);
restore_interrupts(status); restore_interrupts(status);
} }
uint32 round_to_pagesize(uint32 size)
uint32
round_to_pagesize(uint32 size)
{ {
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
} }
area_id alloc_mem(void **phy, void **log, size_t size, const char *name)
area_id
alloc_mem(void **phy, void **log, size_t size, const char *name)
{ {
physical_entry pe; physical_entry pe;
void * logadr; void * logadr;
area_id areaid; area_id area;
status_t rv; status_t rv;
LOG(("allocating %d bytes for %s\n",size,name)); LOG(("allocating %d bytes for %s\n",size,name));
size = round_to_pagesize(size); size = round_to_pagesize(size);
areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS,size,B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); area = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS, size, B_CONTIGUOUS,
if (areaid < B_OK) { B_READ_AREA | B_WRITE_AREA);
if (area < B_OK) {
PRINT(("couldn't allocate area %s\n",name)); PRINT(("couldn't allocate area %s\n",name));
return B_ERROR; return B_ERROR;
} }
rv = get_memory_map(logadr,size,&pe,1); rv = get_memory_map(logadr, size, &pe, 1);
if (rv < B_OK) { if (rv < B_OK) {
delete_area(areaid); delete_area(area);
PRINT(("couldn't map %s\n",name)); PRINT(("couldn't map %s\n", name));
return B_ERROR; return B_ERROR;
} }
memset(logadr,0,size); memset(logadr, 0, size);
if (log) if (log)
*log = logadr; *log = logadr;
if (phy) if (phy)
*phy = pe.address; *phy = pe.address;
LOG(("area = %d, size = %d, log = %#08X, phy = %#08X\n",areaid,size,logadr,pe.address)); LOG(("area = %d, size = %d, log = %#08X, phy = %#08X\n", area, size, logadr,
pe.address));
return areaid; return areaid;
} }
+14 -5
View File
@@ -38,25 +38,33 @@ spinlock slock = B_SPINLOCK_INITIALIZER;
uint32 round_to_pagesize(uint32 size); uint32 round_to_pagesize(uint32 size);
cpu_status lock(void)
cpu_status
lock(void)
{ {
cpu_status status = disable_interrupts(); cpu_status status = disable_interrupts();
acquire_spinlock(&slock); acquire_spinlock(&slock);
return status; return status;
} }
void unlock(cpu_status status)
void
unlock(cpu_status status)
{ {
release_spinlock(&slock); release_spinlock(&slock);
restore_interrupts(status); restore_interrupts(status);
} }
uint32 round_to_pagesize(uint32 size)
uint32
round_to_pagesize(uint32 size)
{ {
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
} }
area_id alloc_mem(void **phy, void **log, size_t size, const char *name)
area_id
alloc_mem(void **phy, void **log, size_t size, const char *name)
{ {
physical_entry pe; physical_entry pe;
void * logadr; void * logadr;
@@ -66,7 +74,8 @@ area_id alloc_mem(void **phy, void **log, size_t size, const char *name)
LOG(("allocating %d bytes for %s\n",size,name)); LOG(("allocating %d bytes for %s\n",size,name));
size = round_to_pagesize(size); size = round_to_pagesize(size);
areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS,size,B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS, size,
B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
if (areaid < B_OK) { if (areaid < B_OK) {
PRINT(("couldn't allocate area %s\n",name)); PRINT(("couldn't allocate area %s\n",name));
return B_ERROR; return B_ERROR;
@@ -317,7 +317,7 @@ init_corb_rirb_pos(hda_controller* controller)
/* Allocate memory area */ /* Allocate memory area */
controller->corb_rirb_pos_area = create_area("hda corb/rirb/pos", controller->corb_rirb_pos_area = create_area("hda corb/rirb/pos",
(void**)&controller->corb, B_ANY_KERNEL_ADDRESS, memSize, (void**)&controller->corb, B_ANY_KERNEL_ADDRESS, memSize,
B_FULL_LOCK | B_CONTIGUOUS, 0); B_CONTIGUOUS, 0);
if (controller->corb_rirb_pos_area < 0) if (controller->corb_rirb_pos_area < 0)
return controller->corb_rirb_pos_area; return controller->corb_rirb_pos_area;
@@ -515,7 +515,7 @@ hda_stream_setup_buffers(hda_audio_group* audioGroup, hda_stream* stream,
/* Allocate memory for buffers */ /* Allocate memory for buffers */
stream->buffer_area = create_area("hda buffers", (void**)&buffer, stream->buffer_area = create_area("hda buffers", (void**)&buffer,
B_ANY_KERNEL_ADDRESS, alloc, B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); B_ANY_KERNEL_ADDRESS, alloc, B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
if (stream->buffer_area < B_OK) if (stream->buffer_area < B_OK)
return stream->buffer_area; return stream->buffer_area;
@@ -544,7 +544,7 @@ hda_stream_setup_buffers(hda_audio_group* audioGroup, hda_stream* stream,
stream->buffer_descriptors_area = create_area("hda buffer descriptors", stream->buffer_descriptors_area = create_area("hda buffer descriptors",
(void**)&bufferDescriptors, B_ANY_KERNEL_ADDRESS, alloc, (void**)&bufferDescriptors, B_ANY_KERNEL_ADDRESS, alloc,
B_FULL_LOCK | B_CONTIGUOUS, 0); B_CONTIGUOUS, 0);
if (stream->buffer_descriptors_area < B_OK) { if (stream->buffer_descriptors_area < B_OK) {
delete_area(stream->buffer_area); delete_area(stream->buffer_area);
return stream->buffer_descriptors_area; return stream->buffer_descriptors_area;
@@ -22,25 +22,33 @@ spinlock slock = 0;
uint32 round_to_pagesize(uint32 size); uint32 round_to_pagesize(uint32 size);
cpu_status lock(void)
cpu_status
lock(void)
{ {
cpu_status status = disable_interrupts(); cpu_status status = disable_interrupts();
acquire_spinlock(&slock); acquire_spinlock(&slock);
return status; return status;
} }
void unlock(cpu_status status)
void
unlock(cpu_status status)
{ {
release_spinlock(&slock); release_spinlock(&slock);
restore_interrupts(status); restore_interrupts(status);
} }
uint32 round_to_pagesize(uint32 size)
uint32
round_to_pagesize(uint32 size)
{ {
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
} }
area_id alloc_mem(void **phy, void **log, size_t size, const char *name)
area_id
alloc_mem(void **phy, void **log, size_t size, const char *name)
{ {
physical_entry pe; physical_entry pe;
void * logadr; void * logadr;
@@ -50,7 +58,8 @@ area_id alloc_mem(void **phy, void **log, size_t size, const char *name)
TRACE_ICE(("allocating %#08 bytes for %s\n",size,name)); TRACE_ICE(("allocating %#08 bytes for %s\n",size,name));
size = round_to_pagesize(size); size = round_to_pagesize(size);
areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS,size,B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS, size,
B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
if (areaid < B_OK) { if (areaid < B_OK) {
TRACE_ICE(("couldn't allocate area %s\n",name)); TRACE_ICE(("couldn't allocate area %s\n",name));
return B_ERROR; return B_ERROR;
+10 -5
View File
@@ -37,19 +37,22 @@
area_id area_id
map_mem(void **virt, void *phy, size_t size, uint32 protection, const char *name) map_mem(void **virt, void *phy, size_t size, uint32 protection,
const char *name)
{ {
uint32 offset; uint32 offset;
void *phyadr; void *phyadr;
void *mapadr; void *mapadr;
area_id area; area_id area;
TRACE("mapping physical address %p with %ld bytes for %s\n", phy, size, name); TRACE("mapping physical address %p with %ld bytes for %s\n", phy, size,
name);
offset = (uint32)phy & (B_PAGE_SIZE - 1); offset = (uint32)phy & (B_PAGE_SIZE - 1);
phyadr = (char *)phy - offset; phyadr = (char *)phy - offset;
size = ROUNDUP(size + offset, B_PAGE_SIZE); size = ROUNDUP(size + offset, B_PAGE_SIZE);
area = map_physical_memory(name, phyadr, size, B_ANY_KERNEL_BLOCK_ADDRESS, protection, &mapadr); area = map_physical_memory(name, phyadr, size, B_ANY_KERNEL_BLOCK_ADDRESS,
protection, &mapadr);
if (area < B_OK) { if (area < B_OK) {
TRACE("mapping '%s' failed, error 0x%lx (%s)\n", name, area, strerror(area)); TRACE("mapping '%s' failed, error 0x%lx (%s)\n", name, area, strerror(area));
return area; return area;
@@ -65,7 +68,8 @@ map_mem(void **virt, void *phy, size_t size, uint32 protection, const char *name
area_id area_id
alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *name) alloc_mem(void **virt, void **phy, size_t size, uint32 protection,
const char *name)
{ {
physical_entry pe; physical_entry pe;
void * virtadr; void * virtadr;
@@ -75,7 +79,8 @@ alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *n
TRACE("allocating %ld bytes for %s\n", size, name); TRACE("allocating %ld bytes for %s\n", size, name);
size = ROUNDUP(size, B_PAGE_SIZE); size = ROUNDUP(size, B_PAGE_SIZE);
areaid = create_area(name, &virtadr, B_ANY_KERNEL_ADDRESS, size, B_FULL_LOCK | B_CONTIGUOUS, protection); areaid = create_area(name, &virtadr, B_ANY_KERNEL_ADDRESS, size,
B_CONTIGUOUS, protection);
if (areaid < B_OK) { if (areaid < B_OK) {
TRACE("couldn't allocate area %s\n", name); TRACE("couldn't allocate area %s\n", name);
return B_ERROR; return B_ERROR;
@@ -475,7 +475,7 @@ static status_t map_device(device_info *di)
// &si->dma_buffer, // &si->dma_buffer,
// B_ANY_ADDRESS, // B_ANY_ADDRESS,
// G400_DMA_BUFFER_SIZE, // G400_DMA_BUFFER_SIZE,
// B_FULL_LOCK|B_CONTIGUOUS, // B_CONTIGUOUS,
// B_READ_AREA|B_WRITE_AREA); // B_READ_AREA|B_WRITE_AREA);
/* if there was an error, delete our other areas and pass on error*/ /* if there was an error, delete our other areas and pass on error*/
@@ -898,7 +898,7 @@ open_hook(const char* name, uint32 flags, void** cookie)
(void **)&unaligned_dma_buffer, (void **)&unaligned_dma_buffer,
B_ANY_KERNEL_ADDRESS, B_ANY_KERNEL_ADDRESS,
2 * net_buf_size, /* take twice the net size so we can have MTRR-WC even on old systems */ 2 * net_buf_size, /* take twice the net size so we can have MTRR-WC even on old systems */
B_FULL_LOCK | B_CONTIGUOUS, /* both properties needed: GPU always needs access */ B_CONTIGUOUS, /* GPU always needs access */
B_USER_CLONEABLE_AREA | B_READ_AREA | B_WRITE_AREA); B_USER_CLONEABLE_AREA | B_READ_AREA | B_WRITE_AREA);
/* on error, abort */ /* on error, abort */
if (si->unaligned_dma_area < 0) if (si->unaligned_dma_area < 0)
@@ -645,7 +645,7 @@ open_hook(const char* name, uint32 flags, void** cookie)
(void **)&unaligned_dma_buffer, (void **)&unaligned_dma_buffer,
B_ANY_KERNEL_ADDRESS, B_ANY_KERNEL_ADDRESS,
2 * net_buf_size, /* take twice the net size so we can have MTRR-WC even on old systems */ 2 * net_buf_size, /* take twice the net size so we can have MTRR-WC even on old systems */
B_FULL_LOCK | B_CONTIGUOUS, /* both properties needed: GPU always needs access */ B_CONTIGUOUS, /* GPU always needs access */
B_USER_CLONEABLE_AREA | B_READ_AREA | B_WRITE_AREA); B_USER_CLONEABLE_AREA | B_READ_AREA | B_WRITE_AREA);
/* on error, abort */ /* on error, abort */
if (si->unaligned_dma_area < 0) if (si->unaligned_dma_area < 0)
@@ -888,7 +888,7 @@ MM_AllocateSharedMemory(PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlockSize,
dev = (struct be_b57_dev *)(pDevice); dev = (struct be_b57_dev *)(pDevice);
area_desc = dev->lockmem_list[dev->lockmem_list_num++] = create_area("broadcom_shared_mem", area_desc = dev->lockmem_list[dev->lockmem_list_num++] = create_area("broadcom_shared_mem",
&pvirt, B_ANY_KERNEL_ADDRESS, ROUND_UP_TO_PAGE(BlockSize), &pvirt, B_ANY_KERNEL_ADDRESS, ROUND_UP_TO_PAGE(BlockSize),
B_CONTIGUOUS | B_FULL_LOCK, 0); B_CONTIGUOUS, 0);
if (area_desc < B_OK) if (area_desc < B_OK)
return LM_STATUS_FAILURE; return LM_STATUS_FAILURE;
@@ -645,16 +645,12 @@ static status_t init_ring_buffers(dp83815_properties_t *data)
pages = pages_needed(2*MAX_DESC*sizeof(descriptor_t) + NUM_BUFFS*BUFFER_SIZE); pages = pages_needed(2*MAX_DESC*sizeof(descriptor_t) + NUM_BUFFS*BUFFER_SIZE);
data->mem_area = create_area(kDevName " desc buffer", data->mem_area = create_area(kDevName " desc buffer", (void**)&RxDescRing,
(void**)&RxDescRing, B_ANY_KERNEL_ADDRESS, pages * B_PAGE_SIZE, B_CONTIGUOUS,
B_ANY_KERNEL_ADDRESS, B_READ_AREA | B_WRITE_AREA);
pages*B_PAGE_SIZE,
B_FULL_LOCK|B_CONTIGUOUS,
B_READ_AREA|B_WRITE_AREA);
if( data->mem_area < 0 ) if( data->mem_area < 0 )
return -1; return -1;
get_area_info(data->mem_area, &info); get_area_info(data->mem_area, &info);
get_memory_map(info.address, info.size, map, 4); get_memory_map(info.address, info.size, map, 4);
@@ -664,7 +660,6 @@ static status_t init_ring_buffers(dp83815_properties_t *data)
buff_base_phys_addr = (int)map[0].address; buff_base_phys_addr = (int)map[0].address;
buff_base_virt_addr = info.address; buff_base_virt_addr = info.address;
RxDescRing = desc_base_virt_addr; RxDescRing = desc_base_virt_addr;
for( i = 0; i < MAX_DESC; i++ ) { for( i = 0; i < MAX_DESC; i++ ) {
RxDescRing[i].link = desc_base_phys_addr + ((i+1)%MAX_DESC)*sizeof(descriptor_t); RxDescRing[i].link = desc_base_phys_addr + ((i+1)%MAX_DESC)*sizeof(descriptor_t);
@@ -35,25 +35,33 @@ spinlock slock = 0;
uint32 round_to_pagesize(uint32 size); uint32 round_to_pagesize(uint32 size);
cpu_status lock(void)
cpu_status
lock(void)
{ {
cpu_status status = disable_interrupts(); cpu_status status = disable_interrupts();
acquire_spinlock(&slock); acquire_spinlock(&slock);
return status; return status;
} }
void unlock(cpu_status status)
void
unlock(cpu_status status)
{ {
release_spinlock(&slock); release_spinlock(&slock);
restore_interrupts(status); restore_interrupts(status);
} }
uint32 round_to_pagesize(uint32 size)
uint32
round_to_pagesize(uint32 size)
{ {
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
} }
area_id alloc_mem(void **log, void **phy, size_t size, const char *name)
area_id
alloc_mem(void **log, void **phy, size_t size, const char *name)
{ {
physical_entry pe; physical_entry pe;
void * logadr; void * logadr;
@@ -63,7 +71,8 @@ area_id alloc_mem(void **log, void **phy, size_t size, const char *name)
dprintf("dp83815: allocating %ld bytes for %s\n",size,name); dprintf("dp83815: allocating %ld bytes for %s\n",size,name);
size = round_to_pagesize(size); size = round_to_pagesize(size);
areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS,size,B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); areaid = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS, size,
B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
if (areaid < B_OK) { if (areaid < B_OK) {
dprintf("couldn't allocate area %s\n",name); dprintf("couldn't allocate area %s\n",name);
return B_ERROR; return B_ERROR;
@@ -83,12 +92,14 @@ area_id alloc_mem(void **log, void **phy, size_t size, const char *name)
return areaid; return areaid;
} }
/* This is not the most advanced method to map physical memory for io access. /* 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 * Perhaps using B_ANY_KERNEL_ADDRESS instead of B_ANY_KERNEL_BLOCK_ADDRESS
* makes the whole offset calculation and relocation obsolete. But the code * 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. * 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) area_id
map_mem(void **log, void *phy, size_t size, const char *name)
{ {
uint32 offset; uint32 offset;
void *phyadr; void *phyadr;
@@ -23,39 +23,46 @@
#undef malloc #undef malloc
#undef free #undef free
void * void *
driver_malloc(int size, int p2, int p3) driver_malloc(int size, int p2, int p3)
{ {
return malloc(size); return malloc(size);
} }
void void
driver_free(void *p, int p2) driver_free(void *p, int p2)
{ {
free(p); free(p);
} }
void * void *
contigmalloc(int size, int p1, int p2, int p3, int p4, int p5, int p6) contigmalloc(int size, int p1, int p2, int p3, int p4, int p5, int p6)
{ {
void *adr; void *adr;
if (create_area("contigmalloc", &adr, B_ANY_KERNEL_ADDRESS, size, B_FULL_LOCK | B_CONTIGUOUS, 0) < 0) if (create_area("contigmalloc", &adr, B_ANY_KERNEL_ADDRESS, size,
return 0; B_CONTIGUOUS, 0) < B_OK)
return NULL;
return adr; return adr;
} }
void void
contigfree(void *p, int p1, int p2) contigfree(void *p, int p1, int p2)
{ {
delete_area(area_for(p)); delete_area(area_for(p));
} }
void void
callout_handle_init(struct callout_handle *handle) callout_handle_init(struct callout_handle *handle)
{ {
handle->timer = -1; handle->timer = -1;
} }
struct callout_handle struct callout_handle
timeout(timer_function func, void *cookie, bigtime_t timeout) timeout(timer_function func, void *cookie, bigtime_t timeout)
{ {
@@ -64,12 +71,14 @@ timeout(timer_function func, void *cookie, bigtime_t timeout)
return handle; return handle;
} }
void void
untimeout(timer_function func, void *cookie, struct callout_handle handle) untimeout(timer_function func, void *cookie, struct callout_handle handle)
{ {
delete_timer(handle.timer); delete_timer(handle.timer);
} }
struct resource * struct resource *
bus_alloc_resource(device_t dev, int type, int *rid, int d, int e, int f, int g) bus_alloc_resource(device_t dev, int type, int *rid, int d, int e, int f, int g)
{ {
@@ -108,6 +117,7 @@ bus_alloc_resource(device_t dev, int type, int *rid, int d, int e, int f, int g)
} }
} }
void void
bus_release_resource(device_t dev, int type, int reg, struct resource *res) bus_release_resource(device_t dev, int type, int reg, struct resource *res)
{ {
@@ -126,19 +136,21 @@ bus_release_resource(device_t dev, int type, int reg, struct resource *res)
} }
} }
uint32 uint32
rman_get_start(struct resource *res) rman_get_start(struct resource *res)
{ {
return (uint32)res; return (uint32)res;
} }
struct int_tag
{ struct int_tag {
interrupt_handler int_func; interrupt_handler int_func;
void *cookie; void *cookie;
int irq; int irq;
}; };
int int
bus_setup_intr(device_t dev, struct resource *res, int p3, interrupt_handler int_func, void *cookie, void **tag) bus_setup_intr(device_t dev, struct resource *res, int p3, interrupt_handler int_func, void *cookie, void **tag)
{ {
@@ -153,6 +165,7 @@ bus_setup_intr(device_t dev, struct resource *res, int p3, interrupt_handler int
return install_io_interrupt_handler(irq, int_func, cookie, 0); return install_io_interrupt_handler(irq, int_func, cookie, 0);
} }
void void
bus_teardown_intr(device_t dev, struct resource *res, void *tag) bus_teardown_intr(device_t dev, struct resource *res, void *tag)
{ {
@@ -921,7 +921,7 @@ IPW2100::AllocateContiguous(const char *name, void **logicalAddress,
size = (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); size = (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
void *virtualAddress = NULL; void *virtualAddress = NULL;
area_id area = create_area(name, &virtualAddress, B_ANY_KERNEL_ADDRESS, area_id area = create_area(name, &virtualAddress, B_ANY_KERNEL_ADDRESS,
size, B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); size, B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
if (area < B_OK) { if (area < B_OK) {
TRACE_ALWAYS(("IPW2100: allocating contiguous area failed\n")); TRACE_ALWAYS(("IPW2100: allocating contiguous area failed\n"));
return area; return area;
@@ -25,14 +25,17 @@
#include "debug.h" #include "debug.h"
#include "util.h" #include "util.h"
static inline uint32 static inline uint32
round_to_pagesize(uint32 size) round_to_pagesize(uint32 size)
{ {
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1); return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
} }
area_id area_id
alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *name) alloc_mem(void **virt, void **phy, size_t size, uint32 protection,
const char *name)
{ {
physical_entry pe; physical_entry pe;
void * virtadr; void * virtadr;
@@ -42,7 +45,8 @@ alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *n
TRACE("allocating %ld bytes for %s\n", size, name); TRACE("allocating %ld bytes for %s\n", size, name);
size = round_to_pagesize(size); size = round_to_pagesize(size);
areaid = create_area(name, &virtadr, B_ANY_KERNEL_ADDRESS, size, B_FULL_LOCK | B_CONTIGUOUS, protection); areaid = create_area(name, &virtadr, B_ANY_KERNEL_ADDRESS, size,
B_CONTIGUOUS, protection);
if (areaid < B_OK) { if (areaid < B_OK) {
ERROR("couldn't allocate area %s\n", name); ERROR("couldn't allocate area %s\n", name);
return B_ERROR; return B_ERROR;
@@ -62,8 +66,10 @@ alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *n
return areaid; return areaid;
} }
area_id area_id
map_mem(void **virt, void *phy, size_t size, uint32 protection, const char *name) map_mem(void **virt, void *phy, size_t size, uint32 protection,
const char *name)
{ {
uint32 offset; uint32 offset;
void *phyadr; void *phyadr;
@@ -75,7 +81,8 @@ map_mem(void **virt, void *phy, size_t size, uint32 protection, const char *name
offset = (uint32)phy & (B_PAGE_SIZE - 1); offset = (uint32)phy & (B_PAGE_SIZE - 1);
phyadr = (char *)phy - offset; phyadr = (char *)phy - offset;
size = round_to_pagesize(size + offset); size = round_to_pagesize(size + offset);
area = map_physical_memory(name, phyadr, size, B_ANY_KERNEL_BLOCK_ADDRESS, protection, &mapadr); area = map_physical_memory(name, phyadr, size, B_ANY_KERNEL_BLOCK_ADDRESS,
protection, &mapadr);
if (area < B_OK) { if (area < B_OK) {
ERROR("mapping '%s' failed, error 0x%lx (%s)\n", name, area, strerror(area)); ERROR("mapping '%s' failed, error 0x%lx (%s)\n", name, area, strerror(area));
return area; return area;
@@ -83,8 +90,9 @@ map_mem(void **virt, void *phy, size_t size, uint32 protection, const char *name
*virt = (char *)mapadr + offset; *virt = (char *)mapadr + offset;
TRACE("physical = %p, virtual = %p, offset = %ld, phyadr = %p, mapadr = %p, size = %ld, area = 0x%08lx\n", TRACE("physical = %p, virtual = %p, offset = %ld, phyadr = %p, mapadr = "
phy, *virt, offset, phyadr, mapadr, size, area); "%p, size = %ld, area = 0x%08lx\n", phy, *virt, offset, phyadr, mapadr,
size, area);
return area; return area;
} }
@@ -431,9 +431,8 @@ block_io_init_device(void *_data, void **cookie)
// (else, we may be on the paging path and have no S/G entries at hand) // (else, we may be on the paging path and have no S/G entries at hand)
device->phys_vecs_pool = locked_pool->create( device->phys_vecs_pool = locked_pool->create(
params.max_sg_blocks * sizeof(physical_entry), params.max_sg_blocks * sizeof(physical_entry),
sizeof( physical_entry ) - 1, sizeof( physical_entry ) - 1, 0, 16*1024, 32, 1, "block io sg lists",
0, 16*1024, 32, 1, "block io sg lists", B_FULL_LOCK | B_CONTIGUOUS, B_CONTIGUOUS, NULL, NULL, NULL);
NULL, NULL, NULL);
// free(tmp_name); // free(tmp_name);
@@ -492,7 +491,7 @@ block_io_init_buffer(void)
res = block_io_buffer_area = create_area("block_io_buffer", res = block_io_buffer_area = create_area("block_io_buffer",
(void **)&block_io_buffer, B_ANY_KERNEL_ADDRESS, (void **)&block_io_buffer, B_ANY_KERNEL_ADDRESS,
block_io_buffer_size, B_FULL_LOCK | B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA); block_io_buffer_size, B_CONTIGUOUS, B_READ_AREA | B_WRITE_AREA);
if (res < 0) if (res < 0)
goto err2; goto err2;
@@ -392,7 +392,7 @@ ide_adapter_init_channel(device_node *node,
// PRDT must be contiguous, dword-aligned and must not cross 64K boundary // PRDT must be contiguous, dword-aligned and must not cross 64K boundary
prdt_size = (IDE_ADAPTER_MAX_SG_COUNT * sizeof( prd_entry ) + (B_PAGE_SIZE - 1)) & ~(B_PAGE_SIZE - 1); prdt_size = (IDE_ADAPTER_MAX_SG_COUNT * sizeof( prd_entry ) + (B_PAGE_SIZE - 1)) & ~(B_PAGE_SIZE - 1);
channel->prd_area = create_area("prd", (void **)&channel->prdt, B_ANY_KERNEL_ADDRESS, channel->prd_area = create_area("prd", (void **)&channel->prdt, B_ANY_KERNEL_ADDRESS,
prdt_size, B_FULL_LOCK | B_CONTIGUOUS, 0); prdt_size, B_CONTIGUOUS, 0);
if (channel->prd_area < B_OK) { if (channel->prd_area < B_OK) {
res = channel->prd_area; res = channel->prd_area;
goto err2; goto err2;