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
0023  */
0024 #include "nv50.h"
0025 
0026 #include <subdev/bios.h>
0027 #include <subdev/bios/bit.h>
0028 #include <subdev/bios/pmu.h>
0029 #include <subdev/timer.h>
0030 
0031 static void
0032 pmu_code(struct nv50_devinit *init, u32 pmu, u32 img, u32 len, bool sec)
0033 {
0034     struct nvkm_device *device = init->base.subdev.device;
0035     struct nvkm_bios *bios = device->bios;
0036     int i;
0037 
0038     nvkm_wr32(device, 0x10a180, 0x01000000 | (sec ? 0x10000000 : 0) | pmu);
0039     for (i = 0; i < len; i += 4) {
0040         if ((i & 0xff) == 0)
0041             nvkm_wr32(device, 0x10a188, (pmu + i) >> 8);
0042         nvkm_wr32(device, 0x10a184, nvbios_rd32(bios, img + i));
0043     }
0044 
0045     while (i & 0xff) {
0046         nvkm_wr32(device, 0x10a184, 0x00000000);
0047         i += 4;
0048     }
0049 }
0050 
0051 static void
0052 pmu_data(struct nv50_devinit *init, u32 pmu, u32 img, u32 len)
0053 {
0054     struct nvkm_device *device = init->base.subdev.device;
0055     struct nvkm_bios *bios = device->bios;
0056     int i;
0057 
0058     nvkm_wr32(device, 0x10a1c0, 0x01000000 | pmu);
0059     for (i = 0; i < len; i += 4)
0060         nvkm_wr32(device, 0x10a1c4, nvbios_rd32(bios, img + i));
0061 }
0062 
0063 static u32
0064 pmu_args(struct nv50_devinit *init, u32 argp, u32 argi)
0065 {
0066     struct nvkm_device *device = init->base.subdev.device;
0067     nvkm_wr32(device, 0x10a1c0, argp);
0068     nvkm_wr32(device, 0x10a1c0, nvkm_rd32(device, 0x10a1c4) + argi);
0069     return nvkm_rd32(device, 0x10a1c4);
0070 }
0071 
0072 static void
0073 pmu_exec(struct nv50_devinit *init, u32 init_addr)
0074 {
0075     struct nvkm_device *device = init->base.subdev.device;
0076     nvkm_wr32(device, 0x10a104, init_addr);
0077     nvkm_wr32(device, 0x10a10c, 0x00000000);
0078     nvkm_wr32(device, 0x10a100, 0x00000002);
0079 }
0080 
0081 static int
0082 pmu_load(struct nv50_devinit *init, u8 type, bool post,
0083      u32 *init_addr_pmu, u32 *args_addr_pmu)
0084 {
0085     struct nvkm_subdev *subdev = &init->base.subdev;
0086     struct nvkm_bios *bios = subdev->device->bios;
0087     struct nvbios_pmuR pmu;
0088 
0089     if (!nvbios_pmuRm(bios, type, &pmu))
0090         return -EINVAL;
0091 
0092     if (!post)
0093         return 0;
0094 
0095     pmu_code(init, pmu.boot_addr_pmu, pmu.boot_addr, pmu.boot_size, false);
0096     pmu_code(init, pmu.code_addr_pmu, pmu.code_addr, pmu.code_size, true);
0097     pmu_data(init, pmu.data_addr_pmu, pmu.data_addr, pmu.data_size);
0098 
0099     if (init_addr_pmu) {
0100         *init_addr_pmu = pmu.init_addr_pmu;
0101         *args_addr_pmu = pmu.args_addr_pmu;
0102         return 0;
0103     }
0104 
0105     return pmu_exec(init, pmu.init_addr_pmu), 0;
0106 }
0107 
0108 void
0109 gm200_devinit_preos(struct nv50_devinit *init, bool post)
0110 {
0111     /* Optional: Execute PRE_OS application on PMU, which should at
0112      * least take care of fans until a full PMU has been loaded.
0113      */
0114     pmu_load(init, 0x01, post, NULL, NULL);
0115 }
0116 
0117 int
0118 gm200_devinit_post(struct nvkm_devinit *base, bool post)
0119 {
0120     struct nv50_devinit *init = nv50_devinit(base);
0121     struct nvkm_subdev *subdev = &init->base.subdev;
0122     struct nvkm_device *device = subdev->device;
0123     struct nvkm_bios *bios = device->bios;
0124     struct bit_entry bit_I;
0125     u32 exec, args;
0126     int ret;
0127 
0128     if (bit_entry(bios, 'I', &bit_I) || bit_I.version != 1 ||
0129                         bit_I.length < 0x1c) {
0130         nvkm_error(subdev, "VBIOS PMU init data not found\n");
0131         return -EINVAL;
0132     }
0133 
0134     /* Upload DEVINIT application from VBIOS onto PMU. */
0135     ret = pmu_load(init, 0x04, post, &exec, &args);
0136     if (ret) {
0137         nvkm_error(subdev, "VBIOS PMU/DEVINIT not found\n");
0138         return ret;
0139     }
0140 
0141     /* Upload tables required by opcodes in boot scripts. */
0142     if (post) {
0143         u32 pmu = pmu_args(init, args + 0x08, 0x08);
0144         u32 img = nvbios_rd16(bios, bit_I.offset + 0x14);
0145         u32 len = nvbios_rd16(bios, bit_I.offset + 0x16);
0146         pmu_data(init, pmu, img, len);
0147     }
0148 
0149     /* Upload boot scripts. */
0150     if (post) {
0151         u32 pmu = pmu_args(init, args + 0x08, 0x10);
0152         u32 img = nvbios_rd16(bios, bit_I.offset + 0x18);
0153         u32 len = nvbios_rd16(bios, bit_I.offset + 0x1a);
0154         pmu_data(init, pmu, img, len);
0155     }
0156 
0157     /* Execute DEVINIT. */
0158     if (post) {
0159         nvkm_wr32(device, 0x10a040, 0x00005000);
0160         pmu_exec(init, exec);
0161         if (nvkm_msec(device, 2000,
0162             if (nvkm_rd32(device, 0x10a040) & 0x00002000)
0163                 break;
0164         ) < 0)
0165             return -ETIMEDOUT;
0166     }
0167 
0168     gm200_devinit_preos(init, post);
0169     return 0;
0170 }
0171 
0172 static const struct nvkm_devinit_func
0173 gm200_devinit = {
0174     .preinit = gf100_devinit_preinit,
0175     .init = nv50_devinit_init,
0176     .post = gm200_devinit_post,
0177     .pll_set = gf100_devinit_pll_set,
0178     .disable = gm107_devinit_disable,
0179 };
0180 
0181 int
0182 gm200_devinit_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
0183           struct nvkm_devinit **pinit)
0184 {
0185     return nv50_devinit_new_(&gm200_devinit, device, type, inst, pinit);
0186 }