35#include "debug/PM4PacketProcessor.hh"
42#include "enums/GfxVersion.hh"
96 addr = (((
addr >> 12) << 3) << 12) | low_bits;
112 return result->second;
150 "%d, pipe %d queue: %d size: %d\n",
id,
q->base(),
q->offset(),
151 q->me(),
q->pipe(),
q->queue(),
q->size());
157 q->wptr(wptrOffset *
sizeof(uint32_t));
159 if (!
q->processing()) {
169 q->id(),
q->rptr(),
q->wptr());
171 if (
q->rptr() !=
q->wptr()) {
186 assert(
q->rptr() ==
q->wptr());
187 q->processing(
false);
196 if (
q->getMQD()->aqlRptr) {
198 uint32_t *
data =
new uint32_t;
201 *
data =
q->getRptr() >> 2;
203 [
data](
const uint32_t &) {
delete data; });
217 void *dmaBuffer =
nullptr;
223 if (
header.count != 0x3fff) {
224 q->incRptr((
header.count + 1) *
sizeof(uint32_t));
233 [ = ] (
const uint64_t &)
242 [ = ] (
const uint64_t &)
251 [ = ] (
const uint64_t &)
260 [ = ] (
const uint64_t &)
269 [ = ] (
const uint64_t &)
278 [ = ] (
const uint64_t &)
287 [ = ] (
const uint64_t &)
293 if (
gpuDevice->getGfxVersion() == GfxVersion::gfx90a ||
294 gpuDevice->getGfxVersion() == GfxVersion::gfx942 ||
295 gpuDevice->getGfxVersion() == GfxVersion::gfx950) {
315 [ = ] (
const uint64_t &)
324 [ = ] (
const uint64_t &)
333 [ = ] (
const uint64_t &)
342 q->incRptr((
header.count + 1) *
sizeof(uint32_t));
347 warn(
"PM4 packet opcode 0x%x not supported.\n",
header.opcode);
350 q->incRptr((
header.count + 1) *
sizeof(uint32_t));
362 "addrIncr: %d resume: %d writeConfirm: %d cachePolicy: %d\n",
374 unsigned size = (
header.count - 2) *
sizeof(uint32_t);
384 }
else if (pkt->
destSel == 0) {
395 fatal(
"Unknown PM4 writeData destination %d\n", pkt->
destSel);
418 "pipe: %d, queueSlot: %d, queueType: %d, allocFormat: %d, "
419 "engineSel: %d, numQueues: %d, checkDisable: %d, doorbellOffset:"
420 " %d, mqdAddr: %lx, wptrAddr: %lx\n", pkt->
queueSel, pkt->
vmid,
431 "Mapping mqd from %p %p (vmid %d - last vmid %d).\n",
443 [ = ] (
const uint32_t &) {
454 [ = ] (
const uint32_t &) {
487 auto &hsa_pp =
gpuDevice->CP()->hsaPacketProc();
488 hsa_pp.setDeviceQueueDesc(mqd->
aqlRptr, mqd->
base, new_q->
id(),
489 mqd_size, 8, GfxVersion::gfx900,
offset,
512 "%#x/%#x ib: %#x/%#x size: %d ctrl: %#x rptr wb addr: %#lx\n",
545 "%d destSel %d dataSel %d, address %p data %p, intCtx %p\n",
550 "PM4 release_mem destSel 0 bypasses caches to MC.\n");
558 panic(
"Unimplemented PM4ReleaseMem.dataSelect");
569 "pipe: %d, queueSlot:%d\n",
q->id(), pkt->
intCtxId,
q->me(),
570 q->pipe(),
q->queue());
574 ringId = (
q->queue() << 4) | (
q->me() << 2) |
q->pipe();
579 gpuDevice->getIH()->submitInterruptCookie();
596 auto &hsa_pp =
gpuDevice->CP()->hsaPacketProc();
597 for (
auto iter :
gpuDevice->getUsedVMIDs()) {
598 for (
auto id : iter.second) {
602 if (
queues[
id]->privileged()) {
607 if (!unmap_static &&
queues[
id]->isStatic()) {
619 96 *
sizeof(uint32_t));
622 [ = ] (
const uint32_t &) {
628 hsa_pp.unsetDeviceQueueDesc(
id, 8);
640 "pasid: %p doorbellOffset0 %p \n",
690 panic(
"Unrecognized options\n");
710 gpuDevice->getVM().setPageTableBase(vmid, ptBase);
715 Addr scratch_base = (
Addr)
bits(shMemBases, 15, 0) << 48;
719 gpuDevice->CP()->shader()->setLdsApe(lds_base, lds_base + 0xFFFFFFFF);
720 gpuDevice->CP()->shader()->setScratchApe(scratch_base,
721 scratch_base + 0xFFFFFFFF);
765 q->wptr(pkt->
ibSize *
sizeof(uint32_t));
781 q->wptr(pkt->
ibSize *
sizeof(uint32_t));
812 reg_addr += 0x40000 *
getIpId();
842 " %d command: %d, pasid: %d, doorbellOffset: %d, engineSel: %d "
856 panic(
"query_status with interruptSel %d command %d not supported",
873 switch (mmio_offset) {
991 kiq.hqd_pq_doorbell_control =
data;
1015 kiq.hqd_pq_rptr_report_addr_lo =
data;
1021 kiq.hqd_pq_rptr_report_addr_hi =
data;
1027 kiq.hqd_pq_wptr_poll_addr_lo =
data;
1033 kiq.hqd_pq_wptr_poll_addr_hi =
data;
1057 pq.hqd_pq_control =
data;
1075 pq.queueRptrAddrLo =
data;
1081 pq.queueRptrAddrHi =
data;
1087 pq.hqd_pq_wptr_poll_addr_lo =
data;
1093 pq.hqd_pq_wptr_poll_addr_hi =
data;
1099 pq.hqd_pq_base_lo =
data;
1105 pq.hqd_pq_base_hi =
data;
1111 pq.hqd_pq_doorbell_control =
data;
1112 pq.doorbellOffset =
data & 0x1ffffffc;
1118 pq.doorbellRangeLo =
data;
1124 pq.doorbellRangeHi =
data;
1133 int num_queues =
queues.size();
1134 auto id = std::make_unique<Addr[]>(num_queues);
1135 auto mqd_base = std::make_unique<Addr[]>(num_queues);
1136 auto mqd_read_index = std::make_unique<uint64_t[]>(num_queues);
1137 auto base = std::make_unique<Addr[]>(num_queues);
1138 auto rptr = std::make_unique<Addr[]>(num_queues);
1139 auto wptr = std::make_unique<Addr[]>(num_queues);
1140 auto ib_base = std::make_unique<Addr[]>(num_queues);
1141 auto ib_rptr = std::make_unique<Addr[]>(num_queues);
1142 auto ib_wptr = std::make_unique<Addr[]>(num_queues);
1143 auto offset = std::make_unique<Addr[]>(num_queues);
1144 auto processing = std::make_unique<bool[]>(num_queues);
1145 auto ib = std::make_unique<bool[]>(num_queues);
1146 auto me = std::make_unique<uint32_t[]>(num_queues);
1147 auto pipe = std::make_unique<uint32_t[]>(num_queues);
1148 auto queue = std::make_unique<uint32_t[]>(num_queues);
1149 auto privileged = std::make_unique<bool[]>(num_queues);
1150 auto queue_type = std::make_unique<uint32_t[]>(num_queues);
1151 auto hqd_active = std::make_unique<uint32_t[]>(num_queues);
1152 auto hqd_vmid = std::make_unique<uint32_t[]>(num_queues);
1153 auto aql_rptr = std::make_unique<Addr[]>(num_queues);
1154 auto aql = std::make_unique<uint32_t[]>(num_queues);
1155 auto doorbell = std::make_unique<uint32_t[]>(num_queues);
1156 auto hqd_pq_control = std::make_unique<uint32_t[]>(num_queues);
1159 for (
auto iter :
queues) {
1162 mqd_base[
i] =
q->mqdBase();
1163 mqd_read_index[
i] =
q->getMQD()->mqdReadIndex;
1164 bool cur_state =
q->ib();
1167 rptr[
i] =
q->getRptr();
1168 wptr[
i] =
q->getWptr();
1170 ib_base[
i] =
q->ibBase();
1171 ib_rptr[
i] =
q->getRptr();
1172 ib_wptr[
i] =
q->getWptr();
1175 processing[
i] =
q->processing();
1178 pipe[
i] =
q->pipe();
1179 queue[
i] =
q->queue();
1180 privileged[
i] =
q->privileged();
1181 queue_type[
i] =
q->queueType();
1182 hqd_active[
i] =
q->getMQD()->hqd_active;
1183 hqd_vmid[
i] =
q->getMQD()->hqd_vmid;
1184 aql_rptr[
i] =
q->getMQD()->aqlRptr;
1185 aql[
i] =
q->getMQD()->aql;
1186 doorbell[
i] =
q->getMQD()->doorbell;
1187 hqd_pq_control[
i] =
q->getMQD()->hqd_pq_control;
1226 auto id = std::make_unique<Addr[]>(num_queues);
1227 auto mqd_base = std::make_unique<Addr[]>(num_queues);
1228 auto mqd_read_index = std::make_unique<uint64_t[]>(num_queues);
1229 auto base = std::make_unique<Addr[]>(num_queues);
1230 auto rptr = std::make_unique<Addr[]>(num_queues);
1231 auto wptr = std::make_unique<Addr[]>(num_queues);
1232 auto ib_base = std::make_unique<Addr[]>(num_queues);
1233 auto ib_rptr = std::make_unique<Addr[]>(num_queues);
1234 auto ib_wptr = std::make_unique<Addr[]>(num_queues);
1235 auto offset = std::make_unique<Addr[]>(num_queues);
1236 auto processing = std::make_unique<bool[]>(num_queues);
1237 auto ib = std::make_unique<bool[]>(num_queues);
1238 auto me = std::make_unique<uint32_t[]>(num_queues);
1239 auto pipe = std::make_unique<uint32_t[]>(num_queues);
1240 auto queue = std::make_unique<uint32_t[]>(num_queues);
1241 auto privileged = std::make_unique<bool[]>(num_queues);
1242 auto queue_type = std::make_unique<uint32_t[]>(num_queues);
1243 auto hqd_active = std::make_unique<uint32_t[]>(num_queues);
1244 auto hqd_vmid = std::make_unique<uint32_t[]>(num_queues);
1245 auto aql_rptr = std::make_unique<Addr[]>(num_queues);
1246 auto aql = std::make_unique<uint32_t[]>(num_queues);
1247 auto doorbell = std::make_unique<uint32_t[]>(num_queues);
1248 auto hqd_pq_control = std::make_unique<uint32_t[]>(num_queues);
1274 for (
int i = 0;
i < num_queues;
i++) {
1296 queues[
id[
i]]->processing(processing[
i]);
1297 queues[
id[
i]]->setPkt(
me[
i], pipe[
i], queue[
i], privileged[
i],
1299 queues[
id[
i]]->getMQD()->hqd_active = hqd_active[
i];
1300 queues[
id[
i]]->getMQD()->hqd_vmid = hqd_vmid[
i];
1301 queues[
id[
i]]->getMQD()->aqlRptr = aql_rptr[
i];
1302 queues[
id[
i]]->getMQD()->doorbell = doorbell[
i];
1303 queues[
id[
i]]->getMQD()->hqd_pq_control = hqd_pq_control[
i];
1306 int mqd_size = (1 << ((hqd_pq_control[
i] & 0x3f) + 1)) * 4;
1307 auto &hsa_pp =
gpuDevice->CP()->hsaPacketProc();
1308 hsa_pp.setDeviceQueueDesc(aql_rptr[
i],
base[
i],
id[
i],
1309 mqd_size, 8, GfxVersion::gfx900,
offset[
i],
Device model for an AMD GPU.
Translation range generators.
void serialize(CheckpointOut &cp) const override
Serialize an object.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Wraps a std::function object in a DmaCallback.
void dmaReadVirt(Addr host_addr, unsigned size, DmaCallback *cb, void *data, Tick delay=0)
Initiate a DMA read from virtual address host_addr.
DmaVirtDevice(const Params &p)
void dmaWriteVirt(Addr host_addr, unsigned size, DmaCallback *b, void *data, Tick delay=0)
Initiate a DMA write from virtual address host_addr.
void writeMMIO(PacketPtr pkt, Addr mmio_offset)
void setRbWptrPollAddrLo(uint32_t data)
void decodeHeader(PM4Queue *q, PM4Header header)
This method calls other PM4 packet processing methods based on the header of a PM4 packet.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void setRbWptrHi(uint32_t data)
void mapKiq(Addr offset)
The first compute queue, the Kernel Interface Queueu a.k.a.
Addr getGARTAddr(Addr addr) const
void writeDataDone(PM4Queue *q, PM4WriteData *pkt, Addr addr)
void setRbWptrLo(uint32_t data)
void switchBuffer(PM4Queue *q, PM4SwitchBuf *pkt)
void setGPUDevice(AMDGPUDevice *gpu_device)
void serialize(CheckpointOut &cp) const override
Serialize an object.
void setRbCntl(uint32_t data)
uint32_t getKiqDoorbellOffset()
void setHqdPqWptrLo(uint32_t data)
std::unordered_map< uint32_t, PM4Queue * > queuesMap
void setUconfigReg(PM4Queue *q, PM4SetUconfigReg *pkt)
void queryStatus(PM4Queue *q, PM4QueryStatus *pkt)
void releaseMem(PM4Queue *q, PM4ReleaseMem *pkt)
void releaseMemDone(PM4Queue *q, PM4ReleaseMem *pkt, Addr addr)
void setHqdPqRptrReportAddr(uint32_t data)
void updateReadIndex(Addr offset, uint64_t rd_idx)
Update read index on doorbell rings.
void setRbBaseHi(uint32_t data)
void mapProcessV1(PM4Queue *q, PM4MapProcess *pkt)
void setRbVmid(uint32_t data)
void setHqdActive(uint32_t data)
void processSDMAMQD(PM4MapQueues *pkt, PM4Queue *q, Addr addr, SDMAQueueDesc *mqd, uint16_t vmid)
void process(PM4Queue *q, Addr wptrOffset)
This method start processing a PM4Queue from the current read pointer to the newly communicated write...
void setHqdPqControl(uint32_t data)
void setRbBaseLo(uint32_t data)
void mapProcessV2(PM4Queue *q, PM4MapProcessV2 *pkt)
void setHqdIbCtrl(uint32_t data)
void setRbRptrAddrHi(uint32_t data)
void setHqdPqWptrPollAddr(uint32_t data)
void newQueue(QueueDesc *q, Addr offset, PM4MapQueues *pkt=nullptr, int id=-1)
This method creates a new PM4Queue based on a queue descriptor and an offset.
void unmapQueues(PM4Queue *q, PM4UnmapQueues *pkt)
void queryStatusDone(PM4Queue *q, PM4QueryStatus *pkt)
void mapProcess(uint32_t pasid, uint64_t ptBase, uint32_t shMemBases)
void setRbDoorbellRangeLo(uint32_t data)
void waitRegMem(PM4Queue *q, PM4WaitRegMem *pkt)
void setHqdPqBaseHi(uint32_t data)
void runList(PM4Queue *q, PM4RunList *pkt)
void decodeNext(PM4Queue *q)
This method decodes the next packet in a PM4Queue.
void mapPq(Addr offset)
The first graphics queue, the Primary Queueu a.k.a.
void setHqdVmid(uint32_t data)
void writeData(PM4Queue *q, PM4WriteData *pkt, PM4Header header)
void setHqdPqDoorbellCtrl(uint32_t data)
void setHqdPqBase(uint32_t data)
void setRbDoorbellRangeHi(uint32_t data)
uint32_t getPqDoorbellOffset()
void doneMQDWrite(Addr mqdAddr, Addr addr)
std::unordered_map< uint16_t, PM4Queue * > queues
void indirectBuffer(PM4Queue *q, PM4IndirectBuf *pkt)
PM4PacketProcessor(const PM4PacketProcessorParams &p)
void unmapAllQueues(bool unmap_static)
void setHqdPqPtr(uint32_t data)
void setHqdPqRptrReportAddrHi(uint32_t data)
void mapQueues(PM4Queue *q, PM4MapQueues *pkt)
TranslationGenPtr translate(Addr vaddr, Addr size) override
Method for functional translation.
void processMQD(PM4MapQueues *pkt, PM4Queue *q, Addr addr, QueueDesc *mqd, uint16_t vmid)
void setRbRptrAddrLo(uint32_t data)
void setRbDoorbellCntrl(uint32_t data)
PM4Queue * getQueue(Addr offset, bool gfx=false)
Based on an offset communicated through doorbell write, the PM4PacketProcessor identifies which queue...
AddrRangeList getAddrRanges() const override
Every PIO device is obliged to provide an implementation that returns the address ranges the device r...
void setHqdPqWptrPollAddrHi(uint32_t data)
void setHqdPqWptrHi(uint32_t data)
void setRbWptrPollAddrHi(uint32_t data)
Class defining a PM4 queue.
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
System DMA Engine class for AMD dGPU.
void registerRLCQueue(Addr doorbell, Addr mqdAddr, SDMAQueueDesc *mqd, bool isStatic)
Methods for RLC queues.
The GPUCommandProcessor (CP) is responsible for accepting commands, in the form of HSA AQL packets,...
std::list< AddrRange > AddrRangeList
Convenience typedef for a collection of address ranges.
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
#define panic(...)
This implements a cprintf based panic() function.
#define fatal(...)
This implements a cprintf based fatal() function.
#define UNSERIALIZE_UNIQUE_PTR_ARRAY(member, size)
#define SERIALIZE_UNIQUE_PTR_ARRAY(member, size)
Copyright (c) 2024 Arm Limited All rights reserved.
struct gem5::GEM5_PACKED PM4WriteData
struct gem5::GEM5_PACKED PM4WaitRegMem
std::ostream CheckpointOut
struct gem5::GEM5_PACKED PM4RunList
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
@ SOC15_IH_CLIENTID_GRBM_CP
struct gem5::GEM5_PACKED PM4ReleaseMem
struct gem5::GEM5_PACKED PM4SwitchBuf
struct gem5::GEM5_PACKED PM4Header
PM4 packets.
struct gem5::GEM5_PACKED PM4MapQueues
struct gem5::GEM5_PACKED PM4MapProcess
struct gem5::GEM5_PACKED PM4MapProcessV2
struct gem5::GEM5_PACKED SDMAQueueDesc
Queue descriptor for SDMA-based user queues (RLC queues).
struct gem5::GEM5_PACKED PM4UnmapQueues
std::unique_ptr< TranslationGen > TranslationGenPtr
struct gem5::GEM5_PACKED PM4SetUconfigReg
struct gem5::GEM5_PACKED PM4QueryStatus
struct gem5::GEM5_PACKED QueueDesc
Queue descriptor with relevant MQD attributes.
struct gem5::GEM5_PACKED PM4IndirectBuf
Declaration of the Packet class.
#define PACKET3_SET_UCONFIG_REG_START
Value from vega10/pm4_header.h.
#define mmCP_RB_DOORBELL_CONTROL
#define mmCP_RB0_RPTR_ADDR_HI
#define mmCP_HQD_PQ_RPTR_REPORT_ADDR
#define mmCP_HQD_PQ_DOORBELL_CONTROL
#define mmCP_HQD_PQ_WPTR_POLL_ADDR
#define mmCP_HQD_PQ_RPTR_REPORT_ADDR_HI
#define mmCP_RB_DOORBELL_RANGE_UPPER
#define mmCP_HQD_IB_CONTROL
#define mmCP_RB_WPTR_POLL_ADDR_LO
#define mmCP_HQD_PQ_BASE_HI
#define mmCP_HQD_PQ_WPTR_HI
#define mmCP_HQD_PQ_CONTROL
#define mmCP_RB_DOORBELL_RANGE_LOWER
#define mmCP_RB_WPTR_POLL_ADDR_HI
#define mmCP_RB0_RPTR_ADDR
#define mmCP_HQD_PQ_WPTR_POLL_ADDR_HI
#define mmCP_HQD_PQ_WPTR_LO
#define UNSERIALIZE_SCALAR(scalar)
#define SERIALIZE_SCALAR(scalar)
uint32_t sdmax_rlcx_ib_base_lo
uint32_t sdmax_rlcx_rb_rptr
uint32_t sdmax_rlcx_rb_rptr_addr_hi
uint32_t sdmax_rlcx_rb_cntl
uint32_t sdmax_rlcx_rb_wptr_hi
uint32_t sdmax_rlcx_ib_base_hi
uint32_t sdmax_rlcx_rb_rptr_addr_lo
uint32_t sdmax_rlcx_rb_wptr
uint32_t sdmax_rlcx_rb_rptr_hi
uint64_t completionSignal