Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
base.c
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Red Hat Inc.
3  *
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:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
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.
21  *
22  * Authors: Ben Skeggs
23  */
24 
25 #include "subdev/fb.h"
26 #include "subdev/bios.h"
27 #include "subdev/bios/bit.h"
28 
29 int
31 {
32  struct bit_entry M;
33  u8 ramcfg;
34 
35  ramcfg = (nv_rd32(bios, 0x101000) & 0x0000003c) >> 2;
36  if (!bit_entry(bios, 'M', &M) && M.version == 2 && M.length >= 5) {
37  u16 table = nv_ro16(bios, M.offset + 3);
38  u8 version = nv_ro08(bios, table + 0);
39  u8 header = nv_ro08(bios, table + 1);
40  u8 record = nv_ro08(bios, table + 2);
41  u8 entries = nv_ro08(bios, table + 3);
42  if (table && version == 0x10 && ramcfg < entries) {
43  u16 entry = table + header + (ramcfg * record);
44  switch (nv_ro08(bios, entry) & 0x0f) {
45  case 0: return NV_MEM_TYPE_DDR2;
46  case 1: return NV_MEM_TYPE_DDR3;
47  case 2: return NV_MEM_TYPE_GDDR3;
48  case 3: return NV_MEM_TYPE_GDDR5;
49  default:
50  break;
51  }
52 
53  }
54  }
55 
56  return NV_MEM_TYPE_UNKNOWN;
57 }
58 
59 int
61 {
62  int ret, i;
63 
64  ret = nouveau_subdev_init(&pfb->base);
65  if (ret)
66  return ret;
67 
68  for (i = 0; i < pfb->tile.regions; i++)
69  pfb->tile.prog(pfb, i, &pfb->tile.region[i]);
70 
71  return 0;
72 }
73 
74 int
76 {
77  struct nouveau_fb *pfb = (void *)object;
78  return nouveau_fb_init(pfb);
79 }
80 
81 void
83 {
84  int i;
85 
86  for (i = 0; i < pfb->tile.regions; i++)
87  pfb->tile.fini(pfb, i, &pfb->tile.region[i]);
88 
89  if (pfb->tags.block_size)
90  nouveau_mm_fini(&pfb->tags);
91 
92  if (pfb->vram.block_size)
93  nouveau_mm_fini(&pfb->vram);
94 
96 }
97 
98 void
100 {
101  struct nouveau_fb *pfb = (void *)object;
102  nouveau_fb_destroy(pfb);
103 }
104 
105 int
107 {
108  static const char *name[] = {
109  [NV_MEM_TYPE_UNKNOWN] = "unknown",
110  [NV_MEM_TYPE_STOLEN ] = "stolen system memory",
111  [NV_MEM_TYPE_SGRAM ] = "SGRAM",
112  [NV_MEM_TYPE_SDRAM ] = "SDRAM",
113  [NV_MEM_TYPE_DDR1 ] = "DDR1",
114  [NV_MEM_TYPE_DDR2 ] = "DDR2",
115  [NV_MEM_TYPE_DDR3 ] = "DDR3",
116  [NV_MEM_TYPE_GDDR2 ] = "GDDR2",
117  [NV_MEM_TYPE_GDDR3 ] = "GDDR3",
118  [NV_MEM_TYPE_GDDR4 ] = "GDDR4",
119  [NV_MEM_TYPE_GDDR5 ] = "GDDR5",
120  };
121 
122  if (pfb->ram.size == 0) {
123  nv_fatal(pfb, "no vram detected!!\n");
124  return -ERANGE;
125  }
126 
127  nv_info(pfb, "RAM type: %s\n", name[pfb->ram.type]);
128  nv_info(pfb, "RAM size: %d MiB\n", (int)(pfb->ram.size >> 20));
129  return 0;
130 }