GNU Linux-libre 4.19.245-gnu1
[releases.git] / drivers / gpu / drm / omapdrm / tcm-sita.h
1 /*
2  * SImple Tiler Allocator (SiTA) private structures.
3  *
4  * Copyright (C) 2009-2011 Texas Instruments Incorporated - http://www.ti.com/
5  * Author: Ravi Ramachandra <r.ramachandra@ti.com>
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  *   notice, this list of conditions and the following disclaimer.
15  *
16  * * Redistributions in binary form must reproduce the above copyright
17  *   notice, this list of conditions and the following disclaimer in the
18  *   documentation and/or other materials provided with the distribution.
19  *
20  * * Neither the name of Texas Instruments Incorporated nor the names of
21  *   its contributors may be used to endorse or promote products derived
22  *   from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
34  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  */
36
37 #ifndef _TCM_SITA_H
38 #define _TCM_SITA_H
39
40 #include "tcm.h"
41
42 /* length between two coordinates */
43 #define LEN(a, b) ((a) > (b) ? (a) - (b) + 1 : (b) - (a) + 1)
44
45 enum criteria {
46         CR_MAX_NEIGHS           = 0x01,
47         CR_FIRST_FOUND          = 0x10,
48         CR_BIAS_HORIZONTAL      = 0x20,
49         CR_BIAS_VERTICAL        = 0x40,
50         CR_DIAGONAL_BALANCE     = 0x80
51 };
52
53 /* nearness to the beginning of the search field from 0 to 1000 */
54 struct nearness_factor {
55         s32 x;
56         s32 y;
57 };
58
59 /*
60  * Statistics on immediately neighboring slots.  Edge is the number of
61  * border segments that are also border segments of the scan field.  Busy
62  * refers to the number of neighbors that are occupied.
63  */
64 struct neighbor_stats {
65         u16 edge;
66         u16 busy;
67 };
68
69 /* structure to keep the score of a potential allocation */
70 struct score {
71         struct nearness_factor  f;
72         struct neighbor_stats   n;
73         struct tcm_area         a;
74         u16    neighs;          /* number of busy neighbors */
75 };
76
77 struct sita_pvt {
78         spinlock_t lock;        /* spinlock to protect access */
79         struct tcm_pt div_pt;   /* divider point splitting container */
80         struct tcm_area ***map; /* pointers to the parent area for each slot */
81 };
82
83 /* assign coordinates to area */
84 static inline
85 void assign(struct tcm_area *a, u16 x0, u16 y0, u16 x1, u16 y1)
86 {
87         a->p0.x = x0;
88         a->p0.y = y0;
89         a->p1.x = x1;
90         a->p1.y = y1;
91 }
92
93 #endif