Re: [PATCH 0/9] TI DMM-TILER driver

2010-12-22 Thread David Sin
On Fri, Dec 17, 2010 at 09:28:07AM +1000, Dave Airlie wrote:
 On Fri, Dec 17, 2010 at 5:02 AM, David Sin david...@ti.com wrote:
 I get the impression with the ARM graphics, that you just have a lot
 of separate drivers for separate IP blocks all providing some misc
 random interfaces to userspace where some binary driver binds all the
 functionality together into a useful whole, which seems like a really
 bad design.
 
 Generally on x86, the tiling hw is part of the GPU and is exposed as
 part of a coherent GPU driver.
 
 I'm just wonder what the use-cases for this tiler are and what open
 apps can use it for?
 
 Dave.
Yes -- on the omap4 soc, the dmm-tiler hw block is separate from the 
gpu.  I've had some, but not much, past discusions on hw designs 
where graphics/video related ip blocks are part of the same core.  It's 
a good point that you bring up and it certainly makes sense to me.  
I will bring it up with some omap hw folks that I know, and see if 
something that can be considered in future omap versions.
 
Some of the use-cases are HD video decoding and encoding.  Also, 
hi-res image capture -- I believe 12MP or greater.  OpenMax IL components 
and other multimedia frameworks can allocate video memory 
through a user space tiler library.  Thanks for your comments, Dave.  
-- 
David Sin
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/9] TI DMM-TILER driver

2010-12-16 Thread David Sin
On Thu, Dec 16, 2010 at 02:34:05PM +0100, Arnd Bergmann wrote:
 On Monday 06 December 2010, David Sin wrote:
  Tiling and Isometric Lightweight Engine for Rotation (TILER) driver
  =
  
  Dynamic Memory Manager (DMM) is a hardware block made by Texas Instruments.
  Within the DMM exists at least one TILER hardware component.  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.
 
 How does this relate to DRM/GEM? I don't understand too much about graphics
 drivers, but it does sound like there is some overlap in functionality.
 
 I guess at the very least the DMM should live in drivers/gpu/ instead of
 drivers/misc, but perhaps it could be integrated more closely with the
 existing code there.
 
   Arnd
Do you know if anyone on your team is familiar with DRM/GEM (grap ext mgr) 
for x86?  I'm trying to understand the differences and make a case that 
 it's not the same as DMM/TILER.  

thanks,
-- 
David Sin
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/9] TI DMM-TILER driver

2010-12-16 Thread David Sin
On Thu, Dec 16, 2010 at 11:25:31AM -0600, David Sin wrote:
 On Thu, Dec 16, 2010 at 02:34:05PM +0100, Arnd Bergmann wrote:
  On Monday 06 December 2010, David Sin wrote:
   Tiling and Isometric Lightweight Engine for Rotation (TILER) driver
   =
   
   Dynamic Memory Manager (DMM) is a hardware block made by Texas 
   Instruments.
   Within the DMM exists at least one TILER hardware component.  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.
  
  How does this relate to DRM/GEM? I don't understand too much about graphics
  drivers, but it does sound like there is some overlap in functionality.
  
  I guess at the very least the DMM should live in drivers/gpu/ instead of
  drivers/misc, but perhaps it could be integrated more closely with the
  existing code there.
  
  Arnd
 Do you know if anyone on your team is familiar with DRM/GEM (grap ext mgr) 
 for x86?  I'm trying to understand the differences and make a case that 
  it's not the same as DMM/TILER.  
 
 thanks,
 -- 
 David Sin
Hi Arnd,
I'm not sure exactly how DRM/GEM works..  What functionality do you think is 
overlapping?  The main feature, aside from reduced page accesses, of the DMM 
hw block is to provide physically contiguous 2 dimensional memory blocks for 
image and video processing.  This hw sits between the interconnect and the 
ext memory interface in the OMAP, and contains an MMU-like address traslator 
for virtually physically contiguous memory and sdram pages.

thank you for your comments.

BR,
-- 
David Sin
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/9] TI DMM-TILER driver

2010-12-16 Thread David Sin
On Thu, Dec 16, 2010 at 06:43:48PM +0100, Arnd Bergmann wrote:
 As far as I can tell, both DMM and GEM at a high level manage objects
 in video memory. The IOMMU that you have on the Omap hardware seems
 to resemble the GART that sits between PC-style video cards and main
 memory.
 
 I don't know any details, but google quickly finds
 http://lwn.net/Articles/283798/ with a description of the
 initial GEM design. My main thought when looking over the
 DMM code was that this should not be tied too closely to a
 specific hardware, and GEM seems to be an existing abstraction
 that may fit what you need.
 
   Arnd
Thanks for the pointer, Arnd.  I also found a nice readme file in 
the gpu/drm directory, which points to a wiki and source code.  
I'll read into this and get back to you.

BR,
-- 
David Sin
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 7/9] TILER-DMM: Main TILER driver implementation

2010-12-13 Thread David Sin
On Mon, Dec 06, 2010 at 03:21:59PM -0800, Tony Lindgren wrote:
 Hi,
 
 * David Sin david...@ti.com [101206 14:09]:
  From: Lajos Molnar mol...@ti.com
  
  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.
 
 ...
  +config TILER_GRANULARITY
  +int Allocation granularity
  +range 1 4096
  +default 128
 ...
  +config TILER_ALIGNMENT
  +int Allocation alignment
  +range 1 4096
  +default 4096
 ...
  +config TILER_CACHE_LIMIT
  +int Memory limit to cache free pages in MBytes
  +range 0 128
  +default 40
 ...
 
 Do you really need these Kconfig options? To me it seems you
 should pass these in platform_data.
 
 Regards,
 
 Tony
Hi Tony,
No -- we don't really need these here, but we thought that 
it would be an easy way for the user to set them -- esp the 
 CACHE_LIMIT.  We can actually remove themi, since it's not 
 going to change very often, and add it to plat data later.  
I'll revise the patch.  BTW, Are you going to be the one to 
 merge this code? 

Regards,
-- 
David Sin
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/9] TILER-DMM: Sample TCM implementation: Simple TILER Allocator (SiTA)

2010-12-06 Thread David Sin
From: Ravi Ramachandra r.ramachan...@ti.com

This patch implements a simple TILER Container Manager (TCM).

Signed-off-by: Ravi Ramachandra r.ramachan...@ti.com
Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 drivers/misc/tiler/tcm/Makefile|1 +
 drivers/misc/tiler/tcm/_tcm-sita.h |   61 +
 drivers/misc/tiler/tcm/tcm-sita.c  |  422 
 drivers/misc/tiler/tcm/tcm-sita.h  |   28 +++
 4 files changed, 512 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/tiler/tcm/Makefile
 create mode 100644 drivers/misc/tiler/tcm/_tcm-sita.h
 create mode 100644 drivers/misc/tiler/tcm/tcm-sita.c
 create mode 100644 drivers/misc/tiler/tcm/tcm-sita.h

