2 * Copyright 2013 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
25 #include <subdev/bios.h>
30 nv50_ram_put(struct nouveau_fb
*pfb
, struct nouveau_mem
**pmem
)
32 struct nouveau_mm_node
*this;
33 struct nouveau_mem
*mem
;
37 if (unlikely(mem
== NULL
))
40 mutex_lock(&pfb
->base
.mutex
);
41 while (!list_empty(&mem
->regions
)) {
42 this = list_first_entry(&mem
->regions
, typeof(*this), rl_entry
);
44 list_del(&this->rl_entry
);
45 nouveau_mm_free(&pfb
->vram
, &this);
48 nouveau_mm_free(&pfb
->tags
, &mem
->tag
);
49 mutex_unlock(&pfb
->base
.mutex
);
55 nv50_ram_get(struct nouveau_fb
*pfb
, u64 size
, u32 align
, u32 ncmin
,
56 u32 memtype
, struct nouveau_mem
**pmem
)
58 struct nouveau_mm
*heap
= &pfb
->vram
;
59 struct nouveau_mm
*tags
= &pfb
->tags
;
60 struct nouveau_mm_node
*r
;
61 struct nouveau_mem
*mem
;
62 int comp
= (memtype
& 0x300) >> 8;
63 int type
= (memtype
& 0x07f);
64 int back
= (memtype
& 0x800);
68 min
= ncmin
? (ncmin
>> 12) : max
;
71 mem
= kzalloc(sizeof(*mem
), GFP_KERNEL
);
75 mutex_lock(&pfb
->base
.mutex
);
78 int n
= (max
>> 4) * comp
;
80 ret
= nouveau_mm_head(tags
, 1, n
, n
, 1, &mem
->tag
);
85 if (unlikely(!mem
->tag
))
89 INIT_LIST_HEAD(&mem
->regions
);
90 mem
->memtype
= (comp
<< 7) | type
;
93 type
= nv50_fb_memtype
[type
];
96 ret
= nouveau_mm_tail(heap
, type
, max
, min
, align
, &r
);
98 ret
= nouveau_mm_head(heap
, type
, max
, min
, align
, &r
);
100 mutex_unlock(&pfb
->base
.mutex
);
101 pfb
->ram
->put(pfb
, &mem
);
105 list_add_tail(&r
->rl_entry
, &mem
->regions
);
108 mutex_unlock(&pfb
->base
.mutex
);
110 r
= list_first_entry(&mem
->regions
, struct nouveau_mm_node
, rl_entry
);
111 mem
->offset
= (u64
)r
->offset
<< 12;
117 nv50_fb_vram_rblock(struct nouveau_fb
*pfb
, struct nouveau_ram
*ram
)
119 int i
, parts
, colbits
, rowbitsa
, rowbitsb
, banks
;
120 u64 rowsize
, predicted
;
121 u32 r0
, r4
, rt
, ru
, rblock_size
;
123 r0
= nv_rd32(pfb
, 0x100200);
124 r4
= nv_rd32(pfb
, 0x100204);
125 rt
= nv_rd32(pfb
, 0x100250);
126 ru
= nv_rd32(pfb
, 0x001540);
127 nv_debug(pfb
, "memcfg 0x%08x 0x%08x 0x%08x 0x%08x\n", r0
, r4
, rt
, ru
);
129 for (i
= 0, parts
= 0; i
< 8; i
++) {
130 if (ru
& (0x00010000 << i
))
134 colbits
= (r4
& 0x0000f000) >> 12;
135 rowbitsa
= ((r4
& 0x000f0000) >> 16) + 8;
136 rowbitsb
= ((r4
& 0x00f00000) >> 20) + 8;
137 banks
= 1 << (((r4
& 0x03000000) >> 24) + 2);
139 rowsize
= parts
* banks
* (1 << colbits
) * 8;
140 predicted
= rowsize
<< rowbitsa
;
142 predicted
+= rowsize
<< rowbitsb
;
144 if (predicted
!= ram
->size
) {
145 nv_warn(pfb
, "memory controller reports %d MiB VRAM\n",
146 (u32
)(ram
->size
>> 20));
149 rblock_size
= rowsize
;
153 nv_debug(pfb
, "rblock %d bytes\n", rblock_size
);
158 nv50_ram_create(struct nouveau_object
*parent
, struct nouveau_object
*engine
,
159 struct nouveau_oclass
*oclass
, void *data
, u32 datasize
,
160 struct nouveau_object
**pobject
)
162 struct nouveau_fb
*pfb
= nouveau_fb(parent
);
163 struct nouveau_device
*device
= nv_device(pfb
);
164 struct nouveau_bios
*bios
= nouveau_bios(device
);
165 struct nouveau_ram
*ram
;
166 const u32 rsvd_head
= ( 256 * 1024) >> 12; /* vga memory */
167 const u32 rsvd_tail
= (1024 * 1024) >> 12; /* vbios etc */
171 ret
= nouveau_ram_create(parent
, engine
, oclass
, &ram
);
172 *pobject
= nv_object(ram
);
176 ram
->size
= nv_rd32(pfb
, 0x10020c);
177 ram
->size
= (ram
->size
& 0xffffff00) |
178 ((ram
->size
& 0x000000ff) << 32);
180 size
= (ram
->size
>> 12) - rsvd_head
- rsvd_tail
;
181 switch (device
->chipset
) {
184 case 0xaf: /* IGPs, no reordering, no real VRAM */
185 ret
= nouveau_mm_init(&pfb
->vram
, rsvd_head
, size
, 1);
189 ram
->type
= NV_MEM_TYPE_STOLEN
;
190 ram
->stolen
= (u64
)nv_rd32(pfb
, 0x100e10) << 12;
193 switch (nv_rd32(pfb
, 0x100714) & 0x00000007) {
194 case 0: ram
->type
= NV_MEM_TYPE_DDR1
; break;
196 if (nouveau_fb_bios_memtype(bios
) == NV_MEM_TYPE_DDR3
)
197 ram
->type
= NV_MEM_TYPE_DDR3
;
199 ram
->type
= NV_MEM_TYPE_DDR2
;
201 case 2: ram
->type
= NV_MEM_TYPE_GDDR3
; break;
202 case 3: ram
->type
= NV_MEM_TYPE_GDDR4
; break;
203 case 4: ram
->type
= NV_MEM_TYPE_GDDR5
; break;
208 ret
= nouveau_mm_init(&pfb
->vram
, rsvd_head
, size
,
209 nv50_fb_vram_rblock(pfb
, ram
) >> 12);
213 ram
->ranks
= (nv_rd32(pfb
, 0x100200) & 0x4) ? 2 : 1;
214 ram
->tags
= nv_rd32(pfb
, 0x100320);
218 ram
->get
= nv50_ram_get
;
219 ram
->put
= nv50_ram_put
;
223 struct nouveau_oclass
226 .ofuncs
= &(struct nouveau_ofuncs
) {
227 .ctor
= nv50_ram_create
,
228 .dtor
= _nouveau_ram_dtor
,
229 .init
= _nouveau_ram_init
,
230 .fini
= _nouveau_ram_fini
,
This page took 0.040574 seconds and 5 git commands to generate.