131214108SAlexandre Courbot /*
231214108SAlexandre Courbot * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
331214108SAlexandre Courbot *
431214108SAlexandre Courbot * Permission is hereby granted, free of charge, to any person obtaining a
531214108SAlexandre Courbot * copy of this software and associated documentation files (the "Software"),
631214108SAlexandre Courbot * to deal in the Software without restriction, including without limitation
731214108SAlexandre Courbot * the rights to use, copy, modify, merge, publish, distribute, sublicense,
831214108SAlexandre Courbot * and/or sell copies of the Software, and to permit persons to whom the
931214108SAlexandre Courbot * Software is furnished to do so, subject to the following conditions:
1031214108SAlexandre Courbot *
1131214108SAlexandre Courbot * The above copyright notice and this permission notice shall be included in
1231214108SAlexandre Courbot * all copies or substantial portions of the Software.
1331214108SAlexandre Courbot *
1431214108SAlexandre Courbot * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1531214108SAlexandre Courbot * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1631214108SAlexandre Courbot * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1731214108SAlexandre Courbot * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1831214108SAlexandre Courbot * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
1931214108SAlexandre Courbot * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2031214108SAlexandre Courbot * DEALINGS IN THE SOFTWARE.
2131214108SAlexandre Courbot */
2231214108SAlexandre Courbot #include "priv.h"
2331214108SAlexandre Courbot
2431214108SAlexandre Courbot #include <core/gpuobj.h>
2531214108SAlexandre Courbot #include <core/memory.h>
2631214108SAlexandre Courbot #include <subdev/timer.h>
2731214108SAlexandre Courbot
28*a128bbfaSBen Skeggs void
nvkm_falcon_v1_load_imem(struct nvkm_falcon * falcon,void * data,u32 start,u32 size,u16 tag,u8 port,bool secure)2931214108SAlexandre Courbot nvkm_falcon_v1_load_imem(struct nvkm_falcon *falcon, void *data, u32 start,
3031214108SAlexandre Courbot u32 size, u16 tag, u8 port, bool secure)
3131214108SAlexandre Courbot {
3231214108SAlexandre Courbot u8 rem = size % 4;
3331214108SAlexandre Courbot u32 reg;
3431214108SAlexandre Courbot int i;
3531214108SAlexandre Courbot
3631214108SAlexandre Courbot size -= rem;
3731214108SAlexandre Courbot
3831214108SAlexandre Courbot reg = start | BIT(24) | (secure ? BIT(28) : 0);
3931214108SAlexandre Courbot nvkm_falcon_wr32(falcon, 0x180 + (port * 16), reg);
4031214108SAlexandre Courbot for (i = 0; i < size / 4; i++) {
4131214108SAlexandre Courbot /* write new tag every 256B */
4231214108SAlexandre Courbot if ((i & 0x3f) == 0)
4317c602e3SAlexandre Courbot nvkm_falcon_wr32(falcon, 0x188 + (port * 16), tag++);
4417c602e3SAlexandre Courbot nvkm_falcon_wr32(falcon, 0x184 + (port * 16), ((u32 *)data)[i]);
4531214108SAlexandre Courbot }
4631214108SAlexandre Courbot
4731214108SAlexandre Courbot /*
4831214108SAlexandre Courbot * If size is not a multiple of 4, mask the last work to ensure garbage
4931214108SAlexandre Courbot * does not get written
5031214108SAlexandre Courbot */
5131214108SAlexandre Courbot if (rem) {
5231214108SAlexandre Courbot u32 extra = ((u32 *)data)[i];
5331214108SAlexandre Courbot
5431214108SAlexandre Courbot /* write new tag every 256B */
5531214108SAlexandre Courbot if ((i & 0x3f) == 0)
5617c602e3SAlexandre Courbot nvkm_falcon_wr32(falcon, 0x188 + (port * 16), tag++);
5717c602e3SAlexandre Courbot nvkm_falcon_wr32(falcon, 0x184 + (port * 16),
5817c602e3SAlexandre Courbot extra & (BIT(rem * 8) - 1));
5931214108SAlexandre Courbot ++i;
6031214108SAlexandre Courbot }
6131214108SAlexandre Courbot
6231214108SAlexandre Courbot /* code must be padded to 0x40 words */
6331214108SAlexandre Courbot for (; i & 0x3f; i++)
6417c602e3SAlexandre Courbot nvkm_falcon_wr32(falcon, 0x184 + (port * 16), 0);
6531214108SAlexandre Courbot }
6631214108SAlexandre Courbot
67*a128bbfaSBen Skeggs void
nvkm_falcon_v1_load_dmem(struct nvkm_falcon * falcon,void * data,u32 start,u32 size,u8 port)6831214108SAlexandre Courbot nvkm_falcon_v1_load_dmem(struct nvkm_falcon *falcon, void *data, u32 start,
6931214108SAlexandre Courbot u32 size, u8 port)
7031214108SAlexandre Courbot {
7131214108SAlexandre Courbot u8 rem = size % 4;
7231214108SAlexandre Courbot int i;
7331214108SAlexandre Courbot
7431214108SAlexandre Courbot size -= rem;
7531214108SAlexandre Courbot
76ca179c85SAlexandre Courbot nvkm_falcon_wr32(falcon, 0x1c0 + (port * 8), start | (0x1 << 24));
7731214108SAlexandre Courbot for (i = 0; i < size / 4; i++)
78ca179c85SAlexandre Courbot nvkm_falcon_wr32(falcon, 0x1c4 + (port * 8), ((u32 *)data)[i]);
7931214108SAlexandre Courbot
8031214108SAlexandre Courbot /*
81ca179c85SAlexandre Courbot * If size is not a multiple of 4, mask the last word to ensure garbage
82ca179c85SAlexandre Courbot * does not get written
8331214108SAlexandre Courbot */
8431214108SAlexandre Courbot if (rem) {
8531214108SAlexandre Courbot u32 extra = ((u32 *)data)[i];
8631214108SAlexandre Courbot
87ca179c85SAlexandre Courbot nvkm_falcon_wr32(falcon, 0x1c4 + (port * 8),
88ca179c85SAlexandre Courbot extra & (BIT(rem * 8) - 1));
8931214108SAlexandre Courbot }
9031214108SAlexandre Courbot }
9131214108SAlexandre Courbot
92*a128bbfaSBen Skeggs void
nvkm_falcon_v1_start(struct nvkm_falcon * falcon)9331214108SAlexandre Courbot nvkm_falcon_v1_start(struct nvkm_falcon *falcon)
9431214108SAlexandre Courbot {
9531214108SAlexandre Courbot u32 reg = nvkm_falcon_rd32(falcon, 0x100);
9631214108SAlexandre Courbot
9731214108SAlexandre Courbot if (reg & BIT(6))
9831214108SAlexandre Courbot nvkm_falcon_wr32(falcon, 0x130, 0x2);
9931214108SAlexandre Courbot else
10031214108SAlexandre Courbot nvkm_falcon_wr32(falcon, 0x100, 0x2);
10131214108SAlexandre Courbot }
102