diff --git a/drivers/misc/tiler/tcm/Makefile b/drivers/misc/tiler/tcm/Makefile
new file mode 100644
index 000..8434607
--- /dev/null
+++ b/drivers/misc/tiler/tcm/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_TI_TILER) += tcm-sita.o
diff --git a/drivers/misc/tiler/tcm/_tcm-sita.h 
b/drivers/misc/tiler/tcm/_tcm-sita.h
new file mode 100644
index 000..6e4d292
--- /dev/null
+++ b/drivers/misc/tiler/tcm/_tcm-sita.h
@@ -0,0 +1,61 @@
+/*
+ * SImple Tiler Allocator (SiTA) private structures.
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _TCM_SITA_H
+#define _TCM_SITA_H
+
+#include ../tcm.h
+
+/* length between two coordinates */
+#define LEN(a, b) ((a)  (b) ? (a) - (b) + 1 : (b) - (a) + 1)
+
+enum criteria {
+   CR_MAX_NEIGHS   = 0x01,
+   CR_FIRST_FOUND  = 0x10,
+   CR_BIAS_HORIZONTAL  = 0x20,
+   CR_BIAS_VERTICAL= 0x40,
+   CR_DIAGONAL_BALANCE = 0x80
+};
+
+/* nearness to the beginning of the search field from 0 to 1000 */
+struct nearness_factor {
+   s32 x;
+   s32 y;
+};
+
+/*
+ * Statistics on immediately neighboring slots. Edge is the number of
+ * border segments that are also border segments of the scan field.  Busy
+ * refers to the number of neighbors that are occupied.
+ */
+struct neighbor_stats {
+   u16 edge;
+   u16 busy;
+};
+
+/* structure to keep the score of a potential allocation */
+struct score {
+   struct nearness_factor  f;
+   struct neighbor_stats   n;
+   struct tcm_area a;
+   u16neighs;  /* number of busy neighbors */
+};
+
+struct sita_pvt {
+   struct mutex mtx;
+   struct tcm_area ***map; /* pointers to the parent area for each slot */
+};
+
+#endif
diff --git a/drivers/misc/tiler/tcm/tcm-sita.c 
b/drivers/misc/tiler/tcm/tcm-sita.c
new file mode 100644
index 000..a7ceac4
--- /dev/null
+++ b/drivers/misc/tiler/tcm/tcm-sita.c
@@ -0,0 +1,422 @@
+/*
+ * SImple Tiler Allocator (SiTA): 2D and 1D allocation(reservation) algorithm
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/slab.h
+
+#include _tcm-sita.h
+#include tcm-sita.h
+
+#define TCM_ALG_NAME tcm_sita
+#include tcm-utils.h
+
+#define ALIGN_DOWN(value, align) ((value)  ~((align) - 1))
+
+/* Individual selection criteria for different scan areas */
+static s32 CR_L2R_T2B = CR_BIAS_HORIZONTAL;
+
+/*
+ * TCM API - Sita Implementation
+ */
+static s32 sita_reserve_2d(struct tcm *tcm, u16 h, u16 w, u8 align,
+  struct tcm_area *area);
+static s32 sita_free(struct tcm *tcm, struct tcm_area *area);
+static void sita_deinit(struct tcm *tcm);
+
+/*
+ * Main Scanner functions
+ */
+static s32 scan_areas_and_find_fit(struct tcm *tcm, u16 w, u16 h, u16 align,
+  struct tcm_area *area);
+
+static s32 scan_l2r_t2b(struct tcm *tcm, u16 w, u16 h, u16 align,
+   struct tcm_area *field, struct tcm_area *area);
+
+/*
+ * Support Infrastructure Methods
+ */
+static s32 is_area_free(struct tcm_area ***map, u16 x0, u16 y0, u16 w, u16 h);
+
+static s32 update_candidate(struct tcm *tcm, u16 x0, u16 y0, u16 w, u16 h,
+   struct tcm_area *field, s32 criteria,
+   struct score *best);
+
+static void

[PATCH 0/9] TI DMM-TILER driver

2010-12-06 Thread David Sin
Tiling and Isometric Lightweight Engine for Rotation (TILER) driver
=

Dynamic Memory Manager (DMM) is a hardware block made by Texas Instruments.
Within the DMM exists at least one TILER hardware component.  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 component 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).

Technical Reference Manual
=
http://focus.ti.com/pdfs/wtbu/OMAP4430_ES2.x_PUBLIC_TRM_vN.zip

Changes since RFC v2: https://lkml.org/lkml/2010/11/30/352
=
Randy Dunlap:
1) Clarify the meaning of 2^n when referring to TILER alignment and 
allocation granularity

Greg KH:
1) Move tiler.h to include/linux since it's not arch specific
2) Rename _tiler.h to tiler-geom.h (ick)
3) Use WARN_ON instead of BUG_ON
4) Export symbols as 'EXPORT_SYMBOL_GPL'
5) Remove comment from Kconfig file

Santosh Shilimkar:
1) Create separate DMM OMAP device file patch (#9)

Changes since RFC v1: http://www.spinics.net/lists/linux-omap/msg33867.html
=
Santosh Shilimkar:
1) Correct documentation location
2) Remove ioremap of RAM
3) Implement probe function and hwmod
4) Correct commenting style
5) Reduce use of barrier instances

Linus Walleij:
1) Define TCM acryonym

Russell King:
1) Implement probe function
2) Fix spelling mistake
3) Remove GFP_ATOMIC flag when calling dma_alloc_coherent for PAT array mem
4) Replace alloc_page and flush range calls with dma_alloc_coherent

Nishanth Menon:
1) Address infinite while loop when reading dmm register

Benoit Cousson:
1) Fix source file headers
2) Correct logical errors in device file

Kevin Hilman:
1) Move DMM/TILER source code into driver/misc/tiler until a recommendation
is made as to where it should go

List of pending items in proposed order:

* Determine driver source code location
 (Currently, resides in drivers/misc/tiler)
* 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 (2):
  TILER-DMM: DMM-PAT driver for TI TILER
  TILER-DMM: Device support for OMAP

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

[PATCH 5/9] TILER-DMM: TILER interface file and documentation

2010-12-06 Thread David Sin
From: Lajos Molnar mol...@ti.com

This patch contains the TILER interface file and the documentation.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 Documentation/arm/OMAP/TILER |  126 ++
 include/linux/tiler.h|  173 ++
 2 files changed, 299 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/arm/OMAP/TILER
 create mode 100644 include/linux/tiler.h

diff --git a/Documentation/arm/OMAP/TILER b/Documentation/arm/OMAP/TILER
new file mode 100644
index 000..2e94ad7
--- /dev/null
+++ b/Documentation/arm/OMAP/TILER
@@ -0,0 +1,126 @@
+Tiling and Isometric Lightweight Engine for Rotation (TILER) driver
+
+Dynamic Memory Manager (DMM) is a hardware block made by Texas Instruments.
+Within the DMM exists at least one TILER hardware component.  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 component 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).
+
+Using TILER driver KERNEL APIs:
+
+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));
+}
+
+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 Physical Address Translator 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

[PATCH 7/9] TILER-DMM: Main TILER driver implementation

2010-12-06 Thread David Sin
From: Lajos Molnar mol...@ti.com

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.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 drivers/misc/tiler/Kconfig   |   72 +++
 drivers/misc/tiler/Makefile  |7 +
 drivers/misc/tiler/tiler-iface.c |   66 ++
 drivers/misc/tiler/tiler-main.c  |  405 ++
 4 files changed, 550 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/tiler/Kconfig
 create mode 100644 drivers/misc/tiler/Makefile
 create mode 100644 drivers/misc/tiler/tiler-iface.c
 create mode 100644 drivers/misc/tiler/tiler-main.c

