Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2013 Red Hat Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: Ben Skeggs <bskeggs@redhat.com>
0023  */
0024 #include <subdev/bios.h>
0025 #include <subdev/bios/bit.h>
0026 #include <subdev/bios/ramcfg.h>
0027 #include <subdev/bios/M0203.h>
0028 
0029 static u8
0030 nvbios_ramcfg_strap(struct nvkm_subdev *subdev)
0031 {
0032     return (nvkm_rd32(subdev->device, 0x101000) & 0x0000003c) >> 2;
0033 }
0034 
0035 u8
0036 nvbios_ramcfg_count(struct nvkm_bios *bios)
0037 {
0038     struct bit_entry bit_M;
0039 
0040     if (!bit_entry(bios, 'M', &bit_M)) {
0041         if (bit_M.version == 1 && bit_M.length >= 5)
0042             return nvbios_rd08(bios, bit_M.offset + 2);
0043         if (bit_M.version == 2 && bit_M.length >= 3)
0044             return nvbios_rd08(bios, bit_M.offset + 0);
0045     }
0046 
0047     return 0x00;
0048 }
0049 
0050 u8
0051 nvbios_ramcfg_index(struct nvkm_subdev *subdev)
0052 {
0053     struct nvkm_bios *bios = subdev->device->bios;
0054     u8 strap = nvbios_ramcfg_strap(subdev);
0055     u32 xlat = 0x00000000;
0056     struct bit_entry bit_M;
0057     struct nvbios_M0203E M0203E;
0058     u8 ver, hdr;
0059 
0060     if (!bit_entry(bios, 'M', &bit_M)) {
0061         if (bit_M.version == 1 && bit_M.length >= 5)
0062             xlat = nvbios_rd16(bios, bit_M.offset + 3);
0063         if (bit_M.version == 2 && bit_M.length >= 3) {
0064             /*XXX: is M ever shorter than this?
0065              *     if not - what is xlat used for now?
0066              *     also - sigh..
0067              */
0068             if (bit_M.length >= 7 &&
0069                 nvbios_M0203Em(bios, strap, &ver, &hdr, &M0203E))
0070                 return M0203E.group;
0071             xlat = nvbios_rd16(bios, bit_M.offset + 1);
0072         }
0073     }
0074 
0075     if (xlat)
0076         strap = nvbios_rd08(bios, xlat + strap);
0077     return strap;
0078 }