1/* $NetBSD: nouveau_subdev_fb_ramnv04.c,v 1.1.1.1 2014/08/06 12:36:30 riastradh Exp $ */
2
3/*
4 * Copyright 2013 Red Hat Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Ben Skeggs
25 */
26
27#include <sys/cdefs.h>
28__KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_fb_ramnv04.c,v 1.1.1.1 2014/08/06 12:36:30 riastradh Exp $");
29
30#define NV04_PFB_BOOT_0 0x00100000
31# define NV04_PFB_BOOT_0_RAM_AMOUNT 0x00000003
32# define NV04_PFB_BOOT_0_RAM_AMOUNT_32MB 0x00000000
33# define NV04_PFB_BOOT_0_RAM_AMOUNT_4MB 0x00000001
34# define NV04_PFB_BOOT_0_RAM_AMOUNT_8MB 0x00000002
35# define NV04_PFB_BOOT_0_RAM_AMOUNT_16MB 0x00000003
36# define NV04_PFB_BOOT_0_RAM_WIDTH_128 0x00000004
37# define NV04_PFB_BOOT_0_RAM_TYPE 0x00000028
38# define NV04_PFB_BOOT_0_RAM_TYPE_SGRAM_8MBIT 0x00000000
39# define NV04_PFB_BOOT_0_RAM_TYPE_SGRAM_16MBIT 0x00000008
40# define NV04_PFB_BOOT_0_RAM_TYPE_SGRAM_16MBIT_4BANK 0x00000010
41# define NV04_PFB_BOOT_0_RAM_TYPE_SDRAM_16MBIT 0x00000018
42# define NV04_PFB_BOOT_0_RAM_TYPE_SDRAM_64MBIT 0x00000020
43# define NV04_PFB_BOOT_0_RAM_TYPE_SDRAM_64MBITX16 0x00000028
44# define NV04_PFB_BOOT_0_UMA_ENABLE 0x00000100
45# define NV04_PFB_BOOT_0_UMA_SIZE 0x0000f000
46
47#include "priv.h"
48
49static int
50nv04_ram_create(struct nouveau_object *parent, struct nouveau_object *engine,
51 struct nouveau_oclass *oclass, void *data, u32 size,
52 struct nouveau_object **pobject)
53{
54 struct nouveau_fb *pfb = nouveau_fb(parent);
55 struct nouveau_ram *ram;
56 u32 boot0 = nv_rd32(pfb, NV04_PFB_BOOT_0);
57 int ret;
58
59 ret = nouveau_ram_create(parent, engine, oclass, &ram);
60 *pobject = nv_object(ram);
61 if (ret)
62 return ret;
63
64 if (boot0 & 0x00000100) {
65 ram->size = ((boot0 >> 12) & 0xf) * 2 + 2;
66 ram->size *= 1024 * 1024;
67 } else {
68 switch (boot0 & NV04_PFB_BOOT_0_RAM_AMOUNT) {
69 case NV04_PFB_BOOT_0_RAM_AMOUNT_32MB:
70 ram->size = 32 * 1024 * 1024;
71 break;
72 case NV04_PFB_BOOT_0_RAM_AMOUNT_16MB:
73 ram->size = 16 * 1024 * 1024;
74 break;
75 case NV04_PFB_BOOT_0_RAM_AMOUNT_8MB:
76 ram->size = 8 * 1024 * 1024;
77 break;
78 case NV04_PFB_BOOT_0_RAM_AMOUNT_4MB:
79 ram->size = 4 * 1024 * 1024;
80 break;
81 }
82 }
83
84 if ((boot0 & 0x00000038) <= 0x10)
85 ram->type = NV_MEM_TYPE_SGRAM;
86 else
87 ram->type = NV_MEM_TYPE_SDRAM;
88 return 0;
89}
90
91struct nouveau_oclass
92nv04_ram_oclass = {
93 .handle = 0,
94 .ofuncs = &(struct nouveau_ofuncs) {
95 .ctor = nv04_ram_create,
96 .dtor = _nouveau_ram_dtor,
97 .init = _nouveau_ram_init,
98 .fini = _nouveau_ram_fini,
99 }
100};
101