Skip to content

Commit 88a2b4d

Browse files
ttabidakr
authored andcommitted
nouveau/gsp: document some aspects of GSP-RM
Document a few aspects of communication with GSP-RM. These comments are derived from notes made during early development of GSP-RM support in Nouveau, but were not included in the initial patch set. Reviewed-by: Dave Airlie <airlied@redhat.com> Signed-off-by: Timur Tabi <ttabi@nvidia.com> Reviewed-by: Danilo Krummrich <dakr@redhat.com> Signed-off-by: Danilo Krummrich <dakr@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20231122202840.2565153-1-ttabi@nvidia.com
1 parent fb18fe0 commit 88a2b4d

2 files changed

Lines changed: 133 additions & 0 deletions

File tree

  • drivers/gpu/drm/nouveau

drivers/gpu/drm/nouveau/include/nvrm/535.113.01/common/shared/msgq/inc/msgq/msgq_priv.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,49 @@
2626
* DEALINGS IN THE SOFTWARE.
2727
*/
2828

29+
/**
30+
* msgqTxHeader -- TX queue data structure
31+
* @version: the version of this structure, must be 0
32+
* @size: the size of the entire queue, including this header
33+
* @msgSize: the padded size of queue element, 16 is minimum
34+
* @msgCount: the number of elements in this queue
35+
* @writePtr: head index of this queue
36+
* @flags: 1 = swap the RX pointers
37+
* @rxHdrOff: offset of readPtr in this structure
38+
* @entryOff: offset of beginning of queue (msgqRxHeader), relative to
39+
* beginning of this structure
40+
*
41+
* The command queue is a queue of RPCs that are sent from the driver to the
42+
* GSP. The status queue is a queue of messages/responses from GSP-RM to the
43+
* driver. Although the driver allocates memory for both queues, the command
44+
* queue is owned by the driver and the status queue is owned by GSP-RM. In
45+
* addition, the headers of the two queues must not share the same 4K page.
46+
*
47+
* Each queue is prefixed with this data structure. The idea is that a queue
48+
* and its header are written to only by their owner. That is, only the
49+
* driver writes to the command queue and command queue header, and only the
50+
* GSP writes to the status (receive) queue and its header.
51+
*
52+
* This is enforced by the concept of "swapping" the RX pointers. This is
53+
* why the 'flags' field must be set to 1. 'rxHdrOff' is how the GSP knows
54+
* where the where the tail pointer of its status queue.
55+
*
56+
* When the driver writes a new RPC to the command queue, it updates writePtr.
57+
* When it reads a new message from the status queue, it updates readPtr. In
58+
* this way, the GSP knows when a new command is in the queue (it polls
59+
* writePtr) and it knows how much free space is in the status queue (it
60+
* checks readPtr). The driver never cares about how much free space is in
61+
* the status queue.
62+
*
63+
* As usual, producers write to the head pointer, and consumers read from the
64+
* tail pointer. When head == tail, the queue is empty.
65+
*
66+
* So to summarize:
67+
* command.writePtr = head of command queue
68+
* command.readPtr = tail of status queue
69+
* status.writePtr = head of status queue
70+
* status.readPtr = tail of command queue
71+
*/
2972
typedef struct
3073
{
3174
NvU32 version; // queue version
@@ -38,6 +81,14 @@ typedef struct
3881
NvU32 entryOff; // Offset of entries from start of backing store.
3982
} msgqTxHeader;
4083

84+
/**
85+
* msgqRxHeader - RX queue data structure
86+
* @readPtr: tail index of the other queue
87+
*
88+
* Although this is a separate struct, it could easily be merged into
89+
* msgqTxHeader. msgqTxHeader.rxHdrOff is simply the offset of readPtr
90+
* from the beginning of msgqTxHeader.
91+
*/
4192
typedef struct
4293
{
4394
NvU32 readPtr; // message id of last message read

drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,13 @@ r535_gsp_msg_post_event(void *priv, u32 fn, void *repv, u32 repc)
13771377
return 0;
13781378
}
13791379

1380+
/**
1381+
* r535_gsp_msg_run_cpu_sequencer() -- process I/O commands from the GSP
1382+
*
1383+
* The GSP sequencer is a list of I/O commands that the GSP can send to
1384+
* the driver to perform for various purposes. The most common usage is to
1385+
* perform a special mid-initialization reset.
1386+
*/
13801387
static int
13811388
r535_gsp_msg_run_cpu_sequencer(void *priv, u32 fn, void *repv, u32 repc)
13821389
{
@@ -1716,6 +1723,23 @@ r535_gsp_libos_id8(const char *name)
17161723
return id;
17171724
}
17181725

1726+
/**
1727+
* create_pte_array() - creates a PTE array of a physically contiguous buffer
1728+
* @ptes: pointer to the array
1729+
* @addr: base address of physically contiguous buffer (GSP_PAGE_SIZE aligned)
1730+
* @size: size of the buffer
1731+
*
1732+
* GSP-RM sometimes expects physically-contiguous buffers to have an array of
1733+
* "PTEs" for each page in that buffer. Although in theory that allows for
1734+
* the buffer to be physically discontiguous, GSP-RM does not currently
1735+
* support that.
1736+
*
1737+
* In this case, the PTEs are DMA addresses of each page of the buffer. Since
1738+
* the buffer is physically contiguous, calculating all the PTEs is simple
1739+
* math.
1740+
*
1741+
* See memdescGetPhysAddrsForGpu()
1742+
*/
17191743
static void create_pte_array(u64 *ptes, dma_addr_t addr, size_t size)
17201744
{
17211745
unsigned int num_pages = DIV_ROUND_UP_ULL(size, GSP_PAGE_SIZE);
@@ -1725,6 +1749,35 @@ static void create_pte_array(u64 *ptes, dma_addr_t addr, size_t size)
17251749
ptes[i] = (u64)addr + (i << GSP_PAGE_SHIFT);
17261750
}
17271751

1752+
/**
1753+
* r535_gsp_libos_init() -- create the libos arguments structure
1754+
*
1755+
* The logging buffers are byte queues that contain encoded printf-like
1756+
* messages from GSP-RM. They need to be decoded by a special application
1757+
* that can parse the buffers.
1758+
*
1759+
* The 'loginit' buffer contains logs from early GSP-RM init and
1760+
* exception dumps. The 'logrm' buffer contains the subsequent logs. Both are
1761+
* written to directly by GSP-RM and can be any multiple of GSP_PAGE_SIZE.
1762+
*
1763+
* The physical address map for the log buffer is stored in the buffer
1764+
* itself, starting with offset 1. Offset 0 contains the "put" pointer.
1765+
*
1766+
* The GSP only understands 4K pages (GSP_PAGE_SIZE), so even if the kernel is
1767+
* configured for a larger page size (e.g. 64K pages), we need to give
1768+
* the GSP an array of 4K pages. Fortunately, since the buffer is
1769+
* physically contiguous, it's simple math to calculate the addresses.
1770+
*
1771+
* The buffers must be a multiple of GSP_PAGE_SIZE. GSP-RM also currently
1772+
* ignores the @kind field for LOGINIT, LOGINTR, and LOGRM, but expects the
1773+
* buffers to be physically contiguous anyway.
1774+
*
1775+
* The memory allocated for the arguments must remain until the GSP sends the
1776+
* init_done RPC.
1777+
*
1778+
* See _kgspInitLibosLoggingStructures (allocates memory for buffers)
1779+
* See kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs[] array)
1780+
*/
17281781
static int
17291782
r535_gsp_libos_init(struct nvkm_gsp *gsp)
17301783
{
@@ -1835,6 +1888,35 @@ nvkm_gsp_radix3_dtor(struct nvkm_gsp *gsp, struct nvkm_gsp_radix3 *rx3)
18351888
nvkm_gsp_mem_dtor(gsp, &rx3->mem[i]);
18361889
}
18371890

1891+
/**
1892+
* nvkm_gsp_radix3_sg - build a radix3 table from a S/G list
1893+
*
1894+
* The GSP uses a three-level page table, called radix3, to map the firmware.
1895+
* Each 64-bit "pointer" in the table is either the bus address of an entry in
1896+
* the next table (for levels 0 and 1) or the bus address of the next page in
1897+
* the GSP firmware image itself.
1898+
*
1899+
* Level 0 contains a single entry in one page that points to the first page
1900+
* of level 1.
1901+
*
1902+
* Level 1, since it's also only one page in size, contains up to 512 entries,
1903+
* one for each page in Level 2.
1904+
*
1905+
* Level 2 can be up to 512 pages in size, and each of those entries points to
1906+
* the next page of the firmware image. Since there can be up to 512*512
1907+
* pages, that limits the size of the firmware to 512*512*GSP_PAGE_SIZE = 1GB.
1908+
*
1909+
* Internally, the GSP has its window into system memory, but the base
1910+
* physical address of the aperture is not 0. In fact, it varies depending on
1911+
* the GPU architecture. Since the GPU is a PCI device, this window is
1912+
* accessed via DMA and is therefore bound by IOMMU translation. The end
1913+
* result is that GSP-RM must translate the bus addresses in the table to GSP
1914+
* physical addresses. All this should happen transparently.
1915+
*
1916+
* Returns 0 on success, or negative error code
1917+
*
1918+
* See kgspCreateRadix3_IMPL
1919+
*/
18381920
static int
18391921
nvkm_gsp_radix3_sg(struct nvkm_device *device, struct sg_table *sgt, u64 size,
18401922
struct nvkm_gsp_radix3 *rx3)

0 commit comments

Comments
 (0)