diff --git a/drivers/misc/tiler/Kconfig b/drivers/misc/tiler/Kconfig
new file mode 100644
index 000..eae4fb1
--- /dev/null
+++ b/drivers/misc/tiler/Kconfig
@@ -0,0 +1,72 @@
+config HAVE_TI_DMM
+   bool
+   default y
+   depends on ARCH_OMAP4
+
+menuconfig TI_DMM
+tristate TI DMM support
+default y
+depends on HAVE_TI_DMM
+help
+   DMM driver for TI chips.
+
+menuconfig TI_TILER
+tristate TI TILER support
+default y
+depends on TI_DMM
+help
+   TILER driver for TI chips.  The TI TILER device
+   enables video rotation on certain TI chips such as OMAP4 or
+   TI816x.  Video rotation will be limited without TILER support.
+
+config TILER_GRANULARITY
+int Allocation granularity
+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 power of 2 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
+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 power of 2 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.
diff --git a/drivers/misc/tiler/Makefile b/drivers/misc/tiler/Makefile
new file mode 100644
index 000..7dbc828
--- /dev/null
+++ b/drivers/misc/tiler/Makefile
@@ -0,0 +1,7 @@
+obj-$(CONFIG_TI_DMM) += dmm.o
+dmm-objs = dmm-main.o
+
+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
diff --git a/drivers/misc/tiler/tiler-iface.c b/drivers/misc/tiler/tiler-iface.c
new file mode 100644
index 000..02c95c5
--- /dev/null
+++ b/drivers/misc/tiler/tiler-iface.c
@@ -0,0 +1,66 @@
+/*
+ * TILER driver interace functions for TI TILER hardware block.
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/module.h
+#include linux/slab.h
+#include linux/mm.h
+#include linux/mm_types.h
+#include asm/mach/map.h
+
+#include tiler-geom.h
+
+/*
+ * Memory-Map Kernel APIs
+ */
+
+s32 tiler_mmap_blk(struct tiler_block_t *blk, u32 offs, u32

[PATCH 9/9] TILER-DMM: Device support for OMAP

2010-12-06 Thread David Sin
Add DMM device support for OMAP utilizing the
OMAP HWMOD framework.

Signed-off-by: Hari Kanigeri h-kanige...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 arch/arm/mach-omap2/Makefile   |2 +
 arch/arm/mach-omap2/dmm-omap44xx.c |   80 
 2 files changed, 82 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-omap2/dmm-omap44xx.c

diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index 60e51bc..fc682ea 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -194,3 +194,5 @@ obj-y   += $(smc91x-m) 
$(smc91x-y)
 
 smsc911x-$(CONFIG_SMSC911X):= gpmc-smsc911x.o
 obj-y  += $(smsc911x-m) $(smsc911x-y)
+
+obj-$(CONFIG_ARCH_OMAP4)   += dmm-omap44xx.o
diff --git a/arch/arm/mach-omap2/dmm-omap44xx.c 
b/arch/arm/mach-omap2/dmm-omap44xx.c
new file mode 100644
index 000..a84490c
--- /dev/null
+++ b/arch/arm/mach-omap2/dmm-omap44xx.c
@@ -0,0 +1,80 @@
+/*
+ * DMM driver support functions for TI OMAP processors.
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/init.h
+#include linux/module.h
+#include mach/dmm.h
+#include plat/omap_device.h
+#include plat/omap_hwmod.h
+#include linux/errno.h
+#include linux/err.h
+
+static struct dmm *plat_data;
+static int pdata;
+
+#ifdef CONFIG_ARCH_OMAP4
+static struct dmm omap4_plat_data[] = {
+   {
+   .oh_name = dmm,
+   },
+};
+#define NUM_PDATA ARRAY_SIZE(omap4_plat_data)
+#else
+#define omap4_plat_data NULL
+#define NUM_PDATA 0
+#endif
+
+static struct omap_device_pm_latency omap_dmm_latency[] = {
+   [0] = {
+   .deactivate_func = omap_device_idle_hwmods,
+   .activate_func = omap_device_enable_hwmods,
+   .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
+   },
+};
+
+static s32 __init dmm_omap_init(void)
+{
+   struct omap_hwmod *oh = NULL;
+   struct omap_device *od = NULL;
+   struct omap_device_pm_latency *ohl = NULL;
+   int ohlc = 0, i = 0;
+
+   plat_data = omap4_plat_data;
+   pdata = NUM_PDATA;
+
+   for (i = 0; i  pdata; i++) {
+   struct dmm *data = plat_data[i];
+
+   oh = omap_hwmod_lookup(data-oh_name);
+   if (!oh)
+   goto error;
+
+   data-base = oh-_mpu_rt_va;
+   ohl = omap_dmm_latency;
+   ohlc = ARRAY_SIZE(omap_dmm_latency);
+
+   od = omap_device_build(data-oh_name, i, oh, data,
+sizeof(*data), ohl, ohlc, false);
+   if (IS_ERR(od))
+   goto error;
+   }
+   return 0;
+error:
+   return -ENODEV;
+}
+
+MODULE_LICENSE(GPL v2);
+MODULE_AUTHOR(David Sin david...@ti.com);
+device_initcall(dmm_omap_init);
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 6/9] TILER-DMM: Geometry and view manipulation functions

2010-12-06 Thread David Sin
From: Lajos Molnar mol...@ti.com

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.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 drivers/misc/tiler/tiler-geom.c |  362 +++
 drivers/misc/tiler/tiler-geom.h |   48 +
 2 files changed, 410 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/tiler/tiler-geom.c
 create mode 100644 drivers/misc/tiler/tiler-geom.h

diff --git a/drivers/misc/tiler/tiler-geom.c b/drivers/misc/tiler/tiler-geom.c
new file mode 100644
index 000..c94193b
--- /dev/null
+++ b/drivers/misc/tiler/tiler-geom.c
@@ -0,0 +1,362 @@
+/*
+ * TILER geometry functions for TI TILER hardware block.
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/module.h
+#include tiler-geom.h
+
+/* bits representing the same slot in DMM-TILER hw-block */
+#define SLOT_WIDTH_BITS6
+#define SLOT_HEIGHT_BITS   6
+
+/* bits reserved to describe coordinates in DMM-TILER hw-block */
+#define CONT_WIDTH_BITS14
+#define CONT_HEIGHT_BITS   13
+
+static struct tiler_geom geom[TILER_FORMATS] = {
+   {
+   .x_shft = 0,
+   .y_shft = 0,
+   },
+   {
+   .x_shft = 0,
+   .y_shft = 1,
+   },
+   {
+   .x_shft = 1,
+   .y_shft = 1,
+   },
+};
+
+/* tiler space addressing bitfields */
+#define MASK_XY_FLIP   (1  31)
+#define MASK_Y_INVERT  (1  30)
+#define MASK_X_INVERT  (1  29)
+#define SHIFT_ACC_MODE 27
+#define MASK_ACC_MODE  3
+
+/* calculated constants */
+#define TILER_PAGE (1  (SLOT_WIDTH_BITS + SLOT_HEIGHT_BITS))
+#define TILER_WIDTH(1  (CONT_WIDTH_BITS - SLOT_WIDTH_BITS))
+#define TILER_HEIGHT   (1  (CONT_HEIGHT_BITS - SLOT_HEIGHT_BITS))
+
+#define VIEW_SIZE  (1u  (CONT_WIDTH_BITS + CONT_HEIGHT_BITS))
+#define VIEW_MASK  (VIEW_SIZE - 1u)
+
+#define MASK(bits) ((1  (bits)) - 1)
+
+#define TILER_FMT(x)   ((enum tiler_fmt) \
+   ((x  SHIFT_ACC_MODE)  MASK_ACC_MODE))
+
+#define MASK_VIEW  (MASK_X_INVERT | MASK_Y_INVERT | MASK_XY_FLIP)
+
+/* location of the various tiler views in physical address space */
+#define TILVIEW_8BIT   0x6000u
+#define TILVIEW_16BIT  (TILVIEW_8BIT  + VIEW_SIZE)
+#define TILVIEW_32BIT  (TILVIEW_16BIT + VIEW_SIZE)
+#define TILVIEW_PAGE   (TILVIEW_32BIT + VIEW_SIZE)
+#define TILVIEW_END(TILVIEW_PAGE  + VIEW_SIZE)
+
+/* create tsptr by adding view orientation and access mode */
+#define TIL_ADDR(x, orient, a)\
+   ((u32) (x) | (orient) | ((a)  SHIFT_ACC_MODE))
+
+bool is_tiler_addr(u32 phys)
+{
+   return phys = TILVIEW_8BIT  phys  TILVIEW_END;
+}
+EXPORT_SYMBOL_GPL(is_tiler_addr);
+
+u32 tiler_bpp(const struct tiler_block_t *b)
+{
+   enum tiler_fmt fmt = tiler_fmt(b-phys);
+   WARN_ON(fmt == TILFMT_INVALID || fmt == TILFMT_PAGE);
+
+   return geom[fmt].bpp;
+}
+EXPORT_SYMBOL_GPL(tiler_bpp);
+
+/* return the stride of a tiler-block in tiler space */
+static inline s32 tiler_stride(u32 tsptr)
+{
+   enum tiler_fmt fmt = TILER_FMT(tsptr);
+
+   if (fmt == TILFMT_PAGE)
+   return 0;
+   else if (tsptr  MASK_XY_FLIP)
+   return 1  (CONT_HEIGHT_BITS + geom[fmt].x_shft);
+   else
+   return 1  (CONT_WIDTH_BITS + geom[fmt].y_shft);
+}
+
+u32 tiler_pstride(const struct tiler_block_t *b)
+{
+   enum tiler_fmt fmt = tiler_fmt(b-phys);
+   WARN_ON(fmt == TILFMT_INVALID);
+
+   /* return the virtual stride for page mode */
+   if (fmt == TILFMT_PAGE)
+   return tiler_vstride(b);
+
+   return tiler_stride(b-phys  ~MASK_VIEW);
+}
+EXPORT_SYMBOL_GPL(tiler_pstride);
+
+enum tiler_fmt tiler_fmt(u32 phys)
+{
+   if (!is_tiler_addr(phys))
+   return TILFMT_INVALID;
+
+   return TILER_FMT(phys);
+}
+EXPORT_SYMBOL_GPL(tiler_fmt);
+
+/* returns the tiler geometry information for a format */
+static const struct tiler_geom *get_geom(enum tiler_fmt fmt)
+{
+   if (fmt = TILFMT_MIN  fmt = TILFMT_MAX)
+   return geom + fmt;
+   return NULL;
+}
+
+/*
+ * Returns the natural x and y coordinates for a pixel in tiler space address.
+ * That is, the coordinates for the same pixel

[PATCH 2/9] TILER-DMM: Container manager interface and utility definitons

2010-12-06 Thread David Sin
From: Lajos Molnar mol...@ti.com

This patch defined the TILER Container Manager (TCM) interface and
provides utility methods for implementing a TCM.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
Signed-off-by: Ravi Ramachandra r.ramachan...@ti.com
---
 drivers/misc/tiler/tcm.h   |  171 
 drivers/misc/tiler/tcm/tcm-utils.h |   51 +++
 2 files changed, 222 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/tiler/tcm.h
 create mode 100644 drivers/misc/tiler/tcm/tcm-utils.h

diff --git a/drivers/misc/tiler/tcm.h b/drivers/misc/tiler/tcm.h
new file mode 100644
index 000..8968108
--- /dev/null
+++ b/drivers/misc/tiler/tcm.h
@@ -0,0 +1,171 @@
+/*
+ * TILER container manager specification and support functions for TI
+ * TILER driver.
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#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);
+};
+
+/*
+ * 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.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * 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;
+}
+
+/* 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

[PATCH 8/9] TILER-DMM: Linking TILER driver into the Linux kernel build

2010-12-06 Thread David Sin
From: Lajos Molnar mol...@ti.com

This patch links the TILER driver into the Linux kernel build
and config system.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 drivers/misc/Kconfig  |1 +
 drivers/misc/Makefile |1 +
 2 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4d073f1..1ebc655 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -457,5 +457,6 @@ source drivers/misc/eeprom/Kconfig
 source drivers/misc/cb710/Kconfig
 source drivers/misc/iwmc3200top/Kconfig
 source drivers/misc/ti-st/Kconfig
+source drivers/misc/tiler/Kconfig
 
 endif # MISC_DEVICES
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 98009cc..3716c49 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -42,3 +42,4 @@ obj-$(CONFIG_ARM_CHARLCD) += arm-charlcd.o
 obj-$(CONFIG_PCH_PHUB) += pch_phub.o
 obj-y  += ti-st/
 obj-$(CONFIG_AB8500_PWM)   += ab8500-pwm.o
+obj-$(CONFIG_TI_TILER) += tiler/
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/9] TILER-DMM: DMM-PAT driver for TI TILER

2010-12-06 Thread David Sin
This patch adds support for DMM-PAT initialization and programming.

Signed-off-by: David Sin david...@ti.com
Signed-off-by: Lajos Molnar mol...@ti.com
---
 arch/arm/mach-omap2/include/mach/dmm.h |   92 
 drivers/misc/tiler/dmm-main.c  |  187 
 2 files changed, 279 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-omap2/include/mach/dmm.h
 create mode 100644 drivers/misc/tiler/dmm-main.c

diff --git a/arch/arm/mach-omap2/include/mach/dmm.h 
b/arch/arm/mach-omap2/include/mach/dmm.h
new file mode 100644
index 000..33a1215
--- /dev/null
+++ b/arch/arm/mach-omap2/include/mach/dmm.h
@@ -0,0 +1,92 @@
+/*
+ * Dynamic Memory Manager (DMM) driver support functions for
+ * TI DMM-TILER hardware block.
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef DMM_H
+#define DMM_H
+
+#define DMM_TILER_OR__0   0x220
+#define DMM_TILER_OR__1   0x224
+#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_IRQSTATUS_RAW 0x480
+#define DMM_PAT_IRQSTATUS 0x490
+#define DMM_PAT_STATUS__0 0x4C0
+#define DMM_PAT_DESCR__0  0x500
+#define DMM_PAT_AREA__0   0x504
+#define DMM_PAT_CTRL__0   0x508
+#define DMM_PAT_DATA__0   0x50C
+
+/*
+ * Physical Address Translator (PAT) refill programming mode
+ */
+enum pat_mode {
+   MANUAL,
+   AUTO
+};
+
+/*
+ * Area definition for DMM physical address translator
+ */
+struct pat_area {
+   s8 x0:8;
+   s8 y0:8;
+   s8 x1:8;
+   s8 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;
+};
+
+/*
+ * Physical Address Translator (PAT) descriptor
+ */
+struct pat {
+   struct pat *next;
+   struct pat_area area;
+   struct pat_ctrl ctrl;
+   u32 data;
+};
+
+/*
+ * DMM device data
+ */
+struct dmm {
+   const char *oh_name;
+   void __iomem *base;
+   int irq;
+};
+
+/*
+ * Create and initialize the physical address translator
+ */
+struct dmm *dmm_pat_init(u32 id);
+
+/*
+ * Program the physical address translator
+ */
+int dmm_pat_refill(struct dmm *dmm, struct pat *desc, enum pat_mode mode);
+
+#endif
diff --git a/drivers/misc/tiler/dmm-main.c b/drivers/misc/tiler/dmm-main.c
new file mode 100644
index 000..f337bd9
--- /dev/null
+++ b/drivers/misc/tiler/dmm-main.c
@@ -0,0 +1,187 @@
+/*
+ * DMM driver support functions for TI OMAP processors.
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/init.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/io.h
+#include linux/errno.h
+#include linux/slab.h
+#include linux/delay.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
+#define MAX_RETRY_MS   1000
+
+static struct dmm *dmm;
+
+static int dmm_probe(struct platform_device *dev)
+{
+   if (dev)
+   dmm = dev-dev.platform_data;
+
+   if (dmm  dmm-base) {
+   writel(0x, dmm-base + DMM_TILER_OR__0);
+   writel(0x, dmm-base + DMM_TILER_OR__1);
+   return 0;
+   }
+   return -EFAULT;
+}
+
+static int dmm_remove(struct platform_device *dev)
+{
+   return 0;
+}
+
+static struct platform_driver dmm_driver = {
+   .probe = dmm_probe,
+   .remove = dmm_remove,
+   .driver = {
+   .owner = THIS_MODULE,
+   .name = dmm,
+   },
+};
+
+int dmm_pat_refill(struct dmm *dmm, struct pat *pd, enum pat_mode mode)
+{
+   void __iomem *r;
+   u32 v, i;
+
+   if (!dmm || !dmm-base || !pd)
+   return -EFAULT;
+
+   /* Only manual refill supported */
+   if (mode != MANUAL)
+   return -EFAULT;
+
+   /* Check

[PATCH 4/9] TILER-DMM: TILER Memory Manager interface and implementation

2010-12-06 Thread David Sin
From: Lajos Molnar mol...@ti.com

This patch defines the TILER Memory Manager (TMM) interface and
provides implementation for a PAT-supporting TMM.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 drivers/misc/tiler/tmm-pat.c |  266 ++
 drivers/misc/tiler/tmm.h |  103 
 2 files changed, 369 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/tiler/tmm-pat.c
 create mode 100644 drivers/misc/tiler/tmm.h

diff --git a/drivers/misc/tiler/tmm-pat.c b/drivers/misc/tiler/tmm-pat.c
new file mode 100644
index 000..682f549
--- /dev/null
+++ b/drivers/misc/tiler/tmm-pat.c
@@ -0,0 +1,266 @@
+/*
+ * DMM driver support functions for TI TILER hardware block.
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#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 linux/dma-mapping.h
+
+#include tmm.h
+
+/* Page size granularity can be 4k, 16k, or 64k */
+#define DMM_PAGE SZ_4K
+
+/* 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;
+   u32 *pg;/* page struct */
+   dma_addr_t 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
+ *  areless 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;
+   dma_free_coherent(NULL, DMM_PAGE, f-mem[i]-pg,
+   f-mem[i]-pa);
+   }
+   }
+   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 = dma_alloc_coherent(NULL, DMM_PAGE, m-pa, GFP_KERNEL);
+   if (!m-pg) {
+   kfree(m);
+   return NULL;
+   }
+   wmb();
+
+   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) {
+   dma_free_coherent(NULL, DMM_PAGE, m-pg, m-pa);
+   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

Re: [RFC v2 8/8] TILER-DMM: Linking TILER driver into the Linux kernel build

2010-12-02 Thread David Sin
On Tue, Nov 30, 2010 at 04:56:47PM -0800, Greg KH wrote:
 On Tue, Nov 30, 2010 at 01:58:59PM -0600, David Sin wrote:
  From: Lajos Molnar mol...@ti.com
  
  This patch links the TILER driver into the Linux kernel build
  and config system.
  
  Signed-off-by: Lajos Molnar mol...@ti.com
  Signed-off-by: David Sin david...@ti.com
  ---
   drivers/misc/Kconfig  |5 +
   drivers/misc/Makefile |1 +
   2 files changed, 6 insertions(+), 0 deletions(-)
  
  diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
  index ac6d6ac..fff7927 100644
  --- a/drivers/misc/Kconfig
  +++ b/drivers/misc/Kconfig
  @@ -378,4 +378,9 @@ source drivers/misc/eeprom/Kconfig
   source drivers/misc/cb710/Kconfig
   source drivers/misc/iwmc3200top/Kconfig
   
  +#
  +# TI TILER driver support
  +#
 
 Comments not needed.
 
 thanks,
 
 greg k-h
thanks, Greg, for the comments.  I will make all of these changes 
in the next revision.
-- 
David Sin
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC v2 0/8] TI DMM-TILER driver

