@@ -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+ */
13801387static int
13811388r535_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+ */
17191743static 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+ */
17281781static int
17291782r535_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+ */
18381920static int
18391921nvkm_gsp_radix3_sg (struct nvkm_device * device , struct sg_table * sgt , u64 size ,
18401922 struct nvkm_gsp_radix3 * rx3 )
0 commit comments