staging: gasket: Apex uncloaks, plus fixes
cover staging: gasket: Apex uncloaks, plus fixes
From: Todd Poynor <[email protected]>
Add a description of the Gasket framework device Apex (it's a Google Edge TPU machine learning accelerator soon to be released), plus a handful of fixes.
Nick Ewalt (7):
staging: gasket: fix DMA direction for extended page tables
staging: gasket: fix data page unmap DMA direction
staging: gasket: page_table: don't unmap coherent pages
staging: gasket: fix gasket_free_coherent_memory metadata frees
staging: gasket: cleanup if dma_map_page fails in
gasket_perform_mapping
staging: gasket: page_table: use total_entries for max ext lvl0 page
idx
staging: gasket: page_table: handle failed dma_map_page
Todd Poynor (3):
staging: gasket: Kconfig: describe Apex as an Edge TPU device
staging: gasket: interrupt: remove PCI-MSIX-specific status check
staging: gasket: page table: use GFP_KERNEL for dma_alloc_coherent
drivers/staging/gasket/Kconfig | 5 +- drivers/staging/gasket/gasket_interrupt.c | 5 -- drivers/staging/gasket/gasket_page_table.c | 61 +++++++++++++++------- 3 files changed, 45 insertions(+), 26 deletions(-)
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
PATCH 1/10 staging: gasket: Kconfig: describe Apex as an Edge TPU device
From: Todd Poynor <[email protected]>
Add a brief description and URL for more information on the Apex device, an Edge TPU (Tensorflow Processing Unit) machine learning accelerator.
--- drivers/staging/gasket/Kconfig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/gasket/Kconfig +3 -2
@@ -14,8 +14,9 @@ config STAGING_APEX_DRIVER tristate "Apex Driver" depends on STAGING_GASKET_FRAMEWORK help - This driver supports the Apex device. Say Y if you want to - include this driver in the kernel. + This driver supports the Apex Edge TPU device. See + https://cloud.google.com/edge-tpu/ for more information. + Say Y if you want to include this driver in the kernel. To compile this driver as a module, choose M here. The module will be called "apex".
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
PATCH 2/10 staging: gasket: interrupt: remove PCI-MSIX-specific status check
In reply to Todd PoynorFrom: Todd Poynor <[email protected]>
Devices not using MSIX don't use the msix_initialized field, so don't require it to be set in the interrupt system status check. The general check for interrupts configured that follows can cover both MSIX and device-managed interrupts.
--- drivers/staging/gasket/gasket_interrupt.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/staging/gasket/gasket_interrupt.c +0 -5
@@ -478,11 +478,6 @@ int gasket_interrupt_system_status(struct gasket_dev *gasket_dev)return GASKET_STATUS_DEAD ; } -if (!gasket_dev->interrupt_data->msix_configured) { -dev_dbg (gasket_dev->dev,"Interrupt not initialized\n" ); -return GASKET_STATUS_LAMED ; - } -if (gasket_dev->interrupt_data->num_configured != gasket_dev->interrupt_data->num_interrupts) { dev_dbg(gasket_dev->dev,
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
PATCH 3/10 staging: gasket: page table: use GFP_KERNEL for dma_alloc_coherent
In reply to Todd PoynorFrom: Todd Poynor <[email protected]>
Flags should be specified for dma_alloc_coherent() call. Use GFP_KERNEL, it's fine to sleep here.
--- drivers/staging/gasket/gasket_page_table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gasket/gasket_page_table.c +1 -1
@@ -1287,7 +1287,7 @@ int gasket_alloc_coherent_memory(struct gasket_dev *gasket_dev, u64 size,return -EINVAL ; mem =dma_alloc_coherent (gasket_get_device (gasket_dev), - num_pages *PAGE_SIZE , &handle,0 ); + num_pages *PAGE_SIZE , &handle,GFP_KERNEL );if (!mem) goto nomem;
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
PATCH 4/10 staging: gasket: fix DMA direction for extended page tables
In reply to Todd PoynorFrom: Nick Ewalt <[email protected]>
Extended page tables should be mapped as DMA_TO_DEVICE, not bi-directional.
--- drivers/staging/gasket/gasket_page_table.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/gasket/gasket_page_table.c +2 -2
@@ -320,7 +320,7 @@ static void gasket_free_extended_subtable(struct gasket_page_table *pg_tbl,if (pte->dma_addr)dma_unmap_page (pg_tbl->device, pte->dma_addr,PAGE_SIZE , -DMA_BIDIRECTIONAL ); +DMA_TO_DEVICE );vfree (pte->sublevel);
@@ -894,7 +894,7 @@ static int gasket_alloc_extended_subtable(struct gasket_page_table *pg_tbl,/* Map the page into DMA space. */ pte->dma_addr =dma_map_page (pg_tbl->device, pte->page,0 ,PAGE_SIZE , -DMA_BIDIRECTIONAL ); +DMA_TO_DEVICE );/* make the addresses available to the device */ dma_addr = (pte->dma_addr + pte->offset) |GASKET_VALID_SLOT_FLAG ;
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
PATCH 5/10 staging: gasket: fix data page unmap DMA direction
In reply to Todd PoynorFrom: Nick Ewalt <[email protected]>
The DMA direction supplied to dma_unmap_page should match the corresponding dma_map_page call, which is mapped bi-directional.
--- drivers/staging/gasket/gasket_page_table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gasket/gasket_page_table.c +1 -1
@@ -612,7 +612,7 @@ static void gasket_perform_unmapping(struct gasket_page_table *pg_tbl,if (ptes[i].status ==PTE_INUSE ) {if (ptes[i].dma_addr) {dma_unmap_page (pg_tbl->device, ptes[i].dma_addr, -PAGE_SIZE ,DMA_FROM_DEVICE ); +PAGE_SIZE ,DMA_BIDIRECTIONAL ); }if (gasket_release_page (ptes[i].page)) --pg_tbl->num_active_pages;
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
PATCH 6/10 staging: gasket: page_table: don't unmap coherent pages
In reply to Todd PoynorFrom: Nick Ewalt <[email protected]>
Only call dma_unmap_page if there was an associated dma_map_page call.
--- drivers/staging/gasket/gasket_page_table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gasket/gasket_page_table.c +1 -1
@@ -610,7 +610,7 @@ static void gasket_perform_unmapping(struct gasket_page_table *pg_tbl,/* release the address from the driver, */ if (ptes[i].status ==PTE_INUSE ) { -if (ptes[i].dma_addr) { +if (ptes[i].page && ptes[i].dma_addr) {dma_unmap_page (pg_tbl->device, ptes[i].dma_addr,PAGE_SIZE ,DMA_BIDIRECTIONAL ); }
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
PATCH 7/10 staging: gasket: fix gasket_free_coherent_memory metadata frees
In reply to Todd PoynorFrom: Nick Ewalt <[email protected]>
Free gasket_coherent_page_entries metadata memory, update data structures accordingly.
--- drivers/staging/gasket/gasket_page_table.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/staging/gasket/gasket_page_table.c +5 -0
@@ -1353,6 +1353,11 @@ int gasket_free_coherent_memory(struct gasket_dev *gasket_dev, u64 size, gasket_dev->coherent_buffer.virt_base =NULL ; gasket_dev->coherent_buffer.phys_base =0 ; } + +kfree (gasket_dev->page_table[index]->coherent_pages); + gasket_dev->page_table[index]->coherent_pages =NULL ; + gasket_dev->page_table[index]->num_coherent_pages =0 ; +return 0 ; }
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
PATCH 8/10 staging: gasket: cleanup if dma_map_page fails in gasket_perform_mapping
In reply to Todd PoynorFrom: Nick Ewalt <[email protected]>
Previously pages would have never been unmapped in this case.
--- drivers/staging/gasket/gasket_page_table.c | 33 +++++++++++++--------- 1 file changed, 20 insertions(+), 13 deletions(-)
drivers/staging/gasket/gasket_page_table.c +20 -13
@@ -433,6 +433,19 @@ static int is_coherent(struct gasket_page_table *pg_tbl, ulong host_addr)return min <= host_addr && host_addr < max; } +/* Safely return a page to the OS. */ +static bool gasket_release_page (struct page *page) +{ +if (!page) +return false; + +if (!PageReserved (page)) +SetPageDirty (page); +put_page (page); + +return true; +} +/* * Get and map last level page table buffers. *
@@ -500,6 +513,13 @@ static int gasket_perform_mapping(struct gasket_page_table *pg_tbl, (unsigned long long )ptes[i].dma_addr, (void *)page_to_pfn (page), (void *)page_to_phys(page)); + +/* clean up */ +if (gasket_release_page (ptes[i].page)) + --pg_tbl->num_active_pages; + +memset (&ptes[i],0 , +sizeof (struct gasket_page_table_entry ));return -1 ; } }
@@ -571,19 +591,6 @@ static int gasket_alloc_simple_entries(struct gasket_page_table *pg_tbl,return 0 ; } -/* Safely return a page to the OS. */ -static bool gasket_release_page (struct page *page) -{ -if (!page) -return false; - -if (!PageReserved (page)) -SetPageDirty (page); -put_page (page); - -return true; -} -/* * Unmap and release mapped pages. * The page table mutex must be held by the caller.
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
PATCH 9/10 staging: gasket: page_table: use total_entries for max ext lvl0 page idx
In reply to Todd PoynorFrom: Nick Ewalt <[email protected]>
The maximum number of entries in the page table is configurable at initialization time and should be used in gasket_extended_lvl0_page_idx.
--- drivers/staging/gasket/gasket_page_table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/gasket/gasket_page_table.c +1 -1
@@ -562,7 +562,7 @@ static ulong gasket_extended_lvl0_page_idx(struct gasket_page_table *pg_tbl, ulong dev_addr) {return (dev_addr >>GASKET_EXTENDED_LVL0_SHIFT ) & - ((1 <<GASKET_EXTENDED_LVL0_WIDTH ) -1 ); + (pg_tbl->config.total_entries -1 ); }/*
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
PATCH 10/10 staging: gasket: page_table: handle failed dma_map_page
In reply to Todd PoynorFrom: Nick Ewalt <[email protected]>
Handle dma_map_page failing in gasket_alloc_extended_subtable: free memory, don't add invalid page table entry.
--- drivers/staging/gasket/gasket_page_table.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/staging/gasket/gasket_page_table.c +11 -0
@@ -902,6 +902,17 @@ static int gasket_alloc_extended_subtable(struct gasket_page_table *pg_tbl,/* Map the page into DMA space. */ pte->dma_addr =dma_map_page (pg_tbl->device, pte->page,0 ,PAGE_SIZE ,DMA_TO_DEVICE ); +if (dma_mapping_error (pg_tbl->device, pte->dma_addr)) { +dev_dbg (pg_tbl->device, +"%s: fail to map page [pfn %lx phys %llx]\n" , + __func__,page_to_pfn (pte->page), +page_to_phys (pte->page)); + +free_page (page_addr); +vfree (pte->sublevel); +memset (pte,0 ,sizeof (struct gasket_page_table_entry )); +return -ENOMEM ; + }/* make the addresses available to the device */ dma_addr = (pte->dma_addr + pte->offset) |GASKET_VALID_SLOT_FLAG ;
Signature · 1 line
2.19.0.397.gdd90340f6a-goog