1 | /* $NetBSD: nouveau_subdev_devinit_nv10.c,v 1.1.1.1 2014/08/06 12:36:30 riastradh Exp $ */ |
2 | |
3 | /* |
4 | * Copyright (C) 2010 Francisco Jerez. |
5 | * All Rights Reserved. |
6 | * |
7 | * Permission is hereby granted, free of charge, to any person obtaining |
8 | * a copy of this software and associated documentation files (the |
9 | * "Software"), to deal in the Software without restriction, including |
10 | * without limitation the rights to use, copy, modify, merge, publish, |
11 | * distribute, sublicense, and/or sell copies of the Software, and to |
12 | * permit persons to whom the Software is furnished to do so, subject to |
13 | * the following conditions: |
14 | * |
15 | * The above copyright notice and this permission notice (including the |
16 | * next paragraph) shall be included in all copies or substantial |
17 | * portions of the Software. |
18 | * |
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
22 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE |
23 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
24 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
25 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
26 | * |
27 | */ |
28 | |
29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_devinit_nv10.c,v 1.1.1.1 2014/08/06 12:36:30 riastradh Exp $" ); |
31 | |
32 | #include <subdev/vga.h> |
33 | |
34 | #include "fbmem.h" |
35 | #include "nv04.h" |
36 | |
37 | static void |
38 | nv10_devinit_meminit(struct nouveau_devinit *devinit) |
39 | { |
40 | struct nv04_devinit_priv *priv = (void *)devinit; |
41 | static const int mem_width[] = { 0x10, 0x00, 0x20 }; |
42 | int mem_width_count; |
43 | uint32_t patt = 0xdeadbeef; |
44 | struct io_mapping *fb; |
45 | int i, j, k; |
46 | |
47 | if (nv_device(priv)->card_type >= NV_11 && |
48 | nv_device(priv)->chipset >= 0x17) |
49 | mem_width_count = 3; |
50 | else |
51 | mem_width_count = 2; |
52 | |
53 | /* Map the framebuffer aperture */ |
54 | fb = fbmem_init(nv_device(priv)); |
55 | if (!fb) { |
56 | nv_error(priv, "failed to map fb\n" ); |
57 | return; |
58 | } |
59 | |
60 | nv_wr32(priv, NV10_PFB_REFCTRL, NV10_PFB_REFCTRL_VALID_1); |
61 | |
62 | /* Probe memory bus width */ |
63 | for (i = 0; i < mem_width_count; i++) { |
64 | nv_mask(priv, NV04_PFB_CFG0, 0x30, mem_width[i]); |
65 | |
66 | for (j = 0; j < 4; j++) { |
67 | for (k = 0; k < 4; k++) |
68 | fbmem_poke(fb, 0x1c, 0); |
69 | |
70 | fbmem_poke(fb, 0x1c, patt); |
71 | fbmem_poke(fb, 0x3c, 0); |
72 | |
73 | if (fbmem_peek(fb, 0x1c) == patt) |
74 | goto mem_width_found; |
75 | } |
76 | } |
77 | |
78 | mem_width_found: |
79 | patt <<= 1; |
80 | |
81 | /* Probe amount of installed memory */ |
82 | for (i = 0; i < 4; i++) { |
83 | int off = nv_rd32(priv, 0x10020c) - 0x100000; |
84 | |
85 | fbmem_poke(fb, off, patt); |
86 | fbmem_poke(fb, 0, 0); |
87 | |
88 | fbmem_peek(fb, 0); |
89 | fbmem_peek(fb, 0); |
90 | fbmem_peek(fb, 0); |
91 | fbmem_peek(fb, 0); |
92 | |
93 | if (fbmem_peek(fb, off) == patt) |
94 | goto amount_found; |
95 | } |
96 | |
97 | /* IC missing - disable the upper half memory space. */ |
98 | nv_mask(priv, NV04_PFB_CFG0, 0x1000, 0); |
99 | |
100 | amount_found: |
101 | fbmem_fini(fb); |
102 | } |
103 | |
104 | struct nouveau_oclass * |
105 | nv10_devinit_oclass = &(struct nouveau_devinit_impl) { |
106 | .base.handle = NV_SUBDEV(DEVINIT, 0x10), |
107 | .base.ofuncs = &(struct nouveau_ofuncs) { |
108 | .ctor = nv04_devinit_ctor, |
109 | .dtor = nv04_devinit_dtor, |
110 | .init = nv04_devinit_init, |
111 | .fini = nv04_devinit_fini, |
112 | }, |
113 | .meminit = nv10_devinit_meminit, |
114 | .pll_set = nv04_devinit_pll_set, |
115 | }.base; |
116 | |