User`s guide

62 Appendix B
B.3.4 Create Memory Buffer for Other Side
int allocatePools(Spull_Dev *pDE)
{
ULONG address;
int order = bytes_to_order(SPULL_SIZE*1024);
int bytes;
do {
address = __get_free_pages(GFP_KERNEL, order);
if (address != 0) /* Success */
{
bytes = PAGE_SIZE << order;
memset((void *) address, 0, bytes);
pDE->RemoteUserBufferSize=bytes;
PDEBUG("allocatePools: Allocating Common Buffer for %0lX
bytes.\n",pDE->RemoteUserBufferSize);
pDE->RemoteUserBufferVirtualAddr=(u32 *) address;
pDE->RemoteUserBufferLogicalAddr=virt_to_bus((u32 *)address);
//phy == logical
pDE->RemoteUserBufferPhysicalAddr
=pDE->RemoteUserBufferLogicalAddr;
PDEBUG("allocatePools: common buffer virtual:%p, logical:%08lX.\n",
pDE->RemoteUserBufferVirtualAddr,
pDE->RemoteUserBufferLogicalAddr);
pDE->RemoteUserBufferLogicalAddrMax =
pDE->RemoteUserBufferLogicalAddr
+ pDE->RemoteUserBufferSize;
pDE->RemoteUserBufferOffsetAddr =
(ULONG)pDE->RemoteUserBufferVirtualAddr
- pDE->RemoteUserBufferLogicalAddr;
break;
}
if ((PAGE_SIZE << --order) < MIN_DISK_SIZE)
{
order = -1; /* Too small - give up */
PWARN("allocatePools: Failed to allocate requested any Map Registers.\n");
return ERR_ALLOC_FAIL;
}
} while (order >= 0);
return 0;