Commit | Line | Data |
---|---|---|
8bded189 FJ |
1 | /* |
2 | * Copyright (C) 2010 Francisco Jerez. | |
3 | * All Rights Reserved. | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining | |
6 | * a copy of this software and associated documentation files (the | |
7 | * "Software"), to deal in the Software without restriction, including | |
8 | * without limitation the rights to use, copy, modify, merge, publish, | |
9 | * distribute, sublicense, and/or sell copies of the Software, and to | |
10 | * permit persons to whom the Software is furnished to do so, subject to | |
11 | * the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice (including the | |
14 | * next paragraph) shall be included in all copies or substantial | |
15 | * portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
20 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE | |
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
24 | * | |
25 | */ | |
26 | ||
760285e7 | 27 | #include <drm/drmP.h> |
8bded189 | 28 | #include "nouveau_drv.h" |
760285e7 | 29 | #include <drm/nouveau_drm.h> |
8bded189 | 30 | |
a5cf68b0 FJ |
31 | void |
32 | nv30_fb_init_tile_region(struct drm_device *dev, int i, uint32_t addr, | |
33 | uint32_t size, uint32_t pitch, uint32_t flags) | |
34 | { | |
35 | struct drm_nouveau_private *dev_priv = dev->dev_private; | |
36 | struct nouveau_tile_reg *tile = &dev_priv->tile.reg[i]; | |
37 | ||
38 | tile->addr = addr | 1; | |
39 | tile->limit = max(1u, addr + size) - 1; | |
40 | tile->pitch = pitch; | |
41 | } | |
42 | ||
43 | void | |
44 | nv30_fb_free_tile_region(struct drm_device *dev, int i) | |
45 | { | |
46 | struct drm_nouveau_private *dev_priv = dev->dev_private; | |
47 | struct nouveau_tile_reg *tile = &dev_priv->tile.reg[i]; | |
48 | ||
49 | tile->addr = tile->limit = tile->pitch = 0; | |
50 | } | |
51 | ||
8bded189 | 52 | static int |
4d1defd7 FJ |
53 | calc_bias(struct drm_device *dev, int k, int i, int j) |
54 | { | |
55 | struct drm_nouveau_private *dev_priv = dev->dev_private; | |
56 | int b = (dev_priv->chipset > 0x30 ? | |
57 | nv_rd32(dev, 0x122c + 0x10 * k + 0x4 * j) >> (4 * (i ^ 1)) : | |
58 | 0) & 0xf; | |
59 | ||
60 | return 2 * (b & 0x8 ? b - 0x10 : b); | |
61 | } | |
62 | ||
63 | static int | |
64 | calc_ref(struct drm_device *dev, int l, int k, int i) | |
8bded189 FJ |
65 | { |
66 | int j, x = 0; | |
67 | ||
68 | for (j = 0; j < 4; j++) { | |
4d1defd7 | 69 | int m = (l >> (8 * i) & 0xff) + calc_bias(dev, k, i, j); |
8bded189 | 70 | |
4d1defd7 | 71 | x |= (0x80 | clamp(m, 0, 0x1f)) << (8 * j); |
8bded189 FJ |
72 | } |
73 | ||
74 | return x; | |
75 | } | |
76 | ||
77 | int | |
78 | nv30_fb_init(struct drm_device *dev) | |
79 | { | |
80 | struct drm_nouveau_private *dev_priv = dev->dev_private; | |
81 | struct nouveau_fb_engine *pfb = &dev_priv->engine.fb; | |
82 | int i, j; | |
83 | ||
84 | pfb->num_tiles = NV10_PFB_TILE__SIZE; | |
85 | ||
86 | /* Turn all the tiling regions off. */ | |
87 | for (i = 0; i < pfb->num_tiles; i++) | |
a5cf68b0 | 88 | pfb->set_tile_region(dev, i); |
8bded189 FJ |
89 | |
90 | /* Init the memory timing regs at 0x10037c/0x1003ac */ | |
91 | if (dev_priv->chipset == 0x30 || | |
92 | dev_priv->chipset == 0x31 || | |
93 | dev_priv->chipset == 0x35) { | |
94 | /* Related to ROP count */ | |
95 | int n = (dev_priv->chipset == 0x31 ? 2 : 4); | |
8bded189 FJ |
96 | int l = nv_rd32(dev, 0x1003d0); |
97 | ||
98 | for (i = 0; i < n; i++) { | |
99 | for (j = 0; j < 3; j++) | |
100 | nv_wr32(dev, 0x10037c + 0xc * i + 0x4 * j, | |
4d1defd7 | 101 | calc_ref(dev, l, 0, j)); |
8bded189 FJ |
102 | |
103 | for (j = 0; j < 2; j++) | |
104 | nv_wr32(dev, 0x1003ac + 0x8 * i + 0x4 * j, | |
4d1defd7 | 105 | calc_ref(dev, l, 1, j)); |
8bded189 FJ |
106 | } |
107 | } | |
108 | ||
109 | return 0; | |
110 | } | |
111 | ||
112 | void | |
113 | nv30_fb_takedown(struct drm_device *dev) | |
114 | { | |
115 | } |