2010-12-02 Thread David Sin
On Wed, Dec 01, 2010 at 12:17:22PM +0530, Varadarajan, Charulatha wrote:
 On Wed, Dec 1, 2010 at 01:28, David Sin david...@ti.com wrote:
 
 The dmm driver is making use of omap_hwmod fw. But I could not see a patch
 to add  dmm hwmod data to omap4 hwmod base in this series. Is this patch 
 series
 tested?
yes -- this code has been tested against the omap_hwmod fw.  I will send 
out a patch in the next rev.  Thanks for your comments.
-- 
David Sin
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC v2 0/8] TI DMM-TILER driver

2010-11-30 Thread David Sin
Tiling and Isometric Lightweight Engine for Rotation (TILER) driver

Dynamic Memory Manager (DMM) is a hardware block made by Texas Instruments.
Within the DMM exists at least one TILER hardware component.  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 component 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).

Changes made from RFC v1: http://www.spinics.net/lists/linux-omap/msg33867.html

Santosh Shilimkar:
1) Correct documentation location
2) Remove ioremap of RAM
3) Implement probe function and hwmod
4) Correct commenting style
5) Reduce use of barrier instances

Linus Walleij:
1) Define TCM acryonym  

Russell King:
1) Implement probe function
2) Fix spelling mistake
3) Remove GFP_ATOMIC flag when calling dma_alloc_coherent for PAT array mem
4) Replace alloc_page and flush range calls with dma_alloc_coherent

