From patchwork Thu Apr 8 23:47:13 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gomez Castellanos, Ivan" X-Patchwork-Id: 91564 X-Patchwork-Delegate: omar.ramirez@ti.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o38Nlbnu019212 for ; Thu, 8 Apr 2010 23:47:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933985Ab0DHXrW (ORCPT ); Thu, 8 Apr 2010 19:47:22 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:33494 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934020Ab0DHXrR convert rfc822-to-8bit (ORCPT ); Thu, 8 Apr 2010 19:47:17 -0400 Received: from dlep36.itg.ti.com ([157.170.170.91]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id o38NlEoY030538 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 8 Apr 2010 18:47:14 -0500 Received: from dlep26.itg.ti.com (localhost [127.0.0.1]) by dlep36.itg.ti.com (8.13.8/8.13.8) with ESMTP id o38NlEod014668; Thu, 8 Apr 2010 18:47:14 -0500 (CDT) Received: from dlee75.ent.ti.com (localhost [127.0.0.1]) by dlep26.itg.ti.com (8.13.8/8.13.8) with ESMTP id o38NlErH018230; Thu, 8 Apr 2010 18:47:14 -0500 (CDT) Received: from dlee01.ent.ti.com ([157.170.170.12]) by dlee75.ent.ti.com ([157.170.170.72]) with mapi; Thu, 8 Apr 2010 18:47:14 -0500 From: "Gomez Castellanos, Ivan" To: "linux-omap@vger.kernel.org" CC: Hiroshi DOYU , Felipe Contreras , Ameya Palande , "Menon, Nishanth" Date: Thu, 8 Apr 2010 18:47:13 -0500 Subject: [PATCH 03/13] DSPBRIDGE: Moving functions from mem.c to drv.c Thread-Topic: [PATCH 03/13] DSPBRIDGE: Moving functions from mem.c to drv.c Thread-Index: AcrXdNmI59Cg5d0aSzO0bw0ecEXNFQ== Message-ID: <818EF96F5A7CC84789DD014773DB09548F6481CF@dlee01.ent.ti.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 08 Apr 2010 23:47:38 +0000 (UTC) diff --git a/arch/arm/plat-omap/include/dspbridge/drv.h b/arch/arm/plat-omap/include/dspbridge/drv.h index 947cbdd..eeb5e23 100644 --- a/arch/arm/plat-omap/include/dspbridge/drv.h +++ b/arch/arm/plat-omap/include/dspbridge/drv.h @@ -390,4 +390,82 @@ extern dsp_status drv_release_resources(IN u32 dw_context, void bridge_recover_schedule(void); #endif +/* + * ======== mem_ext_phys_pool_init ======== + * Purpose: + * Uses the physical memory chunk passed for internal consitent memory + * allocations. + * physical address based on the page frame address. + * Parameters: + * poolPhysBase starting address of the physical memory pool. + * poolSize size of the physical memory pool. + * Returns: + * none. + * Requires: + * - MEM initialized. + * - valid physical address for the base and size > 0 + */ +extern void mem_ext_phys_pool_init(IN u32 poolPhysBase, IN u32 poolSize); + +/* + * ======== mem_ext_phys_pool_release ======== + */ +extern void mem_ext_phys_pool_release(void); + +/* ======== mem_alloc_phys_mem ======== + * Purpose: + * Allocate physically contiguous, uncached memory + * Parameters: + * byte_size: Number of bytes to allocate. + * ulAlign: Alignment Mask. + * pPhysicalAddress: Physical address of allocated memory. + * Returns: + * Pointer to a block of memory; + * NULL if memory couldn't be allocated, or if byte_size == 0. + * Requires: + * MEM initialized. + * Ensures: + * The returned pointer, if not NULL, points to a valid memory block of + * the size requested. Returned physical address refers to physical + * location of memory. + */ +extern void *mem_alloc_phys_mem(IN u32 byte_size, + IN u32 ulAlign, OUT u32 *pPhysicalAddress); + +/* + * ======== mem_flush_cache ======== + * Purpose: + * Performs system cache sync with discard + * Parameters: + * pMemBuf: Pointer to memory region to be flushed. + * pMemBuf: Size of the memory region to be flushed. + * Returns: + * Requires: + * MEM is initialized. + * Ensures: + * Cache is synchronized + */ +extern void mem_flush_cache(void *pMemBuf, u32 byte_size, s32 FlushType); + +/* + * ======== mem_free_phys_mem ======== + * Purpose: + * Free the given block of physically contiguous memory. + * Parameters: + * pVirtualAddress: Pointer to virtual memory region allocated + * by mem_alloc_phys_mem(). + * pPhysicalAddress: Pointer to physical memory region allocated + * by mem_alloc_phys_mem(). + * byte_size: Size of the memory region allocated by mem_alloc_phys_mem(). + * Returns: + * Requires: + * MEM initialized. + * pVirtualAddress is a valid memory address returned by + * mem_alloc_phys_mem() + * Ensures: + * pVirtualAddress is no longer a valid pointer to memory. + */ +extern void mem_free_phys_mem(void *pVirtualAddress, + u32 pPhysicalAddress, u32 byte_size); + #endif /* DRV_ */ diff --git a/arch/arm/plat-omap/include/dspbridge/mem.h b/arch/arm/plat-omap/include/dspbridge/mem.h index 47f32dd..374b971 100644 --- a/arch/arm/plat-omap/include/dspbridge/mem.h +++ b/arch/arm/plat-omap/include/dspbridge/mem.h @@ -68,26 +68,6 @@ extern void *mem_alloc(IN u32 byte_size, IN enum mem_poolattrs type); } \ } -/* ======== mem_alloc_phys_mem ======== - * Purpose: - * Allocate physically contiguous, uncached memory - * Parameters: - * byte_size: Number of bytes to allocate. - * ulAlign: Alignment Mask. - * pPhysicalAddress: Physical address of allocated memory. - * Returns: - * Pointer to a block of memory; - * NULL if memory couldn't be allocated, or if byte_size == 0. - * Requires: - * MEM initialized. - * Ensures: - * The returned pointer, if not NULL, points to a valid memory block of - * the size requested. Returned physical address refers to physical - * location of memory. - */ -extern void *mem_alloc_phys_mem(IN u32 byte_size, - IN u32 ulAlign, OUT u32 *pPhysicalAddress); - /* * ======== mem_calloc ======== * Purpose: @@ -124,42 +104,6 @@ extern void *mem_calloc(IN u32 byte_size, IN enum mem_poolattrs type); extern void mem_exit(void); /* - * ======== mem_flush_cache ======== - * Purpose: - * Performs system cache sync with discard - * Parameters: - * pMemBuf: Pointer to memory region to be flushed. - * pMemBuf: Size of the memory region to be flushed. - * Returns: - * Requires: - * MEM is initialized. - * Ensures: - * Cache is synchronized - */ -extern void mem_flush_cache(void *pMemBuf, u32 byte_size, s32 FlushType); - -/* - * ======== mem_free_phys_mem ======== - * Purpose: - * Free the given block of physically contiguous memory. - * Parameters: - * pVirtualAddress: Pointer to virtual memory region allocated - * by mem_alloc_phys_mem(). - * pPhysicalAddress: Pointer to physical memory region allocated - * by mem_alloc_phys_mem(). - * byte_size: Size of the memory region allocated by mem_alloc_phys_mem(). - * Returns: - * Requires: - * MEM initialized. - * pVirtualAddress is a valid memory address returned by - * mem_alloc_phys_mem() - * Ensures: - * pVirtualAddress is no longer a valid pointer to memory. - */ -extern void mem_free_phys_mem(void *pVirtualAddress, - u32 pPhysicalAddress, u32 byte_size); - -/* * ======== MEM_FREE_OBJECT ======== * Purpose: * Utility macro to invalidate an object's signature, and deallocate it. @@ -255,26 +199,4 @@ extern bool services_mem_init(void); */ #define MEM_UNMAP_LINEAR_ADDRESS(pBaseAddr) {} -/* - * ======== mem_ext_phys_pool_init ======== - * Purpose: - * Uses the physical memory chunk passed for internal consitent memory - * allocations. - * physical address based on the page frame address. - * Parameters: - * poolPhysBase starting address of the physical memory pool. - * poolSize size of the physical memory pool. - * Returns: - * none. - * Requires: - * - MEM initialized. - * - valid physical address for the base and size > 0 - */ -extern void mem_ext_phys_pool_init(IN u32 poolPhysBase, IN u32 poolSize); - -/* - * ======== mem_ext_phys_pool_release ======== - */ -extern void mem_ext_phys_pool_release(void); - #endif /* MEM_ */ diff --git a/drivers/dsp/bridge/rmgr/drv.c b/drivers/dsp/bridge/rmgr/drv.c index 77b54d8..04c7133 100644 --- a/drivers/dsp/bridge/rmgr/drv.c +++ b/drivers/dsp/bridge/rmgr/drv.c @@ -64,6 +64,14 @@ struct drv_ext { /* ----------------------------------- Globals */ static s32 refs; +static bool ext_phys_mem_pool_enabled; +struct ext_phys_mem_pool { + u32 phys_mem_base; + u32 phys_mem_size; + u32 virt_mem_base; + u32 next_phys_alloc_ptr; +}; +static struct ext_phys_mem_pool ext_mem_pool; /* ----------------------------------- Function Prototypes */ static dsp_status request_bridge_resources(u32 dw_context, s32 fRequest); @@ -1068,3 +1076,148 @@ static dsp_status request_bridge_resources_dsp(u32 dw_context, s32 bRequest) /* End Mem alloc */ return status; } + +void mem_ext_phys_pool_init(u32 poolPhysBase, u32 poolSize) +{ + u32 pool_virt_base; + + /* get the virtual address for the physical memory pool passed */ + pool_virt_base = (u32) ioremap(poolPhysBase, poolSize); + + if ((void **)pool_virt_base == NULL) { + pr_err("%s: external physical memory map failed\n", __func__); + ext_phys_mem_pool_enabled = false; + } else { + ext_mem_pool.phys_mem_base = poolPhysBase; + ext_mem_pool.phys_mem_size = poolSize; + ext_mem_pool.virt_mem_base = pool_virt_base; + ext_mem_pool.next_phys_alloc_ptr = poolPhysBase; + ext_phys_mem_pool_enabled = true; + } +} + +void mem_ext_phys_pool_release(void) +{ + if (ext_phys_mem_pool_enabled) { + iounmap((void *)(ext_mem_pool.virt_mem_base)); + ext_phys_mem_pool_enabled = false; + } +} + +/* + * ======== mem_ext_phys_mem_alloc ======== + * Purpose: + * Allocate physically contiguous, uncached memory from external memory pool + */ + +static void *mem_ext_phys_mem_alloc(u32 bytes, u32 align, OUT u32 * pPhysAddr) +{ + u32 new_alloc_ptr; + u32 offset; + u32 virt_addr; + + if (align == 0) + align = 1; + + if (bytes > ((ext_mem_pool.phys_mem_base + ext_mem_pool.phys_mem_size) + - ext_mem_pool.next_phys_alloc_ptr)) { + pPhysAddr = NULL; + return NULL; + } else { + offset = (ext_mem_pool.next_phys_alloc_ptr & (align - 1)); + if (offset == 0) + new_alloc_ptr = ext_mem_pool.next_phys_alloc_ptr; + else + new_alloc_ptr = (ext_mem_pool.next_phys_alloc_ptr) + + (align - offset); + if ((new_alloc_ptr + bytes) <= + (ext_mem_pool.phys_mem_base + ext_mem_pool.phys_mem_size)) { + /* we can allocate */ + *pPhysAddr = new_alloc_ptr; + ext_mem_pool.next_phys_alloc_ptr = + new_alloc_ptr + bytes; + virt_addr = + ext_mem_pool.virt_mem_base + (new_alloc_ptr - + ext_mem_pool. + phys_mem_base); + return (void *)virt_addr; + } else { + *pPhysAddr = 0; + return NULL; + } + } +} + +/* + * ======== mem_alloc_phys_mem ======== + * Purpose: + * Allocate physically contiguous, uncached memory + */ +void *mem_alloc_phys_mem(u32 byte_size, u32 ulAlign, OUT u32 * pPhysicalAddress) +{ + void *va_mem = NULL; + dma_addr_t pa_mem; + + if (byte_size > 0) { + if (ext_phys_mem_pool_enabled) { + va_mem = mem_ext_phys_mem_alloc(byte_size, ulAlign, + (u32 *) &pa_mem); + } else + va_mem = dma_alloc_coherent(NULL, byte_size, &pa_mem, + GFP_KERNEL); + if (va_mem == NULL) + *pPhysicalAddress = 0; + else + *pPhysicalAddress = pa_mem; + } + return va_mem; +} + +/* + * ======== mem_flush_cache ======== + * Purpose: + * Flush cache + */ +void mem_flush_cache(void *pMemBuf, u32 byte_size, s32 FlushType) +{ + if (!pMemBuf) + return; + + switch (FlushType) { + /* invalidate only */ + case PROC_INVALIDATE_MEM: + dmac_inv_range(pMemBuf, pMemBuf + byte_size); + outer_inv_range(__pa((u32) pMemBuf), __pa((u32) pMemBuf + + byte_size)); + break; + /* writeback only */ + case PROC_WRITEBACK_MEM: + dmac_clean_range(pMemBuf, pMemBuf + byte_size); + outer_clean_range(__pa((u32) pMemBuf), __pa((u32) pMemBuf + + byte_size)); + break; + /* writeback and invalidate */ + case PROC_WRITEBACK_INVALIDATE_MEM: + dmac_flush_range(pMemBuf, pMemBuf + byte_size); + outer_flush_range(__pa((u32) pMemBuf), __pa((u32) pMemBuf + + byte_size)); + break; + } + +} + +/* + * ======== mem_free_phys_mem ======== + * Purpose: + * Free the given block of physically contiguous memory. + */ +void mem_free_phys_mem(void *pVirtualAddress, u32 pPhysicalAddress, + u32 byte_size) +{ + DBC_REQUIRE(pVirtualAddress != NULL); + + if (!ext_phys_mem_pool_enabled) + dma_free_coherent(NULL, byte_size, pVirtualAddress, + pPhysicalAddress); +} + diff --git a/drivers/dsp/bridge/services/mem.c b/drivers/dsp/bridge/services/mem.c index 916a49f..6e8834a 100644 --- a/drivers/dsp/bridge/services/mem.c +++ b/drivers/dsp/bridge/services/mem.c @@ -35,87 +35,7 @@ #define MEM512MB 0x1fffffff /* ----------------------------------- Globals */ -static bool ext_phys_mem_pool_enabled; -struct ext_phys_mem_pool { - u32 phys_mem_base; - u32 phys_mem_size; - u32 virt_mem_base; - u32 next_phys_alloc_ptr; -}; - -static struct ext_phys_mem_pool ext_mem_pool; - -void mem_ext_phys_pool_init(u32 poolPhysBase, u32 poolSize) -{ - u32 pool_virt_base; - - /* get the virtual address for the physical memory pool passed */ - pool_virt_base = (u32) ioremap(poolPhysBase, poolSize); - - if ((void **)pool_virt_base == NULL) { - pr_err("%s: external physical memory map failed\n", __func__); - ext_phys_mem_pool_enabled = false; - } else { - ext_mem_pool.phys_mem_base = poolPhysBase; - ext_mem_pool.phys_mem_size = poolSize; - ext_mem_pool.virt_mem_base = pool_virt_base; - ext_mem_pool.next_phys_alloc_ptr = poolPhysBase; - ext_phys_mem_pool_enabled = true; - } -} - -void mem_ext_phys_pool_release(void) -{ - if (ext_phys_mem_pool_enabled) { - iounmap((void *)(ext_mem_pool.virt_mem_base)); - ext_phys_mem_pool_enabled = false; - } -} - -/* - * ======== mem_ext_phys_mem_alloc ======== - * Purpose: - * Allocate physically contiguous, uncached memory from external memory pool - */ - -static void *mem_ext_phys_mem_alloc(u32 bytes, u32 align, OUT u32 * pPhysAddr) -{ - u32 new_alloc_ptr; - u32 offset; - u32 virt_addr; - - if (align == 0) - align = 1; - - if (bytes > ((ext_mem_pool.phys_mem_base + ext_mem_pool.phys_mem_size) - - ext_mem_pool.next_phys_alloc_ptr)) { - pPhysAddr = NULL; - return NULL; - } else { - offset = (ext_mem_pool.next_phys_alloc_ptr & (align - 1)); - if (offset == 0) - new_alloc_ptr = ext_mem_pool.next_phys_alloc_ptr; - else - new_alloc_ptr = (ext_mem_pool.next_phys_alloc_ptr) + - (align - offset); - if ((new_alloc_ptr + bytes) <= - (ext_mem_pool.phys_mem_base + ext_mem_pool.phys_mem_size)) { - /* we can allocate */ - *pPhysAddr = new_alloc_ptr; - ext_mem_pool.next_phys_alloc_ptr = - new_alloc_ptr + bytes; - virt_addr = - ext_mem_pool.virt_mem_base + (new_alloc_ptr - - ext_mem_pool. - phys_mem_base); - return (void *)virt_addr; - } else { - *pPhysAddr = 0; - return NULL; - } - } -} /* * ======== mem_alloc ======== @@ -146,31 +66,6 @@ void *mem_alloc(u32 byte_size, enum mem_poolattrs type) return mem; } -/* - * ======== mem_alloc_phys_mem ======== - * Purpose: - * Allocate physically contiguous, uncached memory - */ -void *mem_alloc_phys_mem(u32 byte_size, u32 ulAlign, OUT u32 * pPhysicalAddress) -{ - void *va_mem = NULL; - dma_addr_t pa_mem; - - if (byte_size > 0) { - if (ext_phys_mem_pool_enabled) { - va_mem = mem_ext_phys_mem_alloc(byte_size, ulAlign, - (u32 *) &pa_mem); - } else - va_mem = dma_alloc_coherent(NULL, byte_size, &pa_mem, - (in_atomic()) ? GFP_ATOMIC : - GFP_KERNEL); - if (va_mem == NULL) - *pPhysicalAddress = 0; - else - *pPhysicalAddress = pa_mem; - } - return va_mem; -} /* * ======== mem_calloc ======== @@ -211,53 +106,7 @@ void mem_exit(void) { } -/* - * ======== mem_flush_cache ======== - * Purpose: - * Flush cache - */ -void mem_flush_cache(void *pMemBuf, u32 byte_size, s32 FlushType) -{ - if (!pMemBuf) - return; - - switch (FlushType) { - /* invalidate only */ - case PROC_INVALIDATE_MEM: - dmac_inv_range(pMemBuf, pMemBuf + byte_size); - outer_inv_range(__pa((u32) pMemBuf), __pa((u32) pMemBuf + - byte_size)); - break; - /* writeback only */ - case PROC_WRITEBACK_MEM: - dmac_clean_range(pMemBuf, pMemBuf + byte_size); - outer_clean_range(__pa((u32) pMemBuf), __pa((u32) pMemBuf + - byte_size)); - break; - /* writeback and invalidate */ - case PROC_WRITEBACK_INVALIDATE_MEM: - dmac_flush_range(pMemBuf, pMemBuf + byte_size); - outer_flush_range(__pa((u32) pMemBuf), __pa((u32) pMemBuf + - byte_size)); - break; - } - -} - -/* - * ======== mem_free_phys_mem ======== - * Purpose: - * Free the given block of physically contiguous memory. - */ -void mem_free_phys_mem(void *pVirtualAddress, u32 pPhysicalAddress, - u32 byte_size) -{ - DBC_REQUIRE(pVirtualAddress != NULL); - if (!ext_phys_mem_pool_enabled) - dma_free_coherent(NULL, byte_size, pVirtualAddress, - pPhysicalAddress); -} /* * ======== services_mem_init ========