* 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 "util.h"
static inline uint32
round_to_pagesize(uint32 size)
{
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
}
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;
void * virtadr;
area_id areaid;
void *virtadr;
area_id area;
status_t rv;
TRACE("allocating %ld bytes for %s\n", size, name);
size = round_to_pagesize(size);
areaid = create_area(name, &virtadr, B_ANY_KERNEL_ADDRESS, size, B_FULL_LOCK | B_CONTIGUOUS, protection);
if (areaid < B_OK) {
area = create_area(name, &virtadr, B_ANY_KERNEL_ADDRESS, size, B_CONTIGUOUS,
protection);
if (area < B_OK) {
ERROR("couldn't allocate area %s\n", name);
return B_ERROR;
}
rv = get_memory_map(virtadr, size, &pe, 1);
if (rv < B_OK) {
delete_area(areaid);
delete_area(area);
ERROR("couldn't get mapping for %s\n", name);
return B_ERROR;
}
@@ -58,33 +62,40 @@ alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *n
*virt = virtadr;
if (phy)
*phy = pe.address;
TRACE("area = %ld, size = %ld, virt = %p, phy = %p\n", areaid, size, virtadr, pe.address);
return areaid;
TRACE("area = %ld, size = %ld, virt = %p, phy = %p\n", area, size, virtadr,
pe.address);
return area;
}
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;
void *phyadr;
void *mapadr;
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);
phyadr = (char *)phy - 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) {
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;
}
*virt = (char *)mapadr + offset;
TRACE("physical = %p, virtual = %p, offset = %ld, phyadr = %p, mapadr = %p, size = %ld, area = 0x%08lx\n",
phy, *virt, offset, phyadr, mapadr, size, area);
TRACE("physical = %p, virtual = %p, offset = %ld, phyadr = %p, mapadr = "
"%p, size = %ld, area = 0x%08lx\n", phy, *virt, offset, phyadr, mapadr,
size, 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
// correctly
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);
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.
*
* 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",
(void **)&dma_buffer_address_unaligned,
B_ANY_KERNEL_ADDRESS, size,
B_FULL_LOCK | B_CONTIGUOUS, 0 );
B_ANY_KERNEL_ADDRESS, size, B_CONTIGUOUS, 0);
if (buffer->area < 0) {
SHOW_ERROR(2, "Cannot create contignous DMA buffer of %d bytes",
(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.
*
* Distributed under the terms of the MIT License.
@@ -174,8 +174,7 @@ init_temp_sg(void)
MAX_TEMP_SG_FRAGMENTS * sizeof(physical_entry),
sizeof(physical_entry) - 1, 0,
B_PAGE_SIZE, MAX_TEMP_SG_LISTS, 1,
"scsi_temp_sg_pool", B_FULL_LOCK | B_CONTIGUOUS,
NULL, NULL, NULL);
"scsi_temp_sg_pool", B_CONTIGUOUS, NULL, NULL, NULL);
if (temp_sg_pool == NULL)
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.
*
* Authors:
@@ -69,7 +69,7 @@ PhysicalMemoryAllocator::PhysicalMemoryAllocator(const char *name,
roundedSize = (roundedSize + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
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) {
TRACE_ERROR(("PMA: failed to create memory area\n"));
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.
*
* Authors:
@@ -282,7 +282,7 @@ Stack::AllocateArea(void **logicalAddress, void **physicalAddress, size_t size,
void *logAddress;
size = (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
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) {
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
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) {
TRACE("creating prd_area failed\n");
goto err;
+15 -6
View File
@@ -13,14 +13,17 @@
#define TRACE(a...) dprintf("\33[34mahci:\33[0m " a)
#define ERROR(a...) dprintf("\33[34mahci:\33[0m " a)
static inline uint32
round_to_pagesize(uint32 size)
{
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
}
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;
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);
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) {
ERROR("couldn't allocate area %s\n", name);
return B_ERROR;
@@ -49,8 +53,10 @@ alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *n
return areaid;
}
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;
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);
phyadr = (char *)phy - 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) {
ERROR("mapping '%s' failed, error 0x%lx (%s)\n", name, area, strerror(area));
return area;
@@ -78,14 +85,16 @@ map_mem(void **virt, void *phy, size_t size, uint32 protection, const char *name
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;
for (i = 0; i < sgCount && dataSize > 0; i++) {
size_t size = min_c(dataSize, sgTable[i].size);
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;
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);
cpu_status lock(void)
cpu_status
lock(void)
{
cpu_status status = disable_interrupts();
acquire_spinlock(&slock);
return status;
}
void unlock(cpu_status status)
void
unlock(cpu_status status)
{
release_spinlock(&slock);
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);
}
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;
void * logadr;
area_id areaid;
area_id area;
status_t rv;
LOG(("allocating %d bytes for %s\n",size,name));
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);
if (areaid < B_OK) {
PRINT(("couldn't allocate area %s\n",name));
area = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS, size, B_CONTIGUOUS,
B_READ_AREA | B_WRITE_AREA);
if (area < B_OK) {
PRINT(("couldn't allocate area %s\n", name));
return B_ERROR;
}
rv = get_memory_map(logadr,size,&pe,1);
rv = get_memory_map(logadr, size, &pe, 1);
if (rv < B_OK) {
delete_area(areaid);
delete_area(area);
PRINT(("couldn't map %s\n",name));
return B_ERROR;
}
memset(logadr,0,size);
memset(logadr, 0, size);
if (log)
*log = logadr;
if (phy)
*phy = pe.address;
LOG(("area = %d, size = %d, log = %#08X, phy = %#08X\n",areaid,size,logadr,pe.address));
return areaid;
LOG(("area = %d, size = %d, log = %#08X, phy = %#08X\n", area, size, logadr,
pe.address));
return area;
}
/* 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)
area_id
map_mem(void **log, void *phy, size_t size, const char *name)
{
uint32 offset;
void *phyadr;
@@ -38,25 +38,33 @@ spinlock slock = B_SPINLOCK_INITIALIZER;
uint32 round_to_pagesize(uint32 size);
cpu_status lock(void)
cpu_status
lock(void)
{
cpu_status status = disable_interrupts();
acquire_spinlock(&slock);
return status;
}
void unlock(cpu_status status)
void
unlock(cpu_status status)
{
release_spinlock(&slock);
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);
}
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;
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));
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) {
PRINT(("couldn't allocate area %s\n",name));
return B_ERROR;
@@ -38,25 +38,33 @@ spinlock slock = 0;
uint32 round_to_pagesize(uint32 size);
cpu_status lock(void)
cpu_status
lock(void)
{
cpu_status status = disable_interrupts();
acquire_spinlock(&slock);
return status;
}
void unlock(cpu_status status)
void
unlock(cpu_status status)
{
release_spinlock(&slock);
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);
}
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;
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));
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) {
PRINT(("couldn't allocate area %s\n",name));
return B_ERROR;
}
rv = get_memory_map(logadr,size,&pe,1);
rv = get_memory_map(logadr, size, &pe, 1);
if (rv < B_OK) {
delete_area(areaid);
PRINT(("couldn't map %s\n",name));
PRINT(("couldn't map %s\n", name));
return B_ERROR;
}
memset(logadr,0,size);
memset(logadr, 0, size);
if (log)
*log = logadr;
if (phy)
*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;
}
/* 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)
area_id
map_mem(void **log, void *phy, size_t size, const char *name)
{
uint32 offset;
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);
phyadr = 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);
area = map_physical_memory(name, phyadr, size, B_ANY_KERNEL_BLOCK_ADDRESS,
B_READ_AREA | B_WRITE_AREA, &mapadr);
*log = mapadr + offset;
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);
cpu_status lock(void)
cpu_status
lock(void)
{
cpu_status status = disable_interrupts();
acquire_spinlock(&slock);
return status;
}
void unlock(cpu_status status)
void
unlock(cpu_status status)
{
release_spinlock(&slock);
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);
}
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;
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));
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) {
PRINT(("couldn't allocate area %s\n",name));
return B_ERROR;
@@ -86,12 +95,14 @@ area_id alloc_mem(void **log, void **phy, 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)
area_id
map_mem(void **log, void *phy, size_t size, const char *name)
{
uint32 offset;
void *phyadr;
@@ -35,13 +35,17 @@
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);
}
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;
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));
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) {
PRINT(("couldn't allocate area %s\n",name));
return B_ERROR;
@@ -71,6 +76,7 @@ alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *n
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
+22 -12
View File
@@ -38,51 +38,61 @@ spinlock slock = 0;
uint32 round_to_pagesize(uint32 size);
cpu_status lock(void)
cpu_status
lock(void)
{
cpu_status status = disable_interrupts();
acquire_spinlock(&slock);
return status;
}
void unlock(cpu_status status)
void
unlock(cpu_status status)
{
release_spinlock(&slock);
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);
}
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;
void * logadr;
area_id areaid;
area_id area;
status_t rv;
LOG(("allocating %d bytes for %s\n",size,name));
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);
if (areaid < B_OK) {
area = create_area(name, &logadr, B_ANY_KERNEL_ADDRESS, size, B_CONTIGUOUS,
B_READ_AREA | B_WRITE_AREA);
if (area < B_OK) {
PRINT(("couldn't allocate area %s\n",name));
return B_ERROR;
}
rv = get_memory_map(logadr,size,&pe,1);
rv = get_memory_map(logadr, size, &pe, 1);
if (rv < B_OK) {
delete_area(areaid);
PRINT(("couldn't map %s\n",name));
delete_area(area);
PRINT(("couldn't map %s\n", name));
return B_ERROR;
}
memset(logadr,0,size);
memset(logadr, 0, size);
if (log)
*log = logadr;
if (phy)
*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;
}
+14 -5
View File
@@ -38,25 +38,33 @@ spinlock slock = B_SPINLOCK_INITIALIZER;
uint32 round_to_pagesize(uint32 size);
cpu_status lock(void)
cpu_status
lock(void)
{
cpu_status status = disable_interrupts();
acquire_spinlock(&slock);
return status;
}
void unlock(cpu_status status)
void
unlock(cpu_status status)
{
release_spinlock(&slock);
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);
}
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;
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));
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) {
PRINT(("couldn't allocate area %s\n",name));
return B_ERROR;
@@ -317,7 +317,7 @@ init_corb_rirb_pos(hda_controller* controller)
/* Allocate memory area */
controller->corb_rirb_pos_area = create_area("hda corb/rirb/pos",
(void**)&controller->corb, B_ANY_KERNEL_ADDRESS, memSize,
B_FULL_LOCK | B_CONTIGUOUS, 0);
B_CONTIGUOUS, 0);
if (controller->corb_rirb_pos_area < 0)
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 */
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)
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",
(void**)&bufferDescriptors, B_ANY_KERNEL_ADDRESS, alloc,
B_FULL_LOCK | B_CONTIGUOUS, 0);
B_CONTIGUOUS, 0);
if (stream->buffer_descriptors_area < B_OK) {
delete_area(stream->buffer_area);
return stream->buffer_descriptors_area;
@@ -22,25 +22,33 @@ spinlock slock = 0;
uint32 round_to_pagesize(uint32 size);
cpu_status lock(void)
cpu_status
lock(void)
{
cpu_status status = disable_interrupts();
acquire_spinlock(&slock);
return status;
}
void unlock(cpu_status status)
void
unlock(cpu_status status)
{
release_spinlock(&slock);
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);
}
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;
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));
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) {
TRACE_ICE(("couldn't allocate area %s\n",name));
return B_ERROR;
+10 -5
View File
@@ -37,19 +37,22 @@
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;
void *phyadr;
void *mapadr;
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);
phyadr = (char *)phy - offset;
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) {
TRACE("mapping '%s' failed, error 0x%lx (%s)\n", name, area, strerror(area));
return area;
@@ -65,7 +68,8 @@ map_mem(void **virt, void *phy, size_t size, uint32 protection, const char *name
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;
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);
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) {
TRACE("couldn't allocate area %s\n", name);
return B_ERROR;
@@ -475,7 +475,7 @@ static status_t map_device(device_info *di)
// &si->dma_buffer,
// B_ANY_ADDRESS,
// G400_DMA_BUFFER_SIZE,
// B_FULL_LOCK|B_CONTIGUOUS,
// B_CONTIGUOUS,
// B_READ_AREA|B_WRITE_AREA);
/* 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,
B_ANY_KERNEL_ADDRESS,
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);
/* on error, abort */
if (si->unaligned_dma_area < 0)
@@ -645,7 +645,7 @@ open_hook(const char* name, uint32 flags, void** cookie)
(void **)&unaligned_dma_buffer,
B_ANY_KERNEL_ADDRESS,
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);
/* on error, abort */
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);
area_desc = dev->lockmem_list[dev->lockmem_list_num++] = create_area("broadcom_shared_mem",
&pvirt, B_ANY_KERNEL_ADDRESS, ROUND_UP_TO_PAGE(BlockSize),
B_CONTIGUOUS | B_FULL_LOCK, 0);
B_CONTIGUOUS, 0);
if (area_desc < B_OK)
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);
data->mem_area = create_area(kDevName " desc buffer",
(void**)&RxDescRing,
B_ANY_KERNEL_ADDRESS,
pages*B_PAGE_SIZE,
B_FULL_LOCK|B_CONTIGUOUS,
B_READ_AREA|B_WRITE_AREA);
data->mem_area = create_area(kDevName " desc buffer", (void**)&RxDescRing,
B_ANY_KERNEL_ADDRESS, pages * B_PAGE_SIZE, B_CONTIGUOUS,
B_READ_AREA | B_WRITE_AREA);
if( data->mem_area < 0 )
return -1;
get_area_info(data->mem_area, &info);
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_virt_addr = info.address;
RxDescRing = desc_base_virt_addr;
for( i = 0; i < MAX_DESC; i++ ) {
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);
cpu_status lock(void)
cpu_status
lock(void)
{
cpu_status status = disable_interrupts();
acquire_spinlock(&slock);
return status;
}
void unlock(cpu_status status)
void
unlock(cpu_status status)
{
release_spinlock(&slock);
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);
}
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;
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);
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) {
dprintf("couldn't allocate area %s\n",name);
return B_ERROR;
@@ -83,12 +92,14 @@ area_id alloc_mem(void **log, void **phy, 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)
area_id
map_mem(void **log, void *phy, size_t size, const char *name)
{
uint32 offset;
void *phyadr;
@@ -23,39 +23,46 @@
#undef malloc
#undef free
void *
driver_malloc(int size, int p2, int p3)
{
return malloc(size);
}
void
driver_free(void *p, int p2)
{
free(p);
}
void *
contigmalloc(int size, int p1, int p2, int p3, int p4, int p5, int p6)
{
void *adr;
if (create_area("contigmalloc", &adr, B_ANY_KERNEL_ADDRESS, size, B_FULL_LOCK | B_CONTIGUOUS, 0) < 0)
return 0;
if (create_area("contigmalloc", &adr, B_ANY_KERNEL_ADDRESS, size,
B_CONTIGUOUS, 0) < B_OK)
return NULL;
return adr;
}
void
contigfree(void *p, int p1, int p2)
{
delete_area(area_for(p));
}
void
callout_handle_init(struct callout_handle *handle)
{
handle->timer = -1;
}
struct callout_handle
timeout(timer_function func, void *cookie, bigtime_t timeout)
{
@@ -64,12 +71,14 @@ timeout(timer_function func, void *cookie, bigtime_t timeout)
return handle;
}
void
untimeout(timer_function func, void *cookie, struct callout_handle handle)
{
delete_timer(handle.timer);
}
struct resource *
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
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
rman_get_start(struct resource *res)
{
return (uint32)res;
}
struct int_tag
{
struct int_tag {
interrupt_handler int_func;
void *cookie;
int irq;
};
int
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);
}
void
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);
void *virtualAddress = NULL;
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) {
TRACE_ALWAYS(("IPW2100: allocating contiguous area failed\n"));
return area;
@@ -25,14 +25,17 @@
#include "debug.h"
#include "util.h"
static inline uint32
round_to_pagesize(uint32 size)
{
return (size + B_PAGE_SIZE - 1) & ~(B_PAGE_SIZE - 1);
}
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;
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);
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) {
ERROR("couldn't allocate area %s\n", name);
return B_ERROR;
@@ -62,8 +66,10 @@ alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *n
return areaid;
}
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;
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);
phyadr = (char *)phy - 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) {
ERROR("mapping '%s' failed, error 0x%lx (%s)\n", name, area, strerror(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;
TRACE("physical = %p, virtual = %p, offset = %ld, phyadr = %p, mapadr = %p, size = %ld, area = 0x%08lx\n",
phy, *virt, offset, phyadr, mapadr, size, area);
TRACE("physical = %p, virtual = %p, offset = %ld, phyadr = %p, mapadr = "
"%p, size = %ld, area = 0x%08lx\n", phy, *virt, offset, phyadr, mapadr,
size, 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)
device->phys_vecs_pool = locked_pool->create(
params.max_sg_blocks * sizeof(physical_entry),
sizeof( physical_entry ) - 1,
0, 16*1024, 32, 1, "block io sg lists", B_FULL_LOCK | B_CONTIGUOUS,
NULL, NULL, NULL);
sizeof( physical_entry ) - 1, 0, 16*1024, 32, 1, "block io sg lists",
B_CONTIGUOUS, NULL, NULL, NULL);
// free(tmp_name);
@@ -492,7 +491,7 @@ block_io_init_buffer(void)
res = block_io_buffer_area = create_area("block_io_buffer",
(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)
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_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,
prdt_size, B_FULL_LOCK | B_CONTIGUOUS, 0);
prdt_size, B_CONTIGUOUS, 0);
if (channel->prd_area < B_OK) {
res = channel->prd_area;
goto err2;