Nishanth Menon:
1) Address infinite while loop when reading dmm register

Benoit Cousson:
1) Fix source file headers
2) Correct logical errors in device file

Kevin Hilman:
1) Move DMM/TILER source code into driver/misc/tiler until a recommendation 
is made as to where it should go

List of pending items in proposed order:

* Determine driver source code location
  (Currently, resides in drivers/misc/tiler)
* 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 (SiTA)

 Documentation/arm/OMAP/TILER |  126 +
 arch/arm/mach-omap2/Makefile |1 +
 arch/arm/mach-omap2/dmm-omap44xx.c   |   81 ++
 arch/arm/mach-omap2/include/mach/dmm.h   |   92 +++
 arch/arm/mach-omap2/include/mach/tiler.h |  173 
 drivers/misc/Kconfig |5 +
 drivers/misc/Makefile|1 +
 drivers/misc/tiler/Kconfig   |   72 +
 drivers/misc/tiler/Makefile  |7 +
 drivers/misc/tiler/_tiler.h  |   48 
 drivers/misc/tiler/dmm

[RFC v2 3/8] TILER-DMM: Sample TCM implementation: Simple TILER Allocator (SiTA)

2010-11-30 Thread David Sin
From: Ravi Ramachandra r.ramachan...@ti.com

This patch implements a simple TILER Container Manager (TCM).

Signed-off-by: Ravi Ramachandra r.ramachan...@ti.com
Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 drivers/misc/tiler/tcm/Makefile|1 +
 drivers/misc/tiler/tcm/_tcm-sita.h |   61 +
 drivers/misc/tiler/tcm/tcm-sita.c  |  422 
 drivers/misc/tiler/tcm/tcm-sita.h  |   28 +++
 4 files changed, 512 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/tiler/tcm/Makefile
 create mode 100644 drivers/misc/tiler/tcm/_tcm-sita.h
 create mode 100644 drivers/misc/tiler/tcm/tcm-sita.c
 create mode 100644 drivers/misc/tiler/tcm/tcm-sita.h

diff --git a/drivers/misc/tiler/tcm/Makefile b/drivers/misc/tiler/tcm/Makefile
new file mode 100644
index 000..8434607
--- /dev/null
+++ b/drivers/misc/tiler/tcm/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_TI_TILER) += tcm-sita.o
diff --git a/drivers/misc/tiler/tcm/_tcm-sita.h 
b/drivers/misc/tiler/tcm/_tcm-sita.h
new file mode 100644
index 000..6e4d292
--- /dev/null
+++ b/drivers/misc/tiler/tcm/_tcm-sita.h
@@ -0,0 +1,61 @@
+/*
+ * SImple Tiler Allocator (SiTA) private structures.
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _TCM_SITA_H
+#define _TCM_SITA_H
+
+#include ../tcm.h
+
+/* length between two coordinates */
+#define LEN(a, b) ((a)  (b) ? (a) - (b) + 1 : (b) - (a) + 1)
+
+enum criteria {
+   CR_MAX_NEIGHS   = 0x01,
+   CR_FIRST_FOUND  = 0x10,
+   CR_BIAS_HORIZONTAL  = 0x20,
+   CR_BIAS_VERTICAL= 0x40,
+   CR_DIAGONAL_BALANCE = 0x80
+};
+
+/* nearness to the beginning of the search field from 0 to 1000 */
+struct nearness_factor {
+   s32 x;
+   s32 y;
+};
+
+/*
+ * Statistics on immediately neighboring slots. Edge is the number of
+ * border segments that are also border segments of the scan field.  Busy
+ * refers to the number of neighbors that are occupied.
+ */
+struct neighbor_stats {
+   u16 edge;
+   u16 busy;
+};
+
+/* structure to keep the score of a potential allocation */
+struct score {
+   struct nearness_factor  f;
+   struct neighbor_stats   n;
+   struct tcm_area a;
+   u16neighs;  /* number of busy neighbors */
+};
+
+struct sita_pvt {
+   struct mutex mtx;
+   struct tcm_area ***map; /* pointers to the parent area for each slot */
+};
+
+#endif
diff --git a/drivers/misc/tiler/tcm/tcm-sita.c 
b/drivers/misc/tiler/tcm/tcm-sita.c
new file mode 100644
index 000..a7ceac4
--- /dev/null
+++ b/drivers/misc/tiler/tcm/tcm-sita.c
@@ -0,0 +1,422 @@
+/*
+ * SImple Tiler Allocator (SiTA): 2D and 1D allocation(reservation) algorithm
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/slab.h
+
+#include _tcm-sita.h
+#include tcm-sita.h
+
+#define TCM_ALG_NAME tcm_sita
+#include tcm-utils.h
+
+#define ALIGN_DOWN(value, align) ((value)  ~((align) - 1))
+
+/* Individual selection criteria for different scan areas */
+static s32 CR_L2R_T2B = CR_BIAS_HORIZONTAL;
+
+/*
+ * TCM API - Sita Implementation
+ */
+static s32 sita_reserve_2d(struct tcm *tcm, u16 h, u16 w, u8 align,
+  struct tcm_area *area);
+static s32 sita_free(struct tcm *tcm, struct tcm_area *area);
+static void sita_deinit(struct tcm *tcm);
+
+/*
+ * Main Scanner functions
+ */
+static s32 scan_areas_and_find_fit(struct tcm *tcm, u16 w, u16 h, u16 align,
+  struct tcm_area *area);
+
+static s32 scan_l2r_t2b(struct tcm *tcm, u16 w, u16 h, u16 align,
+   struct tcm_area *field, struct tcm_area *area);
+
+/*
+ * Support Infrastructure Methods
+ */
+static s32 is_area_free(struct tcm_area ***map, u16 x0, u16 y0, u16 w, u16 h);
+
+static s32 update_candidate(struct tcm *tcm, u16 x0, u16 y0, u16 w, u16 h,
+   struct tcm_area *field, s32 criteria,
+   struct score *best);
+
+static void

