Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2014 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/image.h>
0027 #include <subdev/bios/pmu.h>
0028 
0029 u32
0030 nvbios_pmuTe(struct nvkm_bios *bios, u8 *ver, u8 *hdr, u8 *cnt, u8 *len)
0031 {
0032     struct bit_entry bit_p;
0033     u32 data = 0;
0034 
0035     if (!bit_entry(bios, 'p', &bit_p)) {
0036         if (bit_p.version == 2 && bit_p.length >= 4)
0037             data = nvbios_rd32(bios, bit_p.offset + 0x00);
0038         if (data) {
0039             *ver = nvbios_rd08(bios, data + 0x00); /* maybe? */
0040             *hdr = nvbios_rd08(bios, data + 0x01);
0041             *len = nvbios_rd08(bios, data + 0x02);
0042             *cnt = nvbios_rd08(bios, data + 0x03);
0043         }
0044     }
0045 
0046     return data;
0047 }
0048 
0049 u32
0050 nvbios_pmuEe(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr)
0051 {
0052     u8  cnt, len;
0053     u32 data = nvbios_pmuTe(bios, ver, hdr, &cnt, &len);
0054     if (data && idx < cnt) {
0055         data = data + *hdr + (idx * len);
0056         *hdr = len;
0057         return data;
0058     }
0059     return 0;
0060 }
0061 
0062 u32
0063 nvbios_pmuEp(struct nvkm_bios *bios, int idx, u8 *ver, u8 *hdr,
0064          struct nvbios_pmuE *info)
0065 {
0066     u32 data = nvbios_pmuEe(bios, idx, ver, hdr);
0067     memset(info, 0x00, sizeof(*info));
0068     switch (!!data * *ver) {
0069     default:
0070         info->type = nvbios_rd08(bios, data + 0x00);
0071         info->data = nvbios_rd32(bios, data + 0x02);
0072         break;
0073     }
0074     return data;
0075 }
0076 
0077 bool
0078 nvbios_pmuRm(struct nvkm_bios *bios, u8 type, struct nvbios_pmuR *info)
0079 {
0080     struct nvbios_pmuE pmuE;
0081     u8  ver, hdr, idx = 0;
0082     u32 data;
0083     memset(info, 0x00, sizeof(*info));
0084     while ((data = nvbios_pmuEp(bios, idx++, &ver, &hdr, &pmuE))) {
0085         if (pmuE.type == type && (data = pmuE.data)) {
0086             info->init_addr_pmu = nvbios_rd32(bios, data + 0x08);
0087             info->args_addr_pmu = nvbios_rd32(bios, data + 0x0c);
0088             info->boot_addr     = data + 0x30;
0089             info->boot_addr_pmu = nvbios_rd32(bios, data + 0x10) +
0090                           nvbios_rd32(bios, data + 0x18);
0091             info->boot_size     = nvbios_rd32(bios, data + 0x1c) -
0092                           nvbios_rd32(bios, data + 0x18);
0093             info->code_addr     = info->boot_addr + info->boot_size;
0094             info->code_addr_pmu = info->boot_addr_pmu +
0095                           info->boot_size;
0096             info->code_size     = nvbios_rd32(bios, data + 0x20);
0097             info->data_addr     = data + 0x30 +
0098                           nvbios_rd32(bios, data + 0x24);
0099             info->data_addr_pmu = nvbios_rd32(bios, data + 0x28);
0100             info->data_size     = nvbios_rd32(bios, data + 0x2c);
0101             return true;
0102         }
0103     }
0104     return false;
0105 }