1 /* $NetBSD: nouveau_nvkm_subdev_devinit_nv10.c,v 1.3 2021/12/18 23:45:39 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 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_subdev_devinit_nv10.c,v 1.3 2021/12/18 23:45:39 riastradh Exp $");
30
31 #include "nv04.h"
32 #include "fbmem.h"
33
34 #include <subdev/bios.h>
35 #include <subdev/bios/init.h>
36
37 static void
nv10_devinit_meminit(struct nvkm_devinit * init)38 nv10_devinit_meminit(struct nvkm_devinit *init)
39 {
40 struct nvkm_subdev *subdev = &init->subdev;
41 struct nvkm_device *device = subdev->device;
42 static const int mem_width[] = { 0x10, 0x00, 0x20 };
43 int mem_width_count;
44 uint32_t patt = 0xdeadbeef;
45 struct io_mapping *fb;
46 int i, j, k;
47
48 if (device->card_type >= NV_11 && device->chipset >= 0x17)
49 mem_width_count = 3;
50 else
51 mem_width_count = 2;
52
53 /* Map the framebuffer aperture */
54 fb = fbmem_init(device);
55 if (!fb) {
56 nvkm_error(subdev, "failed to map fb\n");
57 return;
58 }
59
60 nvkm_wr32(device, NV10_PFB_REFCTRL, NV10_PFB_REFCTRL_VALID_1);
61
62 /* Probe memory bus width */
63 for (i = 0; i < mem_width_count; i++) {
64 nvkm_mask(device, 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 = nvkm_rd32(device, 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 nvkm_mask(device, NV04_PFB_CFG0, 0x1000, 0);
99
100 amount_found:
101 fbmem_fini(fb);
102 }
103
104 static const struct nvkm_devinit_func
105 nv10_devinit = {
106 .dtor = nv04_devinit_dtor,
107 .preinit = nv04_devinit_preinit,
108 .post = nv04_devinit_post,
109 .meminit = nv10_devinit_meminit,
110 .pll_set = nv04_devinit_pll_set,
111 };
112
113 int
nv10_devinit_new(struct nvkm_device * device,int index,struct nvkm_devinit ** pinit)114 nv10_devinit_new(struct nvkm_device *device, int index,
115 struct nvkm_devinit **pinit)
116 {
117 return nv04_devinit_new_(&nv10_devinit, device, index, pinit);
118 }
119