[RFC v2 4/8] TILER-DMM: TILER Memory Manager interface and implementation

2010-11-30 Thread David Sin
From: Lajos Molnar mol...@ti.com

This patch defines the TILER Memory Manager (TMM) interface and
provides implementation for a PAT-supporting TMM.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 drivers/misc/tiler/tmm-pat.c |  266 ++
 drivers/misc/tiler/tmm.h |  103 
 2 files changed, 369 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/tiler/tmm-pat.c
 create mode 100644 drivers/misc/tiler/tmm.h

diff --git a/drivers/misc/tiler/tmm-pat.c b/drivers/misc/tiler/tmm-pat.c
new file mode 100644
index 000..26b4da3
--- /dev/null
+++ b/drivers/misc/tiler/tmm-pat.c
@@ -0,0 +1,266 @@
+/*
+ * DMM driver support functions for TI TILER hardware block.
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#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 linux/dma-mapping.h
+
+#include tmm.h
+
+/* Page size granularity can be 4k, 16k, or 64k */
+#define DMM_PAGE SZ_4K
+
+/* 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;
+   u32 *pg;/* page struct */
+   dma_addr_t 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
+ *  areless 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;
+   dma_free_coherent(NULL, DMM_PAGE, f-mem[i]-pg,
+   f-mem[i]-pa);
+   }
+   }
+   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 = dma_alloc_coherent(NULL, DMM_PAGE, m-pa, GFP_KERNEL);
+   if (!m-pg) {
+   kfree(m);
+   return NULL;
+   }
+   wmb();
+
+   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) {
+   dma_free_coherent(NULL, DMM_PAGE, m-pg, m-pa);
+   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

[RFC v2 5/8] TILER-DMM: TILER interface file and documentation

2010-11-30 Thread David Sin
From: Lajos Molnar mol...@ti.com

This patch contains the TILER interface file and the documentation.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 Documentation/arm/OMAP/TILER |  126 ++
 arch/arm/mach-omap2/include/mach/tiler.h |  173 ++
 2 files changed, 299 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/arm/OMAP/TILER
 create mode 100644 arch/arm/mach-omap2/include/mach/tiler.h

diff --git a/Documentation/arm/OMAP/TILER b/Documentation/arm/OMAP/TILER
new file mode 100644
index 000..2e94ad7
--- /dev/null
+++ b/Documentation/arm/OMAP/TILER
@@ -0,0 +1,126 @@
+Tiling and Isometric Lightweight Engine for Rotation (TILER) driver
+
+Dynamic Memory Manager (DMM) is a hardware block made by Texas Instruments.
+Within the DMM exists at least one TILER hardware component.  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 component 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).
+
+Using TILER driver KERNEL APIs:
+
+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));
+}
+
+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 Physical Address Translator 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

[RFC v2 6/8] TILER-DMM: Geometry and view manipulation functions

2010-11-30 Thread David Sin
From: Lajos Molnar mol...@ti.com

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.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 drivers/misc/tiler/_tiler.h |   48 +
 drivers/misc/tiler/tiler-geom.c |  362 +++
 2 files changed, 410 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/tiler/_tiler.h
 create mode 100644 drivers/misc/tiler/tiler-geom.c

diff --git a/drivers/misc/tiler/_tiler.h b/drivers/misc/tiler/_tiler.h
new file mode 100644
index 000..0f00330
--- /dev/null
+++ b/drivers/misc/tiler/_tiler.h
@@ -0,0 +1,48 @@
+/*
+ * TI TILER driver internal shared definitions.
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#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
diff --git a/drivers/misc/tiler/tiler-geom.c b/drivers/misc/tiler/tiler-geom.c
new file mode 100644
index 000..df5fe2c
--- /dev/null
+++ b/drivers/misc/tiler/tiler-geom.c
@@ -0,0 +1,362 @@
+/*
+ * TILER geometry functions for TI TILER hardware block.
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed as is WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/module.h
+#include _tiler.h
+
+/* bits representing the same slot in DMM-TILER hw-block */
+#define SLOT_WIDTH_BITS6
+#define SLOT_HEIGHT_BITS   6
+
+/* bits reserved to describe coordinates in DMM-TILER hw-block */
+#define CONT_WIDTH_BITS14
+#define CONT_HEIGHT_BITS   13
+
+static struct tiler_geom geom[TILER_FORMATS] = {
+   {
+   .x_shft = 0,
+   .y_shft = 0,
+   },
+   {
+   .x_shft = 0,
+   .y_shft = 1,
+   },
+   {
+   .x_shft = 1,
+   .y_shft = 1,
+   },
+};
+
+/* tiler space addressing bitfields */
+#define MASK_XY_FLIP   (1  31)
+#define MASK_Y_INVERT  (1  30)
+#define MASK_X_INVERT  (1  29)
+#define SHIFT_ACC_MODE 27
+#define MASK_ACC_MODE  3
+
+/* calculated constants */
+#define TILER_PAGE (1  (SLOT_WIDTH_BITS + SLOT_HEIGHT_BITS))
+#define TILER_WIDTH(1  (CONT_WIDTH_BITS - SLOT_WIDTH_BITS))
+#define TILER_HEIGHT   (1  (CONT_HEIGHT_BITS - SLOT_HEIGHT_BITS))
+
+#define VIEW_SIZE  (1u  (CONT_WIDTH_BITS + CONT_HEIGHT_BITS))
+#define VIEW_MASK  (VIEW_SIZE - 1u)
+
+#define MASK(bits) ((1  (bits)) - 1)
+
+#define TILER_FMT(x)   ((enum tiler_fmt) \
+   ((x  SHIFT_ACC_MODE)  MASK_ACC_MODE))
+
+#define MASK_VIEW  (MASK_X_INVERT | MASK_Y_INVERT | MASK_XY_FLIP)
+
+/* location of the various tiler views in physical address space */
+#define TILVIEW_8BIT   0x6000u
+#define TILVIEW_16BIT  (TILVIEW_8BIT  + VIEW_SIZE)
+#define TILVIEW_32BIT  (TILVIEW_16BIT + VIEW_SIZE)
+#define TILVIEW_PAGE   (TILVIEW_32BIT + VIEW_SIZE)
+#define TILVIEW_END(TILVIEW_PAGE  + VIEW_SIZE)
+
+/* create tsptr by adding

[RFC v2 7/8] TILER-DMM: Main TILER driver implementation

2010-11-30 Thread David Sin
From: Lajos Molnar mol...@ti.com

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.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 arch/arm/mach-omap2/Makefile |1 +
 drivers/misc/tiler/Kconfig   |   72 +++
 drivers/misc/tiler/Makefile  |7 +
 drivers/misc/tiler/tiler-iface.c |   66 ++
 drivers/misc/tiler/tiler-main.c  |  405 ++
 5 files changed, 551 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/tiler/Kconfig
 create mode 100644 drivers/misc/tiler/Makefile
 create mode 100644 drivers/misc/tiler/tiler-iface.c
 create mode 100644 drivers/misc/tiler/tiler-main.c

diff --git a/arch/arm/mach-omap2/Makefile b/arch/arm/mach-omap2/Makefile
index ebd2589..d55e29c 100644
--- a/arch/arm/mach-omap2/Makefile
+++ b/arch/arm/mach-omap2/Makefile
@@ -183,3 +183,4 @@ obj-y   += $(nand-m) 
$(nand-y)
 smc91x-$(CONFIG_SMC91X):= gpmc-smc91x.o
 obj-y  += $(smc91x-m) $(smc91x-y)
 obj-$(CONFIG_ARCH_OMAP4)   += hwspinlocks.o
+obj-$(CONFIG_ARCH_OMAP4)   += dmm-omap44xx.o
diff --git a/drivers/misc/tiler/Kconfig b/drivers/misc/tiler/Kconfig
new file mode 100644
index 000..9b8bfed
--- /dev/null
+++ b/drivers/misc/tiler/Kconfig
@@ -0,0 +1,72 @@
+config HAVE_TI_DMM
+   bool
+   default y
+   depends on ARCH_OMAP4
+
+menuconfig TI_DMM
+tristate TI DMM support
+default y
+depends on HAVE_TI_DMM
+help
+   DMM driver for TI chips.
+
+menuconfig TI_TILER
+tristate TI TILER support
+default y
+depends on TI_DMM
+help
+   TILER driver for TI chips.  The TI TILER device
+   enables video rotation on certain TI chips such as OMAP4 or
+   TI816x.  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.
diff --git a/drivers/misc/tiler/Makefile b/drivers/misc/tiler/Makefile
new file mode 100644
index 000..7dbc828
--- /dev/null
+++ b/drivers/misc/tiler/Makefile
@@ -0,0 +1,7 @@
+obj-$(CONFIG_TI_DMM) += dmm.o
+dmm-objs = dmm-main.o
+
+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
diff --git a/drivers/misc/tiler/tiler-iface.c b/drivers/misc/tiler/tiler-iface.c
new file mode 100644
index 000..3c64c00
--- /dev/null
+++ b/drivers/misc/tiler/tiler-iface.c
@@ -0,0 +1,66 @@
+/*
+ * TILER driver interace functions for TI TILER hardware block.
+ *
+ * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free

[RFC v2 8/8] TILER-DMM: Linking TILER driver into the Linux kernel build

2010-11-30 Thread David Sin
From: Lajos Molnar mol...@ti.com

This patch links the TILER driver into the Linux kernel build
and config system.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 drivers/misc/Kconfig  |5 +
 drivers/misc/Makefile |1 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index ac6d6ac..fff7927 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -378,4 +378,9 @@ source drivers/misc/eeprom/Kconfig
 source drivers/misc/cb710/Kconfig
 source drivers/misc/iwmc3200top/Kconfig
 
+#
+# TI TILER driver support
+#
+source drivers/misc/tiler/Kconfig
+
 endif # MISC_DEVICES
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index bf6f0e0..9985a6f 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -33,3 +33,4 @@ obj-y += eeprom/
 obj-y  += cb710/
 obj-$(CONFIG_VMWARE_BALLOON)   += vmware_balloon.o
 obj-$(CONFIG_SENSORS_BH1780)   += bh1780gli.o
+obj-$(CONFIG_TI_TILER) += tiler/
-- 
1.7.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC 0/8] TI TILER-DMM driver

2010-07-23 Thread David Sin
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

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC 6/8] TILER-DMM: Geometry and view manipulation functions.

2010-07-23 Thread David Sin
From: Lajos Molnar mol...@ti.com

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.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 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

diff --git a/drivers/media/video/tiler/_tiler.h 
b/drivers/media/video/tiler/_tiler.h
new file mode 100644
index 000..38fff3b
--- /dev/null
+++ b/drivers/media/video/tiler/_tiler.h
@@ -0,0 +1,51 @@
+/*
+ * _tiler.h
+ *
+ * TI TILER driver internal shared definitions.
+ *
+ * Author: Lajos Molnar mol...@ti.com
+ *
+ * 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
diff --git a/drivers/media/video/tiler/tiler-geom.c 
b/drivers/media/video/tiler/tiler-geom.c
new file mode 100644
index 000..619413f
--- /dev/null
+++ b/drivers/media/video/tiler/tiler-geom.c
@@ -0,0 +1,360 @@
+/*
+ * tiler-geom.c
+ *
+ * TILER geometry functions for TI TILER hardware block.
+ *
+ * Author: Lajos Molnar mol...@ti.com
+ *
+ * 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/module.h
+#include _tiler.h
+
+/* bits representing the same slot in DMM-TILER hw-block */
+#define SLOT_WIDTH_BITS6
+#define SLOT_HEIGHT_BITS   6
+
+/* bits reserved to describe coordinates in DMM-TILER hw-block */
+#define CONT_WIDTH_BITS14
+#define CONT_HEIGHT_BITS   13
+
+static struct tiler_geom geom[TILER_FORMATS] = {
+   {
+   .x_shft = 0,
+   .y_shft = 0,
+   },
+   {
+   .x_shft = 0,
+   .y_shft = 1,
+   },
+   {
+   .x_shft = 1,
+   .y_shft = 1,
+   },
+};
+
+/* tiler space addressing bitfields */
+#define MASK_XY_FLIP   (1  31)
+#define MASK_Y_INVERT  (1  30)
+#define MASK_X_INVERT  (1  29)
+#define SHIFT_ACC_MODE 27
+#define MASK_ACC_MODE  3
+
+/* calculated constants */
+#define TILER_PAGE (1  (SLOT_WIDTH_BITS + SLOT_HEIGHT_BITS))
+#define TILER_WIDTH(1  (CONT_WIDTH_BITS - SLOT_WIDTH_BITS))
+#define TILER_HEIGHT   (1  (CONT_HEIGHT_BITS - SLOT_HEIGHT_BITS))
+
+#define VIEW_SIZE  (1u  (CONT_WIDTH_BITS + CONT_HEIGHT_BITS))
+#define VIEW_MASK  (VIEW_SIZE - 1u)
+
+#define MASK(bits) ((1  (bits)) - 1)
+
+#define TILER_FMT(x)   ((enum tiler_fmt) \
+   ((x  SHIFT_ACC_MODE)  MASK_ACC_MODE))
+
+#define MASK_VIEW  (MASK_X_INVERT | MASK_Y_INVERT | MASK_XY_FLIP)
+
+/* location of the various tiler views in physical address space */
+#define TILVIEW_8BIT   0x6000u
+#define TILVIEW_16BIT  (TILVIEW_8BIT  + VIEW_SIZE)
+#define TILVIEW_32BIT  (TILVIEW_16BIT + VIEW_SIZE)
+#define TILVIEW_PAGE   (TILVIEW_32BIT + VIEW_SIZE)
+#define TILVIEW_END(TILVIEW_PAGE

[RFC 7/8] TILER-DMM: Main TILER driver implementation.

2010-07-23 Thread David Sin
From: Lajos Molnar mol...@ti.com

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.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 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

diff --git a/drivers/media/video/tiler/Kconfig 
b/drivers/media/video/tiler/Kconfig
new file mode 100644
index 000..2c61471
--- /dev/null
+++ b/drivers/media/video/tiler/Kconfig
@@ -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.
diff --git a/drivers/media/video/tiler/Makefile 
b/drivers/media/video/tiler/Makefile
new file mode 100644
index 000..4a6495e
--- /dev/null
+++ b/drivers/media/video/tiler/Makefile
@@ -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
diff --git a/drivers/media/video/tiler/tiler-iface.c 
b/drivers/media/video/tiler/tiler-iface.c
new file mode 100644
index 000..0b10fae
--- /dev/null
+++ b/drivers/media/video/tiler/tiler-iface.c
@@ -0,0 +1,106 @@
+/*
+ * tiler-iface.c
+ *
+ * TILER driver interace functions for TI TILER hardware block.
+ *
+ * Authors: Lajos Molnar mol...@ti.com
+ *  David Sin david...@ti.com
+ *
+ * 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/module.h
+#include linux/slab.h/* kmalloc */
+#include linux/mm.h
+#include linux/mm_types.h
+#include asm/mach/map.h  /* for ioremap_page */
+
+#include _tiler.h
+
+/*
+ *  Memory-Map Kernel

[RFC 8/8] TILER-DMM: Linking TILER driver into the Linux kernel build

2010-07-23 Thread David Sin
From: Lajos Molnar mol...@ti.com

This patch links the TILER driver into the Linux kernel build
and config system.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 drivers/media/Kconfig  |6 ++
 drivers/media/Makefile |2 ++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index a28541b..96ebc1d 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -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
 
diff --git a/drivers/media/Makefile b/drivers/media/Makefile
index 499b081..922d71c 100644
--- a/drivers/media/Makefile
+++ b/drivers/media/Makefile
@@ -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/
-- 
1.6.3.3

--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC 1/8] TILER-DMM: DMM-PAT driver for TI TILER

2010-07-23 Thread David Sin
This patch adds support for DMM-PAT initialization and programming.

Signed-off-by: David Sin david...@ti.com
Signed-off-by: Lajos Molnar mol...@ti.com
---
 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

diff --git a/arch/arm/mach-omap2/include/mach/dmm.h 
b/arch/arm/mach-omap2/include/mach/dmm.h
new file mode 100644
index 000..68b798a
--- /dev/null
+++ b/arch/arm/mach-omap2/include/mach/dmm.h
@@ -0,0 +1,128 @@
+/*
+ * dmm.h
+ *
+ * DMM driver support functions for TI DMM-TILER hardware block.
+ *
+ * Author: David Sin david...@ti.com
+ *
+ * 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 0x4E00
+#define DMM_SIZE 0x800
+
+#define DMM_REVISION  0x000
+#define DMM_HWINFO0x004
+#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_HWINFO0x408
+#define DMM_PAT_GEOMETRY  0x40C
+#define DMM_PAT_CONFIG0x410
+#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_HWINFO0x608
+#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 idPAT 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 dmmDevice data
+ * @return an error status.
+ */
+void dmm_pat_release(struct dmm *dmm);
+
+#endif
diff --git a/drivers/media/video/tiler/dmm.c b/drivers/media/video/tiler/dmm.c
new file mode 100644
index 000..e715936
--- /dev/null
+++ b/drivers/media/video/tiler/dmm.c
@@ -0,0 +1,200 @@
+/*
+ * dmm.c
+ *
+ * DMM driver support functions for TI OMAP processors.
+ *
+ * Authors: David Sin david...@ti.com
+ *  Lajos Molnar mol...@ti.com
+ *
+ * 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

[RFC 3/8] TILER-DMM: Sample TCM implementation: Simple TILER Allocator

2010-07-23 Thread David Sin
From: Ravi Ramachandra r.ramachan...@ti.com

This patch implements a simple TILER Container Manager.

Signed-off-by: Ravi Ramachandra r.ramachan...@ti.com
Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 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

diff --git a/drivers/media/video/tiler/tcm/Makefile 
b/drivers/media/video/tiler/tcm/Makefile
new file mode 100644
index 000..8434607
--- /dev/null
+++ b/drivers/media/video/tiler/tcm/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_TI_TILER) += tcm-sita.o
diff --git a/drivers/media/video/tiler/tcm/_tcm-sita.h 
b/drivers/media/video/tiler/tcm/_tcm-sita.h
new file mode 100644
index 000..4ede1ab
--- /dev/null
+++ b/drivers/media/video/tiler/tcm/_tcm-sita.h
@@ -0,0 +1,64 @@
+/*
+ * _tcm_sita.h
+ *
+ * SImple Tiler Allocator (SiTA) private structures.
+ *
+ * Author: Ravi Ramachandra r.ramachan...@ti.com
+ *
+ * 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
+
+/* length between two coordinates */
+#define LEN(a, b) ((a)  (b) ? (a) - (b) + 1 : (b) - (a) + 1)
+
+enum criteria {
+   CR_MAX_NEIGHS   = 0x01,
+   CR_FIRST_FOUND  = 0x10,
+   CR_BIAS_HORIZONTAL  = 0x20,
+   CR_BIAS_VERTICAL= 0x40,
+   CR_DIAGONAL_BALANCE = 0x80
+};
+
+/* nearness to the beginning of the search field from 0 to 1000 */
+struct nearness_factor {
+   s32 x;
+   s32 y;
+};
+
+/*
+ * Statistics on immediately neighboring slots.  Edge is the number of
+ * border segments that are also border segments of the scan field.  Busy
+ * refers to the number of neighbors that are occupied.
+ */
+struct neighbor_stats {
+   u16 edge;
+   u16 busy;
+};
+
+/* structure to keep the score of a potential allocation */
+struct score {
+   struct nearness_factor  f;
+   struct neighbor_stats   n;
+   struct tcm_area a;
+   u16neighs;  /* number of busy neighbors */
+};
+
+struct sita_pvt {
+   struct mutex mtx;
+   struct tcm_area ***map; /* pointers to the parent area for each slot */
+};
+
+#endif
diff --git a/drivers/media/video/tiler/tcm/tcm-sita.c 
b/drivers/media/video/tiler/tcm/tcm-sita.c
new file mode 100644
index 000..93be3e6
--- /dev/null
+++ b/drivers/media/video/tiler/tcm/tcm-sita.c
@@ -0,0 +1,459 @@
+/*
+ * tcm-sita.c
+ *
+ * SImple Tiler Allocator (SiTA): 2D and 1D allocation(reservation) algorithm
+ *
+ * Authors: Ravi Ramachandra r.ramachan...@ti.com,
+ *  Lajos Molnar mol...@ti.com
+ *
+ * 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/slab.h
+
+#include _tcm-sita.h
+#include tcm-sita.h
+
+#define TCM_ALG_NAME tcm_sita
+#include tcm-utils.h
+
+#define ALIGN_DOWN(value, align) ((value)  ~((align) - 1))
+
+/* Individual selection criteria for different scan areas */
+static s32 CR_L2R_T2B = CR_BIAS_HORIZONTAL;
+
+/*
+ * TCM API - Sita Implementation
+ */
+static s32 sita_reserve_2d(struct tcm *tcm, u16 h, u16 w, u8 align,
+  struct tcm_area *area);
+static s32 sita_free(struct tcm *tcm, struct tcm_area *area);
+static void sita_deinit(struct tcm *tcm);
+
+/*
+ * Main Scanner functions
+ */
+static s32 scan_areas_and_find_fit(struct tcm *tcm, u16 w, u16 h, u16 align,
+  struct tcm_area *area);
+
+static s32 scan_l2r_t2b(struct tcm *tcm, u16 w, u16 h, u16 align,
+   struct tcm_area *field, struct tcm_area *area

[RFC 4/8] TILER-DMM: TILER Memory Manager interface and implementation

2010-07-23 Thread David Sin
From: Lajos Molnar mol...@ti.com

This patch defines the TILER Memory Manager (TMM) interface and
provides implementation for a PAT-supporting TMM.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 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

diff --git a/drivers/media/video/tiler/tmm-pat.c 
b/drivers/media/video/tiler/tmm-pat.c
new file mode 100644
index 000..ccd32b4
--- /dev/null
+++ b/drivers/media/video/tiler/tmm-pat.c
@@ -0,0 +1,274 @@
+/*
+ * tmm-pat.c
+ *
+ * DMM driver support functions for TI TILER hardware block.
+ *
+ * Authors: Lajos Molnar mol...@ti.com
+ *  David Sin david...@ti.com
+ *
+ * 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
+ *  areless 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

[RFC 2/8] TILER-DMM: Container manager interface and utility definitons

2010-07-23 Thread David Sin
From: Lajos Molnar mol...@ti.com

This patch defined the TILER Container Manager (TCM) interface and
provides utility methods for implementing a TCM.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
Signed-off-by: Ravi Ramachandra r.ramachan...@ti.com
---
 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

diff --git a/drivers/media/video/tiler/tcm.h b/drivers/media/video/tiler/tcm.h
new file mode 100644
index 000..52a022a
--- /dev/null
+++ b/drivers/media/video/tiler/tcm.h
@@ -0,0 +1,209 @@
+/*
+ * tcm.h
+ *
+ * TILER container manager specification and support functions for TI
+ * TILER driver.
+ *
+ * Author: Lajos Molnar mol...@ti.com
+ *
+ * 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 widthWidth 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 widthWidth(in pages) of area to be reserved.
+ * @param alignAlignment 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

[RFC 5/8] TILER-DMM: TILER interface file and documentation

2010-07-23 Thread David Sin
From: Lajos Molnar mol...@ti.com

This patch contains the TILER interface file and the documentation.

Signed-off-by: Lajos Molnar mol...@ti.com
Signed-off-by: David Sin david...@ti.com
---
 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

diff --git a/Documentation/arm/TILER b/Documentation/arm/TILER
new file mode 100644
index 000..9c54037
--- /dev/null
+++ b/Documentation/arm/TILER
@@ -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