Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (C) 2010 Francisco Jerez.
0003  * All Rights Reserved.
0004  *
0005  * Permission is hereby granted, free of charge, to any person obtaining
0006  * a copy of this software and associated documentation files (the
0007  * "Software"), to deal in the Software without restriction, including
0008  * without limitation the rights to use, copy, modify, merge, publish,
0009  * distribute, sublicense, and/or sell copies of the Software, and to
0010  * permit persons to whom the Software is furnished to do so, subject to
0011  * the following conditions:
0012  *
0013  * The above copyright notice and this permission notice (including the
0014  * next paragraph) shall be included in all copies or substantial
0015  * portions of the Software.
0016  *
0017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0018  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
0020  * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
0021  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
0022  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
0023  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0024  *
0025  */
0026 #include "nv04.h"
0027 #include "fbmem.h"
0028 
0029 #include <subdev/bios.h>
0030 #include <subdev/bios/init.h>
0031 
0032 static void
0033 nv10_devinit_meminit(struct nvkm_devinit *init)
0034 {
0035     struct nvkm_subdev *subdev = &init->subdev;
0036     struct nvkm_device *device = subdev->device;
0037     static const int mem_width[] = { 0x10, 0x00, 0x20 };
0038     int mem_width_count;
0039     uint32_t patt = 0xdeadbeef;
0040     struct io_mapping *fb;
0041     int i, j, k;
0042 
0043     if (device->card_type >= NV_11 && device->chipset >= 0x17)
0044         mem_width_count = 3;
0045     else
0046         mem_width_count = 2;
0047 
0048     /* Map the framebuffer aperture */
0049     fb = fbmem_init(device);
0050     if (!fb) {
0051         nvkm_error(subdev, "failed to map fb\n");
0052         return;
0053     }
0054 
0055     nvkm_wr32(device, NV10_PFB_REFCTRL, NV10_PFB_REFCTRL_VALID_1);
0056 
0057     /* Probe memory bus width */
0058     for (i = 0; i < mem_width_count; i++) {
0059         nvkm_mask(device, NV04_PFB_CFG0, 0x30, mem_width[i]);
0060 
0061         for (j = 0; j < 4; j++) {
0062             for (k = 0; k < 4; k++)
0063                 fbmem_poke(fb, 0x1c, 0);
0064 
0065             fbmem_poke(fb, 0x1c, patt);
0066             fbmem_poke(fb, 0x3c, 0);
0067 
0068             if (fbmem_peek(fb, 0x1c) == patt)
0069                 goto mem_width_found;
0070         }
0071     }
0072 
0073 mem_width_found:
0074     patt <<= 1;
0075 
0076     /* Probe amount of installed memory */
0077     for (i = 0; i < 4; i++) {
0078         int off = nvkm_rd32(device, 0x10020c) - 0x100000;
0079 
0080         fbmem_poke(fb, off, patt);
0081         fbmem_poke(fb, 0, 0);
0082 
0083         fbmem_peek(fb, 0);
0084         fbmem_peek(fb, 0);
0085         fbmem_peek(fb, 0);
0086         fbmem_peek(fb, 0);
0087 
0088         if (fbmem_peek(fb, off) == patt)
0089             goto amount_found;
0090     }
0091 
0092     /* IC missing - disable the upper half memory space. */
0093     nvkm_mask(device, NV04_PFB_CFG0, 0x1000, 0);
0094 
0095 amount_found:
0096     fbmem_fini(fb);
0097 }
0098 
0099 static const struct nvkm_devinit_func
0100 nv10_devinit = {
0101     .dtor = nv04_devinit_dtor,
0102     .preinit = nv04_devinit_preinit,
0103     .post = nv04_devinit_post,
0104     .meminit = nv10_devinit_meminit,
0105     .pll_set = nv04_devinit_pll_set,
0106 };
0107 
0108 int
0109 nv10_devinit_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
0110          struct nvkm_devinit **pinit)
0111 {
0112     return nv04_devinit_new_(&nv10_devinit, device, type, inst, pinit);
0113 }