TI TILER-DMM driver
Subsystems (5)
cover TI TILER-DMM driver
TILER is a hardware block made by Texas Instruments. Its purpose is to organize video/image memory in a 2-dimensional fashion to limit memory bandwidth and facilitate 0 effort rotation and mirroring. The TILER driver facilitates allocating, freeing, as well as mapping 2D blocks (areas) in the TILER container(s). It also facilitates rotating and mirroring the allocated blocks or its rectangular subsections.
List of pending items in proposed order:
* Add area packing support (multiple blocks can reside in the same band/area) to optimize area use
* Add group-ID support (to specify which blocks can reside together in the same area)
* Add multiple search directions to TCM-SiTA
* Add 1D block support (including adding 1D search algo to TCM-SiTA)
* Optimize mutex handling (don.t hold mutex during memory allocation/mapping/cache flushing)
* Add block reference counting, support for sharing blocks
* Move all kernel-API-s to tiler-iface.c
* Support orphaned block support (in preparation for process cleanup support)
* Change block identification from physical address to key-ID pair (in preparation for user space support, and process security)
* Add support for process security (blocks from separate processes never reside in the same band)
* Support file interface (ioctl and mmap)
* Support for buffers (ordered list of blocks that are mapped to userspace together, such as YUV420sp)
* Support 1D user buffer mapping into TILER container
* Support for block pre-reservation (to further optimize area use)
David Sin (1):
TILER-DMM: DMM-PAT driver for TI TILER
Lajos Molnar (6):
TILER-DMM: Container manager interface and utility definitons
TILER-DMM: TILER Memory Manager interface and implementation
TILER-DMM: TILER interface file and documentation
TILER-DMM: Geometry and view manipulation functions.
TILER-DMM: Main TILER driver implementation.
TILER-DMM: Linking TILER driver into the Linux kernel build
Ravi Ramachandra (1):
TILER-DMM: Sample TCM implementation: Simple TILER Allocator
Documentation/arm/TILER | 144 +++++++++ arch/arm/mach-omap2/include/mach/dmm.h | 128 ++++++++ arch/arm/mach-omap2/include/mach/tiler.h | 201 +++++++++++++ drivers/media/Kconfig | 6 + drivers/media/Makefile | 2 + drivers/media/video/tiler/Kconfig | 65 ++++ drivers/media/video/tiler/Makefile | 7 + drivers/media/video/tiler/_tiler.h | 51 ++++ drivers/media/video/tiler/dmm.c | 200 +++++++++++++ drivers/media/video/tiler/tcm.h | 209 +++++++++++++ drivers/media/video/tiler/tcm/Makefile | 1 + drivers/media/video/tiler/tcm/_tcm-sita.h | 64 ++++ drivers/media/video/tiler/tcm/tcm-sita.c | 459 +++++++++++++++++++++++++++++ drivers/media/video/tiler/tcm/tcm-sita.h | 37 +++ drivers/media/video/tiler/tcm/tcm-utils.h | 54 ++++ drivers/media/video/tiler/tiler-geom.c | 360 ++++++++++++++++++++++ drivers/media/video/tiler/tiler-iface.c | 106 +++++++ drivers/media/video/tiler/tiler-main.c | 426 ++++++++++++++++++++++++++ drivers/media/video/tiler/tmm-pat.c | 274 +++++++++++++++++ drivers/media/video/tiler/tmm.h | 109 +++++++ 20 files changed, 2903 insertions(+), 0 deletions(-) create mode 100644 Documentation/arm/TILER create mode 100644 arch/arm/mach-omap2/include/mach/dmm.h create mode 100644 arch/arm/mach-omap2/include/mach/tiler.h create mode 100644 drivers/media/video/tiler/Kconfig create mode 100644 drivers/media/video/tiler/Makefile create mode 100644 drivers/media/video/tiler/_tiler.h create mode 100644 drivers/media/video/tiler/dmm.c create mode 100644 drivers/media/video/tiler/tcm.h create mode 100644 drivers/media/video/tiler/tcm/Makefile create mode 100644 drivers/media/video/tiler/tcm/_tcm-sita.h create mode 100644 drivers/media/video/tiler/tcm/tcm-sita.c create mode 100644 drivers/media/video/tiler/tcm/tcm-sita.h create mode 100644 drivers/media/video/tiler/tcm/tcm-utils.h create mode 100644 drivers/media/video/tiler/tiler-geom.c create mode 100644 drivers/media/video/tiler/tiler-iface.c create mode 100644 drivers/media/video/tiler/tiler-main.c create mode 100644 drivers/media/video/tiler/tmm-pat.c create mode 100644 drivers/media/video/tiler/tmm.h
RFC 1/8 TILER-DMM: DMM-PAT driver for TI TILER
This patch adds support for DMM-PAT initialization and programming.
--- arch/arm/mach-omap2/include/mach/dmm.h | 128 ++++++++++++++++++++ drivers/media/video/tiler/dmm.c | 200 ++++++++++++++++++++++++++++++++ 2 files changed, 328 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-omap2/include/mach/dmm.h create mode 100644 drivers/media/video/tiler/dmm.c
arch/arm/mach-omap2/include/mach/dmm.h new file +128 -0
@@ -0,0 +1,128 @@ +/* +* dmm.h +* +* DMM driver support functions for TI DMM-TILER hardware block. +* +* Author: David Sin <[email protected]> +* +* Copyright (C) 2009-2010 Texas Instruments, Inc. +* +* This package is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#ifndef DMM_H +#define DMM_H + +#define DMM_BASE 0x4E000000 +#define DMM_SIZE 0x800 + +#define DMM_REVISION 0x000 +#define DMM_HWINFO 0x004 +#define DMM_LISA_HWINFO 0x008 +#define DMM_DMM_SYSCONFIG 0x010 +#define DMM_LISA_LOCK 0x01C +#define DMM_LISA_MAP__0 0x040 +#define DMM_LISA_MAP__1 0x044 +#define DMM_TILER_HWINFO 0x208 +#define DMM_TILER_OR__0 0x220 +#define DMM_TILER_OR__1 0x224 +#define DMM_PAT_HWINFO 0x408 +#define DMM_PAT_GEOMETRY 0x40C +#define DMM_PAT_CONFIG 0x410 +#define DMM_PAT_VIEW__0 0x420 +#define DMM_PAT_VIEW__1 0x424 +#define DMM_PAT_VIEW_MAP__0 0x440 +#define DMM_PAT_VIEW_MAP_BASE 0x460 +#define DMM_PAT_IRQ_EOI 0x478 +#define DMM_PAT_IRQSTATUS_RAW 0x480 +#define DMM_PAT_IRQSTATUS 0x490 +#define DMM_PAT_IRQENABLE_SET 0x4A0 +#define DMM_PAT_IRQENABLE_CLR 0x4B0 +#define DMM_PAT_STATUS__0 0x4C0 +#define DMM_PAT_STATUS__1 0x4C4 +#define DMM_PAT_STATUS__2 0x4C8 +#define DMM_PAT_STATUS__3 0x4CC +#define DMM_PAT_DESCR__0 0x500 +#define DMM_PAT_AREA__0 0x504 +#define DMM_PAT_CTRL__0 0x508 +#define DMM_PAT_DATA__0 0x50C +#define DMM_PEG_HWINFO 0x608 +#define DMM_PEG_PRIO 0x620 +#define DMM_PEG_PRIO_PAT 0x640 + +/** +* PAT refill programming mode. +*/ +enum pat_mode { +MANUAL , +AUTO +}; + +/** +* Area definition for DMM physical address translator. +*/ +struct pat_area { +s32 x0:8 ; +s32 y0:8 ; +s32 x1:8 ; +s32 y1:8 ; +}; + +/** +* DMM physical address translator control. +*/ +struct pat_ctrl { +s32 start:4 ; +s32 dir:4 ; +s32 lut_id:8 ; +s32 sync:12 ; +s32 ini:4 ; +}; + +/** +* PAT descriptor. +*/ +struct pat { +struct pat *next; +struct pat_area area; +struct pat_ctrl ctrl; +u32 data; +}; + +/** +* DMM device data +*/ +struct dmm { +void __iomem *base; +}; + +/** +* Create and initialize the physical address translator. +* @param id PAT id +* @return pointer to device data +*/ +struct dmm *dmm_pat_init (u32 id); + +/** +* Program the physical address translator. +* @param dmm Device data +* @param desc PAT descriptor +* @param mode programming mode +* @return an error status. +*/ +s32 dmm_pat_refill (struct dmm *dmm,struct pat *desc,enum pat_mode mode); + +/** +* Clean up the physical address translator. +* @param dmm Device data +* @return an error status. +*/ +void dmm_pat_release (struct dmm *dmm); + +#endif
drivers/media/video/tiler/dmm.c new file +200 -0
200 lines not on this page · raw message
Signature · 1 line
1.6.3.3
RFC 2/8 TILER-DMM: Container manager interface and utility definitons
From: Lajos Molnar <[email protected]>
This patch defined the TILER Container Manager (TCM) interface and provides utility methods for implementing a TCM.
--- drivers/media/video/tiler/tcm.h | 209 +++++++++++++++++++++++++++++ drivers/media/video/tiler/tcm/tcm-utils.h | 54 ++++++++ 2 files changed, 263 insertions(+), 0 deletions(-) create mode 100644 drivers/media/video/tiler/tcm.h create mode 100644 drivers/media/video/tiler/tcm/tcm-utils.h
drivers/media/video/tiler/tcm.h new file +209 -0
@@ -0,0 +1,209 @@ +/* +* tcm.h +* +* TILER container manager specification and support functions for TI +* TILER driver. +* +* Author: Lajos Molnar <[email protected]> +* +* Copyright (C) 2009-2010 Texas Instruments, Inc. +* +* This package is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#ifndef TCM_H +#define TCM_H + +struct tcm ; + +/* point */ +struct tcm_pt { +u16 x; +u16 y; +}; + +/* 2d area */ +struct tcm_area { +struct tcm *tcm;/* parent */ +struct tcm_pt p0; +struct tcm_pt p1; +}; + +struct tcm { +u16 width, height;/* container dimensions */ + +/* 'pvt' structure shall contain any tcm details (attr) along with +linked list of allocated areas and mutex for mutually exclusive access +to the list. It may also contain copies of width and height to notice +any changes to the publicly available width and height fields. */ +void *pvt; + +/* function table */ +s32 (*reserve_2d)(struct tcm *tcm,u16 height,u16 width,u8 align, +struct tcm_area *area); +s32 (*free) (struct tcm *tcm,struct tcm_area *area); +void (*deinit) (struct tcm *tcm); +}; + +/*============================================================================= +BASIC TILER CONTAINER MANAGER INTERFACE +=============================================================================*/ + +/* +* NOTE: +* +* Since some basic parameter checking is done outside the TCM algorithms, +* TCM implementation do NOT have to check the following: +* +* area pointer is NULL +* width and height fits within container +* number of pages is more than the size of the container +* +*/ + +/** +* Template for <ALGO_NAME>_tcm_init method. Define as: +* TCM_INIT(<ALGO_NAME>_tcm_init) +* +* Allocates and initializes a tiler container manager. +* +* @param width Width of container +* @param height Height of container +* @param attr Container manager specific configuration +* arguments. Please describe these in +* your header file. +* +* @return Pointer to the allocated and initialized container +* manager. NULL on failure. DO NOT leak any memory on +* failure! +*/ +#define TCM_INIT (name, attr_t) \ +struct tcm *name(u16 width, u16 height, typeof(attr_t) *attr); + +/** +* Deinitialize tiler container manager. +* +* @param tcm Pointer to container manager. +* +* @return 0 on success, non-0 error value on error. The call +* should free as much memory as possible and meaningful +* even on failure. Some error codes: -ENODEV: invalid +* manager. +*/ +static inline void tcm_deinit (struct tcm *tcm) +{ +if (tcm) + tcm->deinit (tcm); +} + +/** +* Reserves a 2D area in the container. +* +* @param tcm Pointer to container manager. +* @param height Height(in pages) of area to be reserved. +* @param width Width(in pages) of area to be reserved. +* @param align Alignment requirement for top-left corner of area. Not +* all values may be supported by the container manager, +* but it must support 0 (1), 32 and 64. +* 0 value is equivalent to 1. +* @param area Pointer to where the reserved area should be stored. +* +* @return 0 on success. Non-0 error code on failure. Also, +* the tcm field of the area will be set to NULL on +* failure. Some error codes: -ENODEV: invalid manager, +* -EINVAL: invalid area, -ENOMEM: not enough space for +* allocation. +*/ +static inline s32 tcm_reserve_2d (struct tcm *tcm,u16 width,u16 height, +u16 align,struct tcm_area *area) +{ +/* perform rudimentary error checking */ +s32 res = (tcm ==NULL ? -ENODEV : + (area ==NULL || width ==0 || height ==0 || +/* align must be a 2 power */ + align & (align -1 )) ? -EINVAL : + (height > tcm->height || width > tcm->width) ? -ENOMEM : + tcm->reserve_2d (tcm, height, width, align, area)); + +if (area) + area->tcm = res ?NULL : tcm; + +return res; +} + +/** +* Free a previously reserved area from the container. +* +* @param area Pointer to area reserved by a prior call to tcm_reserve_2d call, +* whether it was successful or not. (Note: all fields of +* the structure must match.) +* +* @return 0 on success. Non-0 error code on failure. Also, the tcm +* field of the area is set to NULL on success to avoid subsequent +* freeing. This call will succeed even if supplying +* the area from a failed reserved call. +*/ +static inline s32 tcm_free (struct tcm_area *area) +{ +s32 res =0 ;/* free succeeds by default */ + +if (area && area->tcm) { + res = area->tcm->free (area->tcm, area); +if (res ==0 ) + area->tcm =NULL ; + } + +return res; +} + +/*============================================================================= +HELPER FUNCTION FOR ANY TILER CONTAINER MANAGER +=============================================================================*/ + +/* Verify if a tcm area is logically valid */ +static inline bool tcm_area_is_valid (struct tcm_area *area) +{ +return area && area->tcm && +/* coordinate bounds */ + area->p1.x < area->tcm->width && + area->p1.y < area->tcm->height && + area->p0.y <= area->p1.y && + area->p0.x <= area->p1.x; +} + +/* see if a coordinate is within an area */ +static inline bool __tcm_is_in (struct tcm_pt *p,struct tcm_area *a) +{ +return p->x >= a->p0.x && p->x <= a->p1.x && + p->y >= a->p0.y && p->y <= a->p1.y; +} + +/* calculate area width */ +static inline u16 __tcm_area_width (struct tcm_area *area) +{ +return area->p1.x - area->p0.x +1 ; +} + +/* calculate area height */ +static inline u16 __tcm_area_height (struct tcm_area *area) +{ +return area->p1.y - area->p0.y +1 ; +} + +/* calculate number of slots in an area */ +static inline u16 __tcm_sizeof (struct tcm_area *area) +{ +return __tcm_area_width (area) *__tcm_area_height (area); +} +#define tcm_sizeof (area) __tcm_sizeof(&(area)) +#define tcm_awidth (area) __tcm_area_width(&(area)) +#define tcm_aheight (area) __tcm_area_height(&(area)) +#define tcm_is_in (pt, area) __tcm_is_in(&(pt), &(area)) + +#endif
drivers/media/video/tiler/tcm/tcm-utils.h new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
1.6.3.3
RFC 3/8 TILER-DMM: Sample TCM implementation: Simple TILER Allocator
From: Ravi Ramachandra <[email protected]>
This patch implements a simple TILER Container Manager.
--- drivers/media/video/tiler/tcm/Makefile | 1 + drivers/media/video/tiler/tcm/_tcm-sita.h | 64 ++++ drivers/media/video/tiler/tcm/tcm-sita.c | 459 +++++++++++++++++++++++++++++ drivers/media/video/tiler/tcm/tcm-sita.h | 37 +++ 4 files changed, 561 insertions(+), 0 deletions(-) create mode 100644 drivers/media/video/tiler/tcm/Makefile create mode 100644 drivers/media/video/tiler/tcm/_tcm-sita.h create mode 100644 drivers/media/video/tiler/tcm/tcm-sita.c create mode 100644 drivers/media/video/tiler/tcm/tcm-sita.h
drivers/media/video/tiler/tcm/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_TI_TILER) += tcm-sita.o
drivers/media/video/tiler/tcm/_tcm-sita.h new file +64 -0
64 lines not on this page · raw message
drivers/media/video/tiler/tcm/tcm-sita.c new file +459 -0
459 lines not on this page · raw message
drivers/media/video/tiler/tcm/tcm-sita.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* tcm_sita.h +* +* SImple Tiler Allocator (SiTA) interface. +* +* Author: Ravi Ramachandra <[email protected]> +* +* Copyright (C) 2009-2010 Texas Instruments, Inc. +* +* This package is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#ifndef TCM_SITA_H +#define TCM_SITA_H + +#include "../tcm.h" + +/** +* Create a SiTA tiler container manager. +* +* @param width Container width +* @param height Container height +* @param attr unused +* +* @return TCM instance +*/ +struct tcm *sita_init (u16 width,u16 height,void *attr); + +TCM_INIT (sita_init, void); + +#endif /* TCM_SITA_H_ */
Signature · 1 line
1.6.3.3
RFC 4/8 TILER-DMM: TILER Memory Manager interface and implementation
From: Lajos Molnar <[email protected]>
This patch defines the TILER Memory Manager (TMM) interface and provides implementation for a PAT-supporting TMM.
--- drivers/media/video/tiler/tmm-pat.c | 274 +++++++++++++++++++++++++++++++++++ drivers/media/video/tiler/tmm.h | 109 ++++++++++++++ 2 files changed, 383 insertions(+), 0 deletions(-) create mode 100644 drivers/media/video/tiler/tmm-pat.c create mode 100644 drivers/media/video/tiler/tmm.h
drivers/media/video/tiler/tmm-pat.c new file +274 -0
@@ -0,0 +1,274 @@ +/* +* tmm-pat.c +* +* DMM driver support functions for TI TILER hardware block. +* +* Authors: Lajos Molnar <[email protected]> +* David Sin <[email protected]> +* +* Copyright (C) 2009-2010 Texas Instruments, Inc. +* +* This package is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +*/ +#include <linux/init.h> +#include <linux/module.h> +#include <linux/mm.h> +#include <linux/mmzone.h> +#include <asm/cacheflush.h> +#include <linux/mutex.h> +#include <linux/list.h> +#include <linux/slab.h> + +#include "tmm.h" + +/* Page size granularity can be 4k, 16k, or 64k */ +#define DMM_PAGE 0x1000 + +/* Memory limit to cache free pages. TILER will eventually use this much */ +static u32 cache_limit =CONFIG_TILER_CACHE_LIMIT <<20 ; +module_param_named (cache, cache_limit, uint,0644 ); +MODULE_PARM_DESC (cache,"Cache free pages if total memory is under this limit" ); + +/* global state - statically initialized */ +static LIST_HEAD (free_list);/* page cache: list of free pages */ +static u32 total_mem;/* total memory allocated (free & used) */ +static u32 refs;/* number of tmm_pat instances */ +static DEFINE_MUTEX (mtx);/* global mutex */ + +/* The page struct pointer and physical address of each page.*/ +struct mem { +struct list_head list; +struct page *pg;/* page struct */ +u32 pa;/* physical address */ +}; + +/* Used to keep track of mem per tmm_pat_get_pages call */ +struct fast { +struct list_head list; +struct mem **mem;/* array of page info */ +u32 *pa;/* array of physical addresses */ +u32 num;/* number of pages */ +}; + +/* TMM PAT private structure */ +struct dmm_mem { +struct list_head fast_list; +struct dmm *dmm; +}; + +/** +* Frees pages in a fast structure. Moves pages to the free list if there +* are less pages used than max_to_keep. Otherwise, it frees the pages +*/ +static void free_fast (struct fast *f) +{ +s32 i =0 ; + +/* mutex is locked */ +for (i =0 ; i < f->num; i++) { +if (total_mem < cache_limit) { +/* cache free page if under the limit */ +list_add (&f->mem[i]->list, &free_list); + }else { +/* otherwise, free */ + total_mem -=PAGE_SIZE ; +__free_page (f->mem[i]->pg); + } + } +kfree (f->pa); +kfree (f->mem); +/* remove only if element was added */ +if (f->list.next) +list_del (&f->list); +kfree (f); +} + +/* allocate and flush a page */ +static struct mem *alloc_mem (void ) +{ +struct mem *m =kzalloc (sizeof (*m),GFP_KERNEL ); +if (!m) +return NULL ; + + m->pg =alloc_page (GFP_KERNEL |GFP_DMA ); +if (!m->pg) { +kfree (m); +return NULL ; + } + + m->pa =page_to_phys (m->pg); + +/* flush the cache entry for each page we allocate. */ +dmac_flush_range (page_address (m->pg), +page_address (m->pg) +PAGE_SIZE ); +outer_flush_range (m->pa, m->pa +PAGE_SIZE ); + +return m; +} + +static void free_page_cache (void ) +{ +struct mem *m, *m_; + +/* mutex is locked */ +list_for_each_entry_safe (m, m_, &free_list, list) { +__free_page (m->pg); + total_mem -=PAGE_SIZE ; +list_del (&m->list); +kfree (m); + } +} + +static void tmm_pat_deinit (struct tmm *tmm) +{ +struct fast *f, *f_; +struct dmm_mem *pvt = (struct dmm_mem *) tmm->pvt; + +mutex_lock (&mtx); + +/* free all outstanding used memory */ +list_for_each_entry_safe (f, f_, &pvt->fast_list, list) +free_fast (f); + +/* if this is the last tmm_pat, free all memory */ +if (--refs ==0 ) +free_page_cache (); + +mutex_unlock (&mtx); +} + +static u32 *tmm_pat_get_pages (struct tmm *tmm,u32 n) +{ +struct mem *m; +struct fast *f; +struct dmm_mem *pvt = (struct dmm_mem *) tmm->pvt; + + f =kzalloc (sizeof (*f),GFP_KERNEL ); +if (!f) +return NULL ; + +/* array of mem struct pointers */ + f->mem =kzalloc (n *sizeof (*f->mem),GFP_KERNEL ); + +/* array of physical addresses */ + f->pa =kzalloc (n *sizeof (*f->pa),GFP_KERNEL ); + +/* no pages have been allocated yet (needed for cleanup) */ + f->num =0 ; + +if (!f->mem || !f->pa) + goto cleanup; + +/* fill out fast struct mem array with free pages */ +mutex_lock (&mtx); +while (f->num < n) { +/* if there is a free cached page use it */ +if (!list_empty (&free_list)) { +/* unbind first element from list */ + m =list_first_entry (&free_list,typeof (*m), list); +list_del (&m->list); + }else { +mutex_unlock (&mtx); + +/** +* Unlock mutex during allocation and cache flushing. +*/ + m =alloc_mem (); +if (!m) + goto cleanup; + +mutex_lock (&mtx); + total_mem +=PAGE_SIZE ; + } + + f->mem[f->num] = m; + f->pa[f->num++] = m->pa; + } + +list_add (&f->list, &pvt->fast_list); +mutex_unlock (&mtx); +return f->pa; + +cleanup: +free_fast (f); +return NULL ; +} + +static void tmm_pat_free_pages (struct tmm *tmm,u32 *page_list) +{ +struct dmm_mem *pvt = (struct dmm_mem *) tmm->pvt; +struct fast *f, *f_; + +mutex_lock (&mtx); +/* find fast struct based on 1st page */ +list_for_each_entry_safe (f, f_, &pvt->fast_list, list) { +if (f->pa[0 ] == page_list[0 ]) { +free_fast (f); +break ; + } + } +mutex_unlock (&mtx); +} + +static s32 tmm_pat_map (struct tmm *tmm,struct pat_area area,u32 page_pa) +{ +struct dmm_mem *pvt = (struct dmm_mem *) tmm->pvt; +struct pat pat_desc = {0 }; + +/* send pat descriptor to dmm driver */ + pat_desc.ctrl.dir =0 ; + pat_desc.ctrl.ini =0 ; + pat_desc.ctrl.lut_id =0 ; + pat_desc.ctrl.start =1 ; + pat_desc.ctrl.sync =0 ; + pat_desc.area = area; + pat_desc.next =NULL ; + +/* must be a 16-byte aligned physical address */ + pat_desc.data = page_pa; +return dmm_pat_refill (pvt->dmm, &pat_desc,MANUAL ); +} + +struct tmm *tmm_pat_init (u32 pat_id) +{ +struct tmm *tmm =NULL ; +struct dmm_mem *pvt =NULL ; + +struct dmm *dmm =dmm_pat_init (pat_id); +if (dmm) + tmm =kzalloc (sizeof (*tmm),GFP_KERNEL ); +if (tmm) + pvt =kzalloc (sizeof (*pvt),GFP_KERNEL ); +if (pvt) { +/* private data */ + pvt->dmm = dmm; +INIT_LIST_HEAD (&pvt->fast_list); + +/* increate tmm_pat references */ +mutex_lock (&mtx); + refs++; +mutex_unlock (&mtx); + +/* public data */ + tmm->pvt = pvt; + tmm->deinit = tmm_pat_deinit; + tmm->get = tmm_pat_get_pages; + tmm->free = tmm_pat_free_pages; + tmm->map = tmm_pat_map; + tmm->clear =NULL ;/* not yet supported */ + +return tmm; + } + +kfree (pvt); +kfree (tmm); +dmm_pat_release (dmm); +return NULL ; +} +EXPORT_SYMBOL (tmm_pat_init);
drivers/media/video/tiler/tmm.h new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
1.6.3.3
RFC 5/8 TILER-DMM: TILER interface file and documentation
From: Lajos Molnar <[email protected]>
This patch contains the TILER interface file and the documentation.
--- Documentation/arm/TILER | 144 +++++++++++++++++++++ arch/arm/mach-omap2/include/mach/tiler.h | 201 ++++++++++++++++++++++++++++++ 2 files changed, 345 insertions(+), 0 deletions(-) create mode 100644 Documentation/arm/TILER create mode 100644 arch/arm/mach-omap2/include/mach/tiler.h
Documentation/arm/TILER new file +144 -0
@@ -0,0 +1,144 @@ +TILER driver + +TILER is a hardware block made by Texas Instruments. Its purpose is to +organize video/image memory in a 2-dimensional fashion to limit memory +bandwidth and facilitate 0 effort rotation and mirroring. The TILER driver +facilitates allocating, freeing, as well as mapping 2D blocks (areas) in the +TILER container(s). It also facilitates rotating and mirroring the allocated +blocks or its rectangular subsections. + +TERMINOLOGY + +"slot" + +The basic TILER driver operates on blocks of slots. A slot is the granularity +of the TILER hardware device. For all current uses it is 4K, but could also be +16 or 64K. The DMM-TILER TRM refers to this as "page" but we want to separate +this concept from the MMU pages. + +"page" + +The granularity of the MMU, used by the kernel. This is 4K. + +"block" + +The TILER hardware block supports 1D and 2D blocks. A 2D block is a rectangular +arrangement of slots with arbitrary width and height in a 2D container. A +1D block is a linear arrangement of slots with arbitrary length in a 1D +container. This TILER driver only supports 2D blocks. + +"container" + +The TILER driver supports an arbitrary TILER container size. However, for +all current implementations it is 256 by 128 slots. The container currently can +only be used as a 2D container. + +"reserved area" + +Each block resides within a reserved area in the container. This area may +be larger than the actual set of slots that a block occupies. The reason for +this is to protect access from one block into another. Since TILER container is +mmap-ped into user space as individual pages, all slots that are spanned by +that page become visible to the user. The tiler driver allows restricting the +granularity of the reserved area (default alignment) as well as the mapped +area (granularity). + +KERNEL API to the TILER driver. + +1. Allocating and freeing a 1080p YUV422 block + + struct tiler_block_t blk = {0}; + int res; + + blk.width = 1920; + blk.height = 1080; + res = tiler_alloc(&blk, TILFMT_16BIT, 0, 0); + + tiler_free(&blk); + +2. Allocating and freeing a 1080p YUV420p block + + struct tiler_block_t blk_Y = {0}, blk_UV = {0}; + int res; + + blk_Y.width = 1920; + blk_Y.height = 1080; + blk_UV.widht = 960; + blk_UV.height = 540; + res = tiler_alloc(&blk_Y, TILFMT_8BIT, 0, 0) ? : + tiler_alloc(&blk_UV, TILFMT_16BIT, PAGE_SIZE, + blk_y->phys & ~PAGE_MASK); + + tiler_free(&blk_Y); + tiler_free(&blk_UV); + +Note how we allocated the UV block at the same in-page offset as the Y buffer. +This facilitates mmap-ping both Y and UV blocks into userspace as one +contiguous buffer. + +3. Mmap-ing YUV420p block into user space + + static int my_mmap(struct file *file, struct vm_area_struct *vma) + { + unsigned long size = (vma->vm_end - vma->vm_start); + unsigned long start = vma->vm_start; + + if (size != tiler_size(&blk_Y) + tiler_size(&blk_UV)) + return -EINVAL; + + return tiler_mmap_blk(&blk_Y, 0, tiler_size(&blk_Y), vma, 0) ? + : tiler_mmap_blk(&blk_UV, 0, tiler_size(&blk_UV), vma, + tiler_size(&blk_Y)); + } + +4. Ioremap-ing YUV422 block into kernel space + + void *my_ioremap(tiler_block_t *blk) { + struct vm_struct *area; + int res; + + area = get_vm_area(tiler_size(&blk), VM_IOREMAP); + if (!area) + return NULL; + + int res = tiler_ioremap_blk(&blk, 0, tiler_size(&block), + (u32) area->addr, MT_DEVICE_WC); + if (res) { + vunmap(area->addr); + return NULL; + } + return area->addr; + } + +CONFIGURATIONS + +The TILER driver allows specifying a container manager (tcm) for each +pixel format. The same container manager can be specified for more than +one pixel formats. + +Each container manager also operates on a PAT instance. One can also +specify a "virtual" PAT (with a linear preassigned memory space no actual +PAT programming), but it is not implemented. + +PARAMETERS + +The TILER driver allows specifying: + + granularity (tiler.grain, CONFIG_TILER_GRANULARITY): + + Each block is mapped in width-chunks of granularity. + + default alignment (tiler.align, CONFIG_TILER_ALIGNMENT): + + Default alignment if aligment is not specified (0). Otherwise, + blocks are allocated at an address aligned to the value given plus an + offset within the alignment. + + cache limit (tiler.cache, CONFIG_TILER_CACHE_LIMIT): + + TILER driver keeps a cache of allocated pages to speed up allocation of + TILER blocks. You can set a limit of how much memory the TILER driver + should keep if there are no actual TILER allocations. This also means + that if there is less memory used than this limit, the pages of freed + tiler blocks will not actually be freed, but instead are put into this + cache.
arch/arm/mach-omap2/include/mach/tiler.h new file +201 -0
201 lines not on this page · raw message
Signature · 1 line
1.6.3.3
RFC 6/8 TILER-DMM: Geometry and view manipulation functions.
From: Lajos Molnar <[email protected]>
This patch contains information on TILER geometry, as well as tiler_view_t object manipulation functions.
It also contains an internal TILER header file to share geometric information with other TILER files.
--- drivers/media/video/tiler/_tiler.h | 51 +++++ drivers/media/video/tiler/tiler-geom.c | 360 ++++++++++++++++++++++++++++++++ 2 files changed, 411 insertions(+), 0 deletions(-) create mode 100644 drivers/media/video/tiler/_tiler.h create mode 100644 drivers/media/video/tiler/tiler-geom.c
drivers/media/video/tiler/_tiler.h new file +51 -0
@@ -0,0 +1,51 @@ +/* +* _tiler.h +* +* TI TILER driver internal shared definitions. +* +* Author: Lajos Molnar <[email protected]> +* +* Copyright (C) 2009-2010 Texas Instruments, Inc. +* +* This package is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#ifndef _TILER_H +#define _TILER_H + +#include <linux/kernel.h> +#include <mach/tiler.h> +#include "tcm.h" + +#define TILER_FORMATS (TILFMT_MAX - TILFMT_MIN + 1) + +/* tiler geometry information */ +struct tiler_geom { +u32 x_shft;/* unused X-bits (as part of bpp) */ +u32 y_shft;/* unused Y-bits (as part of bpp) */ +u32 bpp;/* bytes per pixel */ +u32 slot_w;/* width of each slot (in pixels) */ +u32 slot_h;/* height of each slot (in pixels) */ +}; + +/* methods and variables shared between source files */ +struct tiler_ops { +/* geometry operations */ +void (*xy) (u32 ssptr,u32 *x,u32 *y); +u32 (*addr) (enum tiler_fmt fmt,u32 x,u32 y); +const struct tiler_geom * (*geom) (enum tiler_fmt fmt); + +u32 page;/* page size */ +u32 width;/* container width */ +u32 height;/* container height */ +}; + +void tiler_geom_init (struct tiler_ops *tiler); + +#endif
drivers/media/video/tiler/tiler-geom.c new file +360 -0
360 lines not on this page · raw message
Signature · 1 line
1.6.3.3
RFC 7/8 TILER-DMM: Main TILER driver implementation.
From: Lajos Molnar <[email protected]>
This patch contains the TILER driver and implementation of the TILER block manipulation and mapping functions.
It also contains the makefile and config file for the TILER driver.
--- drivers/media/video/tiler/Kconfig | 65 +++++ drivers/media/video/tiler/Makefile | 7 + drivers/media/video/tiler/tiler-iface.c | 106 ++++++++ drivers/media/video/tiler/tiler-main.c | 426 +++++++++++++++++++++++++++++++ 4 files changed, 604 insertions(+), 0 deletions(-) create mode 100644 drivers/media/video/tiler/Kconfig create mode 100644 drivers/media/video/tiler/Makefile create mode 100644 drivers/media/video/tiler/tiler-iface.c create mode 100644 drivers/media/video/tiler/tiler-main.c
drivers/media/video/tiler/Kconfig new file +65 -0
@@ -0,0 +1,65 @@ +config HAVE_TI_TILER + bool + default y + depends on ARCH_OMAP4 + +menuconfig TI_TILER + tristate "TI TILER support" + default y + depends on HAVE_TI_TILER + help + TILER and TILER-DMM driver for TI chips. The TI TILER device + enables video rotation on certain TI chips such as OMAP4 or + Netra. Video rotation will be limited without TILER support. + +config TILER_GRANULARITY + int "Allocation granularity (2^n)" + range 1 4096 + default 128 + depends on TI_TILER + help + This option sets the default TILER allocation granularity. It can + be overriden by the tiler.grain boot argument. + + The allocation granularity is the smallest TILER block size (in + bytes) managed distinctly by the TILER driver. TILER blocks of any + size are managed in chunks of at least this size. + + Must be a 2^n in the range of 1 to 4096; however, the TILER driver + may use a larger supported granularity. + + Supported values are: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, + 2048, 4096. + +config TILER_ALIGNMENT + int "Allocation alignment (2^n)" + range 1 4096 + default 4096 + depends on TI_TILER + help + This option sets the default TILER allocation alignment. It can + be overriden by the tiler.align boot argument. + + Must be a 2^n in the range of 1 to 4096; however, it is naturally + aligned to the TILER granularity. + + Supported values are: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, + 2048, 4096. + +config TILER_CACHE_LIMIT + int "Memory limit to cache free pages in MBytes" + range 0 128 + default 40 + depends on TI_TILER + help + This option sets the minimum memory that TILER retains even if + there is less TILER allocated memory is use. The unused memory is + instead stored in a cache to speed up allocation and freeing of + physical pages. + + This option can be overriden by the tiler.cache boot argument. + + While initially TILER will use less memory than this limit (0), it + will not release any memory used until it reaches this limit. + Thereafter, TILER will release any unused memory immediately as + long as there it is above this threshold.
drivers/media/video/tiler/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +obj-$(CONFIG_TI_TILER) += tcm/ + +obj-$(CONFIG_TI_TILER) += tiler.o +tiler-objs = tiler-geom.o tiler-main.o tiler-iface.o tmm-pat.o + +obj-$(CONFIG_TI_TILER) += tiler_dmm.o +tiler_dmm-objs = dmm.o
drivers/media/video/tiler/tiler-iface.c new file +106 -0
106 lines not on this page · raw message
drivers/media/video/tiler/tiler-main.c new file +426 -0
426 lines not on this page · raw message
Signature · 1 line
1.6.3.3
RFC 8/8 TILER-DMM: Linking TILER driver into the Linux kernel build
From: Lajos Molnar <[email protected]>
This patch links the TILER driver into the Linux kernel build and config system.
--- drivers/media/Kconfig | 6 ++++++ drivers/media/Makefile | 2 ++ 2 files changed, 8 insertions(+), 0 deletions(-)
drivers/media/Kconfig +6 -0
@@ -98,6 +98,12 @@ config VIDEO_MEDIA comment "Multimedia drivers" +# +# TI TILER driver support +# + +source "drivers/media/video/tiler/Kconfig" + source "drivers/media/common/Kconfig" source "drivers/media/IR/Kconfig"
drivers/media/Makefile +2 -0
@@ -4,5 +4,7 @@ obj-y += common/ IR/ video/ +obj-${CONFIG_TI_TILER} += video/tiler/ + obj-$(CONFIG_VIDEO_DEV) += radio/ obj-$(CONFIG_DVB_CORE) += dvb/
Signature · 1 line
1.6.3.3
RFC 5/8 TILER-DMM: TILER interface file and documentation
In reply to David SinHi,
Quoted 3 lines · On Saturday 24 July 2010 01:28:11 David Sin wrote:
From: Lajos Molnar <[email protected]>
This patch contains the TILER interface file and the documentation.
I got a problem with the documentation. After reading it I'm still not sure how the tiler works and what it's supposed to do exactly.
Signature · 3 lines
Regards, Laurent Pinchart
RFC 5/8 TILER-DMM: TILER interface file and documentation
Quoted 10 lines
-----Original Message-----
From: Laurent Pinchart [mailto:laurent.pinchart at ideasonboard.com]
Sent: Wednesday, July 28, 2010 4:59 AM
To: linux-arm-kernel at lists.infradead.org
Cc: Sin, David; Molnar, Lajos
Subject: Re: [RFC 5/8] TILER-DMM: TILER interface file and documentationHi,
Quoted 14 lines
Quoted 3 lines · On Saturday 24 July 2010 01:28:11 David Sin wrote:
From: Lajos Molnar <[email protected]>
This patch contains the TILER interface file and the documentation.
I got a problem with the documentation. After reading it I'm still not sure
how the tiler works and what it's supposed to do exactly.Signature · 3 lines
Regards, Laurent Pinchart
[dhs] Thanks for this feedback. I'm working on getting the public TRM link fixed, which should explain more. I will also work on improving the document.
RFC 5/8 TILER-DMM: TILER interface file and documentation
In reply to Laurent PinchartQuoted 31 lines
-----Original Message-----
From: Sin, David
Sent: Wednesday, July 28, 2010 9:44 AM
To: 'Laurent Pinchart'; linux-arm-kernel at lists.infradead.org
Cc: Molnar, Lajos
Subject: RE: [RFC 5/8] TILER-DMM: TILER interface file and documentationQuoted 8 lines
-----Original Message-----
From: Laurent Pinchart [mailto:laurent.pinchart at ideasonboard.com]
Sent: Wednesday, July 28, 2010 4:59 AM
To: linux-arm-kernel at lists.infradead.org
Cc: Sin, David; Molnar, Lajos
Subject: Re: [RFC 5/8] TILER-DMM: TILER interface file and documentationQuoted 6 lines
Hi,
Quoted 3 lines · On Saturday 24 July 2010 01:28:11 David Sin wrote:
From: Lajos Molnar <[email protected]>
This patch contains the TILER interface file and the
documentation.
Quoted 8 lines
I got a problem with the documentation. After reading it I'm still not sure
how the tiler works and what it's supposed to do exactly.Signature · 1 line
Regards,
Quoted 6 lines
Quoted 2 lines
Laurent Pinchart
[dhs] Thanks for this feedback. I'm working on getting the public TRM link fixed, which should explain more. I will also work on improving the document.
Laurent,
I have uploaded the DMM-TILER TRM section for omap4 es 2.0 here:
https://gforge.ti.com/gf/download/docmanfileversion/208/3739/OMAP4430_ES2.0_PUBLIC_TRM_MEMSS_DMM_v3.0.pdf
I'm not able to provide you a link to the complete TRM, at this time. It will not be available until the end of September.
BR,
--
David Sin
RFC 5/8 TILER-DMM: TILER interface file and documentation
Hi David,
Quoted 8 lines · David
Laurent,
I have uploaded the DMM-TILER TRM section for omap4 es 2.0 here:
https://gforge.ti.com/gf/download/docmanfileversion/208/3739/OMAP4430_ES2.0
_PUBLIC_TRM_MEMSS_DMM_v3.0.pdfI'm not able to provide you a link to the complete TRM, at this time. It will not be available until the end of September.
Thanks a lot. I'll read (and digest) the DMM-TILER TRM and I'll then review the patches again.
Signature · 3 lines
Regards, Laurent Pinchart
RFC 1/8 TILER-DMM: DMM-PAT driver for TI TILER
In reply to David SinHi David,
Quoted 39 lines · On Saturday 24 July 2010 01:28:07 David Sin wrote:
This patch adds support for DMM-PAT initialization and programming.
Signed-off-by David Sin <[email protected]>Signed-off-by Lajos Molnar <[email protected]>--- arch/arm/mach-omap2/include/mach/dmm.h | 128 ++++++++++++++++++++ drivers/media/video/tiler/dmm.c | 200 ++++++++++++++++++++++++++++++++ 2 files changed, 328 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-omap2/include/mach/dmm.h create mode 100644 drivers/media/video/tiler/dmm.c(quoted diff) +0
-0
b/arch/arm/mach-omap2/include/mach/dmm.hnew file mode 100644 index 0000000..68b798aarch/arm/mach-omap2/include/mach/dmm.h new file +21
-0@@ -0,0 +1,128 @@ +/* +* dmm.h +* +* DMM driver support functions for TI DMM-TILER hardware block. +* +* Author: David Sin <[email protected]> +* +* Copyright (C) 2009-2010 Texas Instruments, Inc. +* +* This package is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#ifndef DMM_H +#define DMM_H +
arch/arm/mach-omap2/include/mach/dmm.h line 31
Quoted 10 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +10
-0+#define DMM_BASE 0x4E000000 +#define DMM_SIZE 0x800 + +#define DMM_REVISION 0x000 +#define DMM_HWINFO 0x004 +#define DMM_LISA_HWINFO 0x008 +#define DMM_DMM_SYSCONFIG 0x010 +#define DMM_LISA_LOCK 0x01C +#define DMM_LISA_MAP__0 0x040 +#define DMM_LISA_MAP__1 0x044
Why the double _ ?
Quoted 24 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +24
-0+#define DMM_TILER_HWINFO 0x208 +#define DMM_TILER_OR__0 0x220 +#define DMM_TILER_OR__1 0x224 +#define DMM_PAT_HWINFO 0x408 +#define DMM_PAT_GEOMETRY 0x40C +#define DMM_PAT_CONFIG 0x410 +#define DMM_PAT_VIEW__0 0x420 +#define DMM_PAT_VIEW__1 0x424 +#define DMM_PAT_VIEW_MAP__0 0x440 +#define DMM_PAT_VIEW_MAP_BASE 0x460 +#define DMM_PAT_IRQ_EOI 0x478 +#define DMM_PAT_IRQSTATUS_RAW 0x480 +#define DMM_PAT_IRQSTATUS 0x490 +#define DMM_PAT_IRQENABLE_SET 0x4A0 +#define DMM_PAT_IRQENABLE_CLR 0x4B0 +#define DMM_PAT_STATUS__0 0x4C0 +#define DMM_PAT_STATUS__1 0x4C4 +#define DMM_PAT_STATUS__2 0x4C8 +#define DMM_PAT_STATUS__3 0x4CC +#define DMM_PAT_DESCR__0 0x500 +#define DMM_PAT_AREA__0 0x504 +#define DMM_PAT_CTRL__0 0x508 +#define DMM_PAT_DATA__0 0x50C +#define DMM_PEG_HWINFO 0x608
arch/arm/mach-omap2/include/mach/dmm.h line 65
Quoted 10 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +10
-0+#define DMM_PEG_PRIO 0x620 +#define DMM_PEG_PRIO_PAT 0x640 + +/** +* PAT refill programming mode. +*/ +enum pat_mode { +MANUAL , +AUTO +};
MANUAL and AUTO are pretty generic names to have in the top-level scope. Please at least rename them to PAT_MANUAL and PAT_AUTO.
Even better, the pat_ prefix might be better called dmm_pat_, as PAT is already used for Physical Address Extension on x86 (granted, the DMM-PAT is not likely to be used on x86 platforms).
An explanation of the DMM and PAT acronyms would be nice as well.
arch/arm/mach-omap2/include/mach/dmm.h line 74
Quoted 9 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +9
-0+ +/** +* Area definition for DMM physical address translator. +*/ +struct pat_area { +s32 x0:8 ; +s32 y0:8 ; +s32 x1:8 ; +s32 y1:8 ;
What's wrong with four u8 fields ?
Quoted 91 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +54
-0+}; + +/** +* DMM physical address translator control. +*/ +struct pat_ctrl { +s32 start:4 ; +s32 dir:4 ; +s32 lut_id:8 ; +s32 sync:12 ; +s32 ini:4 ; +}; + +/** +* PAT descriptor. +*/ +struct pat { +struct pat *next; +struct pat_area area; +struct pat_ctrl ctrl; +u32 data; +}; + +/** +* DMM device data +*/ +struct dmm { +void __iomem *base; +}; + +/** +* Create and initialize the physical address translator. +* @param id PAT id +* @return pointer to device data +*/ +struct dmm *dmm_pat_init (u32 id); + +/** +* Program the physical address translator. +* @param dmm Device data +* @param desc PAT descriptor +* @param mode programming mode +* @return an error status. +*/ +s32 dmm_pat_refill (struct dmm *dmm,struct pat *desc,enum pat_mode mode); + +/** +* Clean up the physical address translator. +* @param dmm Device data +* @return an error status. +*/ +void dmm_pat_release (struct dmm *dmm); + +#endif (quoted diff) +0
-0
b/drivers/media/video/tiler/dmm.cnew file mode 100644 index 0000000..e715936drivers/media/video/tiler/dmm.c new file +31
-0@@ -0,0 +1,200 @@ +/* +* dmm.c +* +* DMM driver support functions for TI OMAP processors. +* +* Authors: David Sin <[email protected]> +* Lajos Molnar <[email protected]> +* +* Copyright (C) 2009-2010 Texas Instruments, Inc. +* +* This package is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#include <linux/init.h> +#include <linux/module.h> +#include <linux/platform_device.h> /* platform_device() */ +#include <linux/io.h> /* ioremap() */ +#include <linux/errno.h> +#include <linux/slab.h> + +#include <mach/dmm.h> + +#define MASK (msb, lsb) (((1 << ((msb) + 1 - (lsb))) - 1) << (lsb)) +#define SET_FLD (reg, msb, lsb, val) \ +(((reg) & ~MASK((msb), (lsb))) | (((val) << (lsb)) & MASK((msb), (lsb))))
drivers/media/video/tiler/dmm.c line 41
Quoted 10 lines
drivers/media/video/tiler/dmm.c new file +10
-0+ +static struct platform_driver dmm_driver_ldm = { + .driver = { + .owner =THIS_MODULE , + .name ="dmm" , + }, + .probe =NULL , + .shutdown =NULL , + .remove =NULL , +};
Why do you need a platform_driver if it's completely empty ? Instead of using the hardcoded DMM_BASE and DMM_SIZE constants in the driver, you should implement a probe function and retrieve them from the platform device resources.
drivers/media/video/tiler/dmm.c line 54
Quoted 12 lines
drivers/media/video/tiler/dmm.c new file +12
-0+s32 dmm_pat_refill (struct dmm *dmm,struct pat *pd,enum pat_mode mode) +{ +void __iomem *r; +u32 v; + +/* Only manual refill supported */ +if (mode !=MANUAL ) +return -EFAULT ; + +/* Check that the DMM_PAT_STATUS register has not reported an error */ + r = dmm->base +DMM_PAT_STATUS__0 ; + v =__raw_readl (r);
Adding dmm_read and dmm_write macros that compute the address using the base and offset would make the code simpler. You could also define dmm_clear_bits and dmm_set_bits macros.
drivers/media/video/tiler/dmm.c line 54
Quoted 1 line
drivers/media/video/tiler/dmm.c new file +1
-0+if (WARN (v &0xFC00 ,KERN_ERR "dmm_pat_refill() error.\n" ))
Can you define constants for the field's bits and use them instead of the hardcoded 0xfc00 ?
Same comment for the other values you use in the driver (both the register values, field numbers, shift constants, ...).
Quoted 16 lines
drivers/media/video/tiler/dmm.c new file +16
-0+return -EIO ; + +/* Set "next" register to NULL */ + r = dmm->base +DMM_PAT_DESCR__0 ; + v =__raw_readl (r); + v =SET_FLD (v,31 ,4 , (u32 )NULL ); +__raw_writel (v, r); + +/* Set area to be refilled */ + r = dmm->base +DMM_PAT_AREA__0 ; + v =__raw_readl (r); + v =SET_FLD (v,30 ,24 , pd->area.y1); + v =SET_FLD (v,23 ,16 , pd->area.x1); + v =SET_FLD (v,14 ,8 , pd->area.y0); + v =SET_FLD (v,7 ,0 , pd->area.x0); +__raw_writel (v, r);
drivers/media/video/tiler/dmm.c line 81
Quoted 10 lines
drivers/media/video/tiler/dmm.c new file +10
-0+wmb (); + +/* First, clear the DMM_PAT_IRQSTATUS register */ + r = dmm->base +DMM_PAT_IRQSTATUS ; +__raw_writel (0xFFFFFFFF , r); +wmb (); + + r = dmm->base +DMM_PAT_IRQSTATUS_RAW ; +while (__raw_readl (r) !=0 ) + ;
How long is this expected to last ? Shouldn't you add a timeout ?
drivers/media/video/tiler/dmm.c line 93
Quoted 11 lines
drivers/media/video/tiler/dmm.c new file +11
-0+/* Fill data register */ + r = dmm->base +DMM_PAT_DATA__0 ; + v =__raw_readl (r); + + v =SET_FLD (v,31 ,4 , pd->data >>4 ); +__raw_writel (v, r); +wmb (); + +/* Read back PAT_DATA__0 to see if write was successful */ +while (__raw_readl (r) != pd->data) + ;
Do you really need to read back every register after writing them ?
Quoted 45 lines
drivers/media/video/tiler/dmm.c new file +45
-0+ r = dmm->base +DMM_PAT_CTRL__0 ; + v =__raw_readl (r); + v =SET_FLD (v,31 ,28 , pd->ctrl.ini); + v =SET_FLD (v,16 ,16 , pd->ctrl.sync); + v =SET_FLD (v,9 ,8 , pd->ctrl.lut_id); + v =SET_FLD (v,6 ,4 , pd->ctrl.dir); + v =SET_FLD (v,0 ,0 , pd->ctrl.start); +__raw_writel (v, r); +wmb (); + +/* Check if PAT_IRQSTATUS_RAW is set after the PAT has been refilled */ + r = dmm->base +DMM_PAT_IRQSTATUS_RAW ; +while ((__raw_readl (r) &0x3 ) !=0x3 ) + ; + +/* Again, clear the DMM_PAT_IRQSTATUS register */ + r = dmm->base +DMM_PAT_IRQSTATUS ; +__raw_writel (0xFFFFFFFF , r); +wmb (); + + r = dmm->base +DMM_PAT_IRQSTATUS_RAW ; +while (__raw_readl (r) !=0 ) + ; + +/* Again, set "next" register to NULL to clear any PAT STATUS errors */ + r = dmm->base +DMM_PAT_DESCR__0 ; + v =__raw_readl (r); + v =SET_FLD (v,31 ,4 , (u32 )NULL ); +__raw_writel (v, r); + +/* +* Now, check that the DMM_PAT_STATUS register +* has not reported an error before exiting. +*/ + r = dmm->base +DMM_PAT_STATUS__0 ; + v =__raw_readl (r); +if (WARN (v &0xFC00 ,KERN_ERR "dmm_pat_refill() error.\n" )) +return -EIO ; + +return 0 ; +} +EXPORT_SYMBOL (dmm_pat_refill); + +struct dmm *dmm_pat_init (u32 id) +{
drivers/media/video/tiler/dmm.c line 149
Quoted 10 lines
drivers/media/video/tiler/dmm.c new file +10
-0+u32 base; +struct dmm *dmm; +switch (id) { +case 0 : +/* only support id 0 for now */ + base =DMM_BASE ; +break ; +default : +return NULL ; + }
Shouldn't you protect against multiple driver trying to initialize the same DMM-PAT ?
Quoted 50 lines
drivers/media/video/tiler/dmm.c new file +50
-0+ dmm =kzalloc (sizeof (*dmm),GFP_KERNEL ); +if (!dmm) +return NULL ; + + dmm->base =ioremap (base,DMM_SIZE ); +if (!dmm->base) { +kfree (dmm); +return NULL ; + } + +__raw_writel (0x88888888 , dmm->base +DMM_PAT_VIEW__0 ); +__raw_writel (0x88888888 , dmm->base +DMM_PAT_VIEW__1 ); +__raw_writel (0x80808080 , dmm->base +DMM_PAT_VIEW_MAP__0 ); +__raw_writel (0x80000000 , dmm->base +DMM_PAT_VIEW_MAP_BASE ); +__raw_writel (0x88888888 , dmm->base +DMM_TILER_OR__0 ); +__raw_writel (0x88888888 , dmm->base +DMM_TILER_OR__1 ); + +return dmm; +} +EXPORT_SYMBOL (dmm_pat_init); + +/** +* Clean up the physical address translator. +* @param dmm Device data +* @return an error status. +*/ +void dmm_pat_release (struct dmm *dmm) +{ +if (dmm) { +iounmap (dmm->base); +kfree (dmm); + } +} +EXPORT_SYMBOL (dmm_pat_release); + +static s32 __init dmm_init (void ) +{ +return platform_driver_register (&dmm_driver_ldm); +} + +static void __exit dmm_exit(void) +{ +platform_driver_unregister (&dmm_driver_ldm); +} + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("davidsin at ti.com" ); +MODULE_AUTHOR ("molnar at ti.com" ); +module_init (dmm_init); +module_exit (dmm_exit);
Signature · 3 lines
Regards, Laurent Pinchart
RFC 1/8 TILER-DMM: DMM-PAT driver for TI TILER
Hi Laurent,
Thanks for taking the time to review. These are all very good comments and I will work on incorporating them into the next RFC version.
-David
-----Original Message-----
From: Laurent Pinchart [mailto:laurent.pinchart at ideasonboard.com]
Sent: Monday, July 26, 2010 3:13 AM
To: linux-arm-kernel at lists.infradead.org
Cc: Sin, David; Molnar, Lajos
Subject: Re: [RFC 1/8] TILER-DMM: DMM-PAT driver for TI TILER
Hi David,
Quoted 39 lines · On Saturday 24 July 2010 01:28:07 David Sin wrote:
This patch adds support for DMM-PAT initialization and programming.
Signed-off-by David Sin <[email protected]>Signed-off-by Lajos Molnar <[email protected]>--- arch/arm/mach-omap2/include/mach/dmm.h | 128 ++++++++++++++++++++ drivers/media/video/tiler/dmm.c | 200 ++++++++++++++++++++++++++++++++ 2 files changed, 328 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-omap2/include/mach/dmm.h create mode 100644 drivers/media/video/tiler/dmm.c(quoted diff) +0
-0
b/arch/arm/mach-omap2/include/mach/dmm.hnew file mode 100644 index 0000000..68b798aarch/arm/mach-omap2/include/mach/dmm.h new file +21
-0@@ -0,0 +1,128 @@ +/* +* dmm.h +* +* DMM driver support functions for TI DMM-TILER hardware block. +* +* Author: David Sin <[email protected]> +* +* Copyright (C) 2009-2010 Texas Instruments, Inc. +* +* This package is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#ifndef DMM_H +#define DMM_H +
arch/arm/mach-omap2/include/mach/dmm.h line 31
Quoted 10 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +10
-0+#define DMM_BASE 0x4E000000 +#define DMM_SIZE 0x800 + +#define DMM_REVISION 0x000 +#define DMM_HWINFO 0x004 +#define DMM_LISA_HWINFO 0x008 +#define DMM_DMM_SYSCONFIG 0x010 +#define DMM_LISA_LOCK 0x01C +#define DMM_LISA_MAP__0 0x040 +#define DMM_LISA_MAP__1 0x044
Why the double _ ?
Quoted 24 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +24
-0+#define DMM_TILER_HWINFO 0x208 +#define DMM_TILER_OR__0 0x220 +#define DMM_TILER_OR__1 0x224 +#define DMM_PAT_HWINFO 0x408 +#define DMM_PAT_GEOMETRY 0x40C +#define DMM_PAT_CONFIG 0x410 +#define DMM_PAT_VIEW__0 0x420 +#define DMM_PAT_VIEW__1 0x424 +#define DMM_PAT_VIEW_MAP__0 0x440 +#define DMM_PAT_VIEW_MAP_BASE 0x460 +#define DMM_PAT_IRQ_EOI 0x478 +#define DMM_PAT_IRQSTATUS_RAW 0x480 +#define DMM_PAT_IRQSTATUS 0x490 +#define DMM_PAT_IRQENABLE_SET 0x4A0 +#define DMM_PAT_IRQENABLE_CLR 0x4B0 +#define DMM_PAT_STATUS__0 0x4C0 +#define DMM_PAT_STATUS__1 0x4C4 +#define DMM_PAT_STATUS__2 0x4C8 +#define DMM_PAT_STATUS__3 0x4CC +#define DMM_PAT_DESCR__0 0x500 +#define DMM_PAT_AREA__0 0x504 +#define DMM_PAT_CTRL__0 0x508 +#define DMM_PAT_DATA__0 0x50C +#define DMM_PEG_HWINFO 0x608
arch/arm/mach-omap2/include/mach/dmm.h line 65
Quoted 10 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +10
-0+#define DMM_PEG_PRIO 0x620 +#define DMM_PEG_PRIO_PAT 0x640 + +/** +* PAT refill programming mode. +*/ +enum pat_mode { +MANUAL , +AUTO +};
MANUAL and AUTO are pretty generic names to have in the top-level scope. Please at least rename them to PAT_MANUAL and PAT_AUTO.
Even better, the pat_ prefix might be better called dmm_pat_, as PAT is already used for Physical Address Extension on x86 (granted, the DMM-PAT is not likely to be used on x86 platforms).
An explanation of the DMM and PAT acronyms would be nice as well.
arch/arm/mach-omap2/include/mach/dmm.h line 74
Quoted 9 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +9
-0+ +/** +* Area definition for DMM physical address translator. +*/ +struct pat_area { +s32 x0:8 ; +s32 y0:8 ; +s32 x1:8 ; +s32 y1:8 ;
What's wrong with four u8 fields ?
Quoted 91 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +54
-0+}; + +/** +* DMM physical address translator control. +*/ +struct pat_ctrl { +s32 start:4 ; +s32 dir:4 ; +s32 lut_id:8 ; +s32 sync:12 ; +s32 ini:4 ; +}; + +/** +* PAT descriptor. +*/ +struct pat { +struct pat *next; +struct pat_area area; +struct pat_ctrl ctrl; +u32 data; +}; + +/** +* DMM device data +*/ +struct dmm { +void __iomem *base; +}; + +/** +* Create and initialize the physical address translator. +* @param id PAT id +* @return pointer to device data +*/ +struct dmm *dmm_pat_init (u32 id); + +/** +* Program the physical address translator. +* @param dmm Device data +* @param desc PAT descriptor +* @param mode programming mode +* @return an error status. +*/ +s32 dmm_pat_refill (struct dmm *dmm,struct pat *desc,enum pat_mode mode); + +/** +* Clean up the physical address translator. +* @param dmm Device data +* @return an error status. +*/ +void dmm_pat_release (struct dmm *dmm); + +#endif (quoted diff) +0
-0
b/drivers/media/video/tiler/dmm.cnew file mode 100644 index 0000000..e715936drivers/media/video/tiler/dmm.c new file +31
-0@@ -0,0 +1,200 @@ +/* +* dmm.c +* +* DMM driver support functions for TI OMAP processors. +* +* Authors: David Sin <[email protected]> +* Lajos Molnar <[email protected]> +* +* Copyright (C) 2009-2010 Texas Instruments, Inc. +* +* This package is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#include <linux/init.h> +#include <linux/module.h> +#include <linux/platform_device.h> /* platform_device() */ +#include <linux/io.h> /* ioremap() */ +#include <linux/errno.h> +#include <linux/slab.h> + +#include <mach/dmm.h> + +#define MASK (msb, lsb) (((1 << ((msb) + 1 - (lsb))) - 1) << (lsb)) +#define SET_FLD (reg, msb, lsb, val) \ +(((reg) & ~MASK((msb), (lsb))) | (((val) << (lsb)) & MASK((msb), (lsb))))
drivers/media/video/tiler/dmm.c line 41
Quoted 10 lines
drivers/media/video/tiler/dmm.c new file +10
-0+ +static struct platform_driver dmm_driver_ldm = { + .driver = { + .owner =THIS_MODULE , + .name ="dmm" , + }, + .probe =NULL , + .shutdown =NULL , + .remove =NULL , +};
Why do you need a platform_driver if it's completely empty ? Instead of using the hardcoded DMM_BASE and DMM_SIZE constants in the driver, you should implement a probe function and retrieve them from the platform device resources.
drivers/media/video/tiler/dmm.c line 54
Quoted 12 lines
drivers/media/video/tiler/dmm.c new file +12
-0+s32 dmm_pat_refill (struct dmm *dmm,struct pat *pd,enum pat_mode mode) +{ +void __iomem *r; +u32 v; + +/* Only manual refill supported */ +if (mode !=MANUAL ) +return -EFAULT ; + +/* Check that the DMM_PAT_STATUS register has not reported an error */ + r = dmm->base +DMM_PAT_STATUS__0 ; + v =__raw_readl (r);
Adding dmm_read and dmm_write macros that compute the address using the base and offset would make the code simpler. You could also define dmm_clear_bits and dmm_set_bits macros.
drivers/media/video/tiler/dmm.c line 54
Quoted 1 line
drivers/media/video/tiler/dmm.c new file +1
-0+if (WARN (v &0xFC00 ,KERN_ERR "dmm_pat_refill() error.\n" ))
Can you define constants for the field's bits and use them instead of the hardcoded 0xfc00 ?
Same comment for the other values you use in the driver (both the register values, field numbers, shift constants, ...).
Quoted 16 lines
drivers/media/video/tiler/dmm.c new file +16
-0+return -EIO ; + +/* Set "next" register to NULL */ + r = dmm->base +DMM_PAT_DESCR__0 ; + v =__raw_readl (r); + v =SET_FLD (v,31 ,4 , (u32 )NULL ); +__raw_writel (v, r); + +/* Set area to be refilled */ + r = dmm->base +DMM_PAT_AREA__0 ; + v =__raw_readl (r); + v =SET_FLD (v,30 ,24 , pd->area.y1); + v =SET_FLD (v,23 ,16 , pd->area.x1); + v =SET_FLD (v,14 ,8 , pd->area.y0); + v =SET_FLD (v,7 ,0 , pd->area.x0); +__raw_writel (v, r);
drivers/media/video/tiler/dmm.c line 81
Quoted 10 lines
drivers/media/video/tiler/dmm.c new file +10
-0+wmb (); + +/* First, clear the DMM_PAT_IRQSTATUS register */ + r = dmm->base +DMM_PAT_IRQSTATUS ; +__raw_writel (0xFFFFFFFF , r); +wmb (); + + r = dmm->base +DMM_PAT_IRQSTATUS_RAW ; +while (__raw_readl (r) !=0 ) + ;
How long is this expected to last ? Shouldn't you add a timeout ?
drivers/media/video/tiler/dmm.c line 93
Quoted 11 lines
drivers/media/video/tiler/dmm.c new file +11
-0+/* Fill data register */ + r = dmm->base +DMM_PAT_DATA__0 ; + v =__raw_readl (r); + + v =SET_FLD (v,31 ,4 , pd->data >>4 ); +__raw_writel (v, r); +wmb (); + +/* Read back PAT_DATA__0 to see if write was successful */ +while (__raw_readl (r) != pd->data) + ;
Do you really need to read back every register after writing them ?
Quoted 45 lines
drivers/media/video/tiler/dmm.c new file +45
-0+ r = dmm->base +DMM_PAT_CTRL__0 ; + v =__raw_readl (r); + v =SET_FLD (v,31 ,28 , pd->ctrl.ini); + v =SET_FLD (v,16 ,16 , pd->ctrl.sync); + v =SET_FLD (v,9 ,8 , pd->ctrl.lut_id); + v =SET_FLD (v,6 ,4 , pd->ctrl.dir); + v =SET_FLD (v,0 ,0 , pd->ctrl.start); +__raw_writel (v, r); +wmb (); + +/* Check if PAT_IRQSTATUS_RAW is set after the PAT has been refilled */ + r = dmm->base +DMM_PAT_IRQSTATUS_RAW ; +while ((__raw_readl (r) &0x3 ) !=0x3 ) + ; + +/* Again, clear the DMM_PAT_IRQSTATUS register */ + r = dmm->base +DMM_PAT_IRQSTATUS ; +__raw_writel (0xFFFFFFFF , r); +wmb (); + + r = dmm->base +DMM_PAT_IRQSTATUS_RAW ; +while (__raw_readl (r) !=0 ) + ; + +/* Again, set "next" register to NULL to clear any PAT STATUS errors */ + r = dmm->base +DMM_PAT_DESCR__0 ; + v =__raw_readl (r); + v =SET_FLD (v,31 ,4 , (u32 )NULL ); +__raw_writel (v, r); + +/* +* Now, check that the DMM_PAT_STATUS register +* has not reported an error before exiting. +*/ + r = dmm->base +DMM_PAT_STATUS__0 ; + v =__raw_readl (r); +if (WARN (v &0xFC00 ,KERN_ERR "dmm_pat_refill() error.\n" )) +return -EIO ; + +return 0 ; +} +EXPORT_SYMBOL (dmm_pat_refill); + +struct dmm *dmm_pat_init (u32 id) +{
drivers/media/video/tiler/dmm.c line 149
Quoted 10 lines
drivers/media/video/tiler/dmm.c new file +10
-0+u32 base; +struct dmm *dmm; +switch (id) { +case 0 : +/* only support id 0 for now */ + base =DMM_BASE ; +break ; +default : +return NULL ; + }
Shouldn't you protect against multiple driver trying to initialize the same DMM-PAT ?
Quoted 50 lines
drivers/media/video/tiler/dmm.c new file +50
-0+ dmm =kzalloc (sizeof (*dmm),GFP_KERNEL ); +if (!dmm) +return NULL ; + + dmm->base =ioremap (base,DMM_SIZE ); +if (!dmm->base) { +kfree (dmm); +return NULL ; + } + +__raw_writel (0x88888888 , dmm->base +DMM_PAT_VIEW__0 ); +__raw_writel (0x88888888 , dmm->base +DMM_PAT_VIEW__1 ); +__raw_writel (0x80808080 , dmm->base +DMM_PAT_VIEW_MAP__0 ); +__raw_writel (0x80000000 , dmm->base +DMM_PAT_VIEW_MAP_BASE ); +__raw_writel (0x88888888 , dmm->base +DMM_TILER_OR__0 ); +__raw_writel (0x88888888 , dmm->base +DMM_TILER_OR__1 ); + +return dmm; +} +EXPORT_SYMBOL (dmm_pat_init); + +/** +* Clean up the physical address translator. +* @param dmm Device data +* @return an error status. +*/ +void dmm_pat_release (struct dmm *dmm) +{ +if (dmm) { +iounmap (dmm->base); +kfree (dmm); + } +} +EXPORT_SYMBOL (dmm_pat_release); + +static s32 __init dmm_init (void ) +{ +return platform_driver_register (&dmm_driver_ldm); +} + +static void __exit dmm_exit(void) +{ +platform_driver_unregister (&dmm_driver_ldm); +} + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("davidsin at ti.com" ); +MODULE_AUTHOR ("molnar at ti.com" ); +module_init (dmm_init); +module_exit (dmm_exit);
Signature · 3 lines
Regards, Laurent Pinchart
RE: [RFC 1/8] TILER-DMM: DMM-PAT driver for TI TILER
In reply to Laurent PinchartHi Laurent,
Thanks for taking the time to review. These are all very good comments and I will work on incorporating them into the next RFC version.
-David
-----Original Message-----
From: Laurent Pinchart [mailto:[email protected]]
Sent: Monday, July 26, 2010 3:13 AM
To: [email protected]
Cc: Sin, David; Molnar, Lajos
Subject: Re: [RFC 1/8] TILER-DMM: DMM-PAT driver for TI TILER
Hi David,
Quoted 39 lines · On Saturday 24 July 2010 01:28:07 David Sin wrote:
This patch adds support for DMM-PAT initialization and programming.
Signed-off-by David Sin <[email protected]>Signed-off-by Lajos Molnar <[email protected]>--- arch/arm/mach-omap2/include/mach/dmm.h | 128 ++++++++++++++++++++ drivers/media/video/tiler/dmm.c | 200 ++++++++++++++++++++++++++++++++ 2 files changed, 328 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-omap2/include/mach/dmm.h create mode 100644 drivers/media/video/tiler/dmm.c(quoted diff) +0
-0
b/arch/arm/mach-omap2/include/mach/dmm.hnew file mode 100644 index 0000000..68b798aarch/arm/mach-omap2/include/mach/dmm.h new file +21
-0@@ -0,0 +1,128 @@ +/* +* dmm.h +* +* DMM driver support functions for TI DMM-TILER hardware block. +* +* Author: David Sin <[email protected]> +* +* Copyright (C) 2009-2010 Texas Instruments, Inc. +* +* This package is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#ifndef DMM_H +#define DMM_H +
arch/arm/mach-omap2/include/mach/dmm.h line 31
Quoted 10 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +10
-0+#define DMM_BASE 0x4E000000 +#define DMM_SIZE 0x800 + +#define DMM_REVISION 0x000 +#define DMM_HWINFO 0x004 +#define DMM_LISA_HWINFO 0x008 +#define DMM_DMM_SYSCONFIG 0x010 +#define DMM_LISA_LOCK 0x01C +#define DMM_LISA_MAP__0 0x040 +#define DMM_LISA_MAP__1 0x044
Why the double _ ?
Quoted 24 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +24
-0+#define DMM_TILER_HWINFO 0x208 +#define DMM_TILER_OR__0 0x220 +#define DMM_TILER_OR__1 0x224 +#define DMM_PAT_HWINFO 0x408 +#define DMM_PAT_GEOMETRY 0x40C +#define DMM_PAT_CONFIG 0x410 +#define DMM_PAT_VIEW__0 0x420 +#define DMM_PAT_VIEW__1 0x424 +#define DMM_PAT_VIEW_MAP__0 0x440 +#define DMM_PAT_VIEW_MAP_BASE 0x460 +#define DMM_PAT_IRQ_EOI 0x478 +#define DMM_PAT_IRQSTATUS_RAW 0x480 +#define DMM_PAT_IRQSTATUS 0x490 +#define DMM_PAT_IRQENABLE_SET 0x4A0 +#define DMM_PAT_IRQENABLE_CLR 0x4B0 +#define DMM_PAT_STATUS__0 0x4C0 +#define DMM_PAT_STATUS__1 0x4C4 +#define DMM_PAT_STATUS__2 0x4C8 +#define DMM_PAT_STATUS__3 0x4CC +#define DMM_PAT_DESCR__0 0x500 +#define DMM_PAT_AREA__0 0x504 +#define DMM_PAT_CTRL__0 0x508 +#define DMM_PAT_DATA__0 0x50C +#define DMM_PEG_HWINFO 0x608
arch/arm/mach-omap2/include/mach/dmm.h line 65
Quoted 10 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +10
-0+#define DMM_PEG_PRIO 0x620 +#define DMM_PEG_PRIO_PAT 0x640 + +/** +* PAT refill programming mode. +*/ +enum pat_mode { +MANUAL , +AUTO +};
MANUAL and AUTO are pretty generic names to have in the top-level scope. Please at least rename them to PAT_MANUAL and PAT_AUTO.
Even better, the pat_ prefix might be better called dmm_pat_, as PAT is already used for Physical Address Extension on x86 (granted, the DMM-PAT is not likely to be used on x86 platforms).
An explanation of the DMM and PAT acronyms would be nice as well.
arch/arm/mach-omap2/include/mach/dmm.h line 74
Quoted 9 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +9
-0+ +/** +* Area definition for DMM physical address translator. +*/ +struct pat_area { +s32 x0:8 ; +s32 y0:8 ; +s32 x1:8 ; +s32 y1:8 ;
What's wrong with four u8 fields ?
Quoted 91 lines
arch/arm/mach-omap2/include/mach/dmm.h new file +54
-0+}; + +/** +* DMM physical address translator control. +*/ +struct pat_ctrl { +s32 start:4 ; +s32 dir:4 ; +s32 lut_id:8 ; +s32 sync:12 ; +s32 ini:4 ; +}; + +/** +* PAT descriptor. +*/ +struct pat { +struct pat *next; +struct pat_area area; +struct pat_ctrl ctrl; +u32 data; +}; + +/** +* DMM device data +*/ +struct dmm { +void __iomem *base; +}; + +/** +* Create and initialize the physical address translator. +* @param id PAT id +* @return pointer to device data +*/ +struct dmm *dmm_pat_init (u32 id); + +/** +* Program the physical address translator. +* @param dmm Device data +* @param desc PAT descriptor +* @param mode programming mode +* @return an error status. +*/ +s32 dmm_pat_refill (struct dmm *dmm,struct pat *desc,enum pat_mode mode); + +/** +* Clean up the physical address translator. +* @param dmm Device data +* @return an error status. +*/ +void dmm_pat_release (struct dmm *dmm); + +#endif (quoted diff) +0
-0
b/drivers/media/video/tiler/dmm.cnew file mode 100644 index 0000000..e715936drivers/media/video/tiler/dmm.c new file +31
-0@@ -0,0 +1,200 @@ +/* +* dmm.c +* +* DMM driver support functions for TI OMAP processors. +* +* Authors: David Sin <[email protected]> +* Lajos Molnar <[email protected]> +* +* Copyright (C) 2009-2010 Texas Instruments, Inc. +* +* This package is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +*/ + +#include <linux/init.h> +#include <linux/module.h> +#include <linux/platform_device.h> /* platform_device() */ +#include <linux/io.h> /* ioremap() */ +#include <linux/errno.h> +#include <linux/slab.h> + +#include <mach/dmm.h> + +#define MASK (msb, lsb) (((1 << ((msb) + 1 - (lsb))) - 1) << (lsb)) +#define SET_FLD (reg, msb, lsb, val) \ +(((reg) & ~MASK((msb), (lsb))) | (((val) << (lsb)) & MASK((msb), (lsb))))
drivers/media/video/tiler/dmm.c line 41
Quoted 10 lines
drivers/media/video/tiler/dmm.c new file +10
-0+ +static struct platform_driver dmm_driver_ldm = { + .driver = { + .owner =THIS_MODULE , + .name ="dmm" , + }, + .probe =NULL , + .shutdown =NULL , + .remove =NULL , +};
Why do you need a platform_driver if it's completely empty ? Instead of using the hardcoded DMM_BASE and DMM_SIZE constants in the driver, you should implement a probe function and retrieve them from the platform device resources.
drivers/media/video/tiler/dmm.c line 54
Quoted 12 lines
drivers/media/video/tiler/dmm.c new file +12
-0+s32 dmm_pat_refill (struct dmm *dmm,struct pat *pd,enum pat_mode mode) +{ +void __iomem *r; +u32 v; + +/* Only manual refill supported */ +if (mode !=MANUAL ) +return -EFAULT ; + +/* Check that the DMM_PAT_STATUS register has not reported an error */ + r = dmm->base +DMM_PAT_STATUS__0 ; + v =__raw_readl (r);
Adding dmm_read and dmm_write macros that compute the address using the base and offset would make the code simpler. You could also define dmm_clear_bits and dmm_set_bits macros.
drivers/media/video/tiler/dmm.c line 54
Quoted 1 line
drivers/media/video/tiler/dmm.c new file +1
-0+if (WARN (v &0xFC00 ,KERN_ERR "dmm_pat_refill() error.\n" ))
Can you define constants for the field's bits and use them instead of the hardcoded 0xfc00 ?
Same comment for the other values you use in the driver (both the register values, field numbers, shift constants, ...).
Quoted 16 lines
drivers/media/video/tiler/dmm.c new file +16
-0+return -EIO ; + +/* Set "next" register to NULL */ + r = dmm->base +DMM_PAT_DESCR__0 ; + v =__raw_readl (r); + v =SET_FLD (v,31 ,4 , (u32 )NULL ); +__raw_writel (v, r); + +/* Set area to be refilled */ + r = dmm->base +DMM_PAT_AREA__0 ; + v =__raw_readl (r); + v =SET_FLD (v,30 ,24 , pd->area.y1); + v =SET_FLD (v,23 ,16 , pd->area.x1); + v =SET_FLD (v,14 ,8 , pd->area.y0); + v =SET_FLD (v,7 ,0 , pd->area.x0); +__raw_writel (v, r);
drivers/media/video/tiler/dmm.c line 81
Quoted 10 lines
drivers/media/video/tiler/dmm.c new file +10
-0+wmb (); + +/* First, clear the DMM_PAT_IRQSTATUS register */ + r = dmm->base +DMM_PAT_IRQSTATUS ; +__raw_writel (0xFFFFFFFF , r); +wmb (); + + r = dmm->base +DMM_PAT_IRQSTATUS_RAW ; +while (__raw_readl (r) !=0 ) + ;
How long is this expected to last ? Shouldn't you add a timeout ?
drivers/media/video/tiler/dmm.c line 93
Quoted 11 lines
drivers/media/video/tiler/dmm.c new file +11
-0+/* Fill data register */ + r = dmm->base +DMM_PAT_DATA__0 ; + v =__raw_readl (r); + + v =SET_FLD (v,31 ,4 , pd->data >>4 ); +__raw_writel (v, r); +wmb (); + +/* Read back PAT_DATA__0 to see if write was successful */ +while (__raw_readl (r) != pd->data) + ;
Do you really need to read back every register after writing them ?
Quoted 45 lines
drivers/media/video/tiler/dmm.c new file +45
-0+ r = dmm->base +DMM_PAT_CTRL__0 ; + v =__raw_readl (r); + v =SET_FLD (v,31 ,28 , pd->ctrl.ini); + v =SET_FLD (v,16 ,16 , pd->ctrl.sync); + v =SET_FLD (v,9 ,8 , pd->ctrl.lut_id); + v =SET_FLD (v,6 ,4 , pd->ctrl.dir); + v =SET_FLD (v,0 ,0 , pd->ctrl.start); +__raw_writel (v, r); +wmb (); + +/* Check if PAT_IRQSTATUS_RAW is set after the PAT has been refilled */ + r = dmm->base +DMM_PAT_IRQSTATUS_RAW ; +while ((__raw_readl (r) &0x3 ) !=0x3 ) + ; + +/* Again, clear the DMM_PAT_IRQSTATUS register */ + r = dmm->base +DMM_PAT_IRQSTATUS ; +__raw_writel (0xFFFFFFFF , r); +wmb (); + + r = dmm->base +DMM_PAT_IRQSTATUS_RAW ; +while (__raw_readl (r) !=0 ) + ; + +/* Again, set "next" register to NULL to clear any PAT STATUS errors */ + r = dmm->base +DMM_PAT_DESCR__0 ; + v =__raw_readl (r); + v =SET_FLD (v,31 ,4 , (u32 )NULL ); +__raw_writel (v, r); + +/* +* Now, check that the DMM_PAT_STATUS register +* has not reported an error before exiting. +*/ + r = dmm->base +DMM_PAT_STATUS__0 ; + v =__raw_readl (r); +if (WARN (v &0xFC00 ,KERN_ERR "dmm_pat_refill() error.\n" )) +return -EIO ; + +return 0 ; +} +EXPORT_SYMBOL (dmm_pat_refill); + +struct dmm *dmm_pat_init (u32 id) +{
drivers/media/video/tiler/dmm.c line 149
Quoted 10 lines
drivers/media/video/tiler/dmm.c new file +10
-0+u32 base; +struct dmm *dmm; +switch (id) { +case 0 : +/* only support id 0 for now */ + base =DMM_BASE ; +break ; +default : +return NULL ; + }
Shouldn't you protect against multiple driver trying to initialize the same DMM-PAT ?
Quoted 50 lines
drivers/media/video/tiler/dmm.c new file +50
-0+ dmm =kzalloc (sizeof (*dmm),GFP_KERNEL ); +if (!dmm) +return NULL ; + + dmm->base =ioremap (base,DMM_SIZE ); +if (!dmm->base) { +kfree (dmm); +return NULL ; + } + +__raw_writel (0x88888888 , dmm->base +DMM_PAT_VIEW__0 ); +__raw_writel (0x88888888 , dmm->base +DMM_PAT_VIEW__1 ); +__raw_writel (0x80808080 , dmm->base +DMM_PAT_VIEW_MAP__0 ); +__raw_writel (0x80000000 , dmm->base +DMM_PAT_VIEW_MAP_BASE ); +__raw_writel (0x88888888 , dmm->base +DMM_TILER_OR__0 ); +__raw_writel (0x88888888 , dmm->base +DMM_TILER_OR__1 ); + +return dmm; +} +EXPORT_SYMBOL (dmm_pat_init); + +/** +* Clean up the physical address translator. +* @param dmm Device data +* @return an error status. +*/ +void dmm_pat_release (struct dmm *dmm) +{ +if (dmm) { +iounmap (dmm->base); +kfree (dmm); + } +} +EXPORT_SYMBOL (dmm_pat_release); + +static s32 __init dmm_init (void ) +{ +return platform_driver_register (&dmm_driver_ldm); +} + +static void __exit dmm_exit(void) +{ +platform_driver_unregister (&dmm_driver_ldm); +} + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("[email protected]" ); +MODULE_AUTHOR ("[email protected]" ); +module_init (dmm_init); +module_exit (dmm_exit);
Signature · 3 lines
Regards, Laurent Pinchart
cover TI TILER-DMM driver
In reply to David Sin2010/7/24 David Sin <[email protected]>:
Quoted 6 lines
TILER is a hardware block made by Texas Instruments. ?Its purpose is to organize video/image memory in a 2-dimensional fashion to limit memory bandwidth and facilitate 0 effort rotation and mirroring. ?The TILER driver facilitates allocating, freeing, as well as mapping 2D blocks (areas) in the TILER container(s). ?It also facilitates rotating and mirroring the allocated blocks or its rectangular subsections.
Pretty cool hardware!
(...)
Quoted 2 lines
* Add multiple search directions to TCM-SiTA
* Add 1D block support (including adding 1D search algo to TCM-SiTA)
Spell out these acronyms. I've been writing some code for the ARM TCM (Tightly Coupled Memory) and often vendors pick up this terminology and call all on-chip memory "TCM", though it has a specific technical meaning in ARM context.
What does TCM mean in your case?
And what is SiTA?
Yours,
Linus Walleij
cover TI TILER-DMM driver
Thanks for your feedback, Linus. I will incorporate an acronym list in the documentation. TCM stands for TILER container manager, which pretty much represents the interface to the logic which determines the location for a given 2-D area request. SiTA (Simple TILER algorithm) is the implementation behind that interface. I will work on revising the acronym to avoid any conflicts.
-David
-----Original Message-----
From: Linus Walleij [mailto:linus.ml.walleij at gmail.com]
Sent: Saturday, July 24, 2010 6:48 PM
To: Sin, David
Cc: linux-arm-kernel at lists.infradead.org
Subject: Re: [RFC 0/8] TI TILER-DMM driver
2010/7/24 David Sin <[email protected]>:
Quoted 6 lines
TILER is a hardware block made by Texas Instruments. ?Its purpose is to organize video/image memory in a 2-dimensional fashion to limit memory bandwidth and facilitate 0 effort rotation and mirroring. ?The TILER driver facilitates allocating, freeing, as well as mapping 2D blocks (areas) in the TILER container(s). ?It also facilitates rotating and mirroring the allocated blocks or its rectangular subsections.
Pretty cool hardware!
(...)
Quoted 2 lines
* Add multiple search directions to TCM-SiTA
* Add 1D block support (including adding 1D search algo to TCM-SiTA)
Spell out these acronyms. I've been writing some code for the ARM TCM (Tightly Coupled Memory) and often vendors pick up this terminology and call all on-chip memory "TCM", though it has a specific technical meaning in ARM context.
What does TCM mean in your case?
And what is SiTA?
Yours,
Linus Walleij