* [PATCH 01/10] staging: gasket: Kconfig: describe Apex as an Edge TPU device
2018-09-17 12:38 [PATCH 00/10] staging: gasket: Apex uncloaks, plus fixes Todd Poynor
@ 2018-09-17 12:38 ` Todd Poynor
2018-09-17 12:38 ` [PATCH 02/10] staging: gasket: interrupt: remove PCI-MSIX-specific status check Todd Poynor
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Todd Poynor @ 2018-09-17 12:38 UTC (permalink / raw)
To: Rob Springer, Ben Chan, Greg Kroah-Hartman
Cc: devel, linux-kernel, Todd Poynor
From: Todd Poynor <toddpoynor@google.com>
Add a brief description and URL for more information on the Apex device,
an Edge TPU (Tensorflow Processing Unit) machine learning accelerator.
Signed-off-by: Todd Poynor <toddpoynor@google.com>
---
drivers/staging/gasket/Kconfig | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/gasket/Kconfig b/drivers/staging/gasket/Kconfig
index 970e299046c37..e82b85541f7ef 100644
--- a/drivers/staging/gasket/Kconfig
+++ b/drivers/staging/gasket/Kconfig
@@ -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".
--
2.19.0.397.gdd90340f6a-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 02/10] staging: gasket: interrupt: remove PCI-MSIX-specific status check
2018-09-17 12:38 [PATCH 00/10] staging: gasket: Apex uncloaks, plus fixes Todd Poynor
2018-09-17 12:38 ` [PATCH 01/10] staging: gasket: Kconfig: describe Apex as an Edge TPU device Todd Poynor
@ 2018-09-17 12:38 ` Todd Poynor
2018-09-17 12:38 ` [PATCH 03/10] staging: gasket: page table: use GFP_KERNEL for dma_alloc_coherent Todd Poynor
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Todd Poynor @ 2018-09-17 12:38 UTC (permalink / raw)
To: Rob Springer, Ben Chan, Greg Kroah-Hartman
Cc: devel, linux-kernel, Todd Poynor
From: Todd Poynor <toddpoynor@google.com>
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.
Signed-off-by: Todd Poynor <toddpoynor@google.com>
---
drivers/staging/gasket/gasket_interrupt.c | 5 -----
1 file changed, 5 deletions(-)
diff --git a/drivers/staging/gasket/gasket_interrupt.c b/drivers/staging/gasket/gasket_interrupt.c
index 2cd262be65ca0..49d47afad64fa 100644
--- a/drivers/staging/gasket/gasket_interrupt.c
+++ b/drivers/staging/gasket/gasket_interrupt.c
@@ -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,
--
2.19.0.397.gdd90340f6a-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 03/10] staging: gasket: page table: use GFP_KERNEL for dma_alloc_coherent
2018-09-17 12:38 [PATCH 00/10] staging: gasket: Apex uncloaks, plus fixes Todd Poynor
2018-09-17 12:38 ` [PATCH 01/10] staging: gasket: Kconfig: describe Apex as an Edge TPU device Todd Poynor
2018-09-17 12:38 ` [PATCH 02/10] staging: gasket: interrupt: remove PCI-MSIX-specific status check Todd Poynor
@ 2018-09-17 12:38 ` Todd Poynor
2018-09-17 12:38 ` [PATCH 04/10] staging: gasket: fix DMA direction for extended page tables Todd Poynor
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Todd Poynor @ 2018-09-17 12:38 UTC (permalink / raw)
To: Rob Springer, Ben Chan, Greg Kroah-Hartman
Cc: devel, linux-kernel, Todd Poynor
From: Todd Poynor <toddpoynor@google.com>
Flags should be specified for dma_alloc_coherent() call. Use
GFP_KERNEL, it's fine to sleep here.
Signed-off-by: Todd Poynor <toddpoynor@google.com>
---
drivers/staging/gasket/gasket_page_table.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c
index 53492f4fad6aa..71b77da2e18ca 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -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;
--
2.19.0.397.gdd90340f6a-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 04/10] staging: gasket: fix DMA direction for extended page tables
2018-09-17 12:38 [PATCH 00/10] staging: gasket: Apex uncloaks, plus fixes Todd Poynor
` (2 preceding siblings ...)
2018-09-17 12:38 ` [PATCH 03/10] staging: gasket: page table: use GFP_KERNEL for dma_alloc_coherent Todd Poynor
@ 2018-09-17 12:38 ` Todd Poynor
2018-09-17 12:39 ` [PATCH 05/10] staging: gasket: fix data page unmap DMA direction Todd Poynor
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Todd Poynor @ 2018-09-17 12:38 UTC (permalink / raw)
To: Rob Springer, Ben Chan, Greg Kroah-Hartman
Cc: devel, linux-kernel, Nick Ewalt, Todd Poynor
From: Nick Ewalt <nicholasewalt@google.com>
Extended page tables should be mapped as DMA_TO_DEVICE, not
bi-directional.
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
---
drivers/staging/gasket/gasket_page_table.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c
index 71b77da2e18ca..e86bdc5fc79d2 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -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;
--
2.19.0.397.gdd90340f6a-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 05/10] staging: gasket: fix data page unmap DMA direction
2018-09-17 12:38 [PATCH 00/10] staging: gasket: Apex uncloaks, plus fixes Todd Poynor
` (3 preceding siblings ...)
2018-09-17 12:38 ` [PATCH 04/10] staging: gasket: fix DMA direction for extended page tables Todd Poynor
@ 2018-09-17 12:39 ` Todd Poynor
2018-09-17 12:39 ` [PATCH 06/10] staging: gasket: page_table: don't unmap coherent pages Todd Poynor
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Todd Poynor @ 2018-09-17 12:39 UTC (permalink / raw)
To: Rob Springer, Ben Chan, Greg Kroah-Hartman
Cc: devel, linux-kernel, Nick Ewalt, Todd Poynor
From: Nick Ewalt <nicholasewalt@google.com>
The DMA direction supplied to dma_unmap_page should match the
corresponding dma_map_page call, which is mapped bi-directional.
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
---
drivers/staging/gasket/gasket_page_table.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c
index e86bdc5fc79d2..8fe27e7d1b53c 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -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;
--
2.19.0.397.gdd90340f6a-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 06/10] staging: gasket: page_table: don't unmap coherent pages
2018-09-17 12:38 [PATCH 00/10] staging: gasket: Apex uncloaks, plus fixes Todd Poynor
` (4 preceding siblings ...)
2018-09-17 12:39 ` [PATCH 05/10] staging: gasket: fix data page unmap DMA direction Todd Poynor
@ 2018-09-17 12:39 ` Todd Poynor
2018-09-17 12:39 ` [PATCH 07/10] staging: gasket: fix gasket_free_coherent_memory metadata frees Todd Poynor
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Todd Poynor @ 2018-09-17 12:39 UTC (permalink / raw)
To: Rob Springer, Ben Chan, Greg Kroah-Hartman
Cc: devel, linux-kernel, Nick Ewalt, Todd Poynor
From: Nick Ewalt <nicholasewalt@google.com>
Only call dma_unmap_page if there was an associated dma_map_page call.
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
---
drivers/staging/gasket/gasket_page_table.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c
index 8fe27e7d1b53c..33d98043953a5 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -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);
}
--
2.19.0.397.gdd90340f6a-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 07/10] staging: gasket: fix gasket_free_coherent_memory metadata frees
2018-09-17 12:38 [PATCH 00/10] staging: gasket: Apex uncloaks, plus fixes Todd Poynor
` (5 preceding siblings ...)
2018-09-17 12:39 ` [PATCH 06/10] staging: gasket: page_table: don't unmap coherent pages Todd Poynor
@ 2018-09-17 12:39 ` Todd Poynor
2018-09-17 12:39 ` [PATCH 08/10] staging: gasket: cleanup if dma_map_page fails in gasket_perform_mapping Todd Poynor
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Todd Poynor @ 2018-09-17 12:39 UTC (permalink / raw)
To: Rob Springer, Ben Chan, Greg Kroah-Hartman
Cc: devel, linux-kernel, Nick Ewalt, Todd Poynor
From: Nick Ewalt <nicholasewalt@google.com>
Free gasket_coherent_page_entries metadata memory, update data
structures accordingly.
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
---
drivers/staging/gasket/gasket_page_table.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c
index 33d98043953a5..c1ce8f984f8e0 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -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;
}
--
2.19.0.397.gdd90340f6a-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 08/10] staging: gasket: cleanup if dma_map_page fails in gasket_perform_mapping
2018-09-17 12:38 [PATCH 00/10] staging: gasket: Apex uncloaks, plus fixes Todd Poynor
` (6 preceding siblings ...)
2018-09-17 12:39 ` [PATCH 07/10] staging: gasket: fix gasket_free_coherent_memory metadata frees Todd Poynor
@ 2018-09-17 12:39 ` Todd Poynor
2018-09-17 12:39 ` [PATCH 09/10] staging: gasket: page_table: use total_entries for max ext lvl0 page idx Todd Poynor
2018-09-17 12:39 ` [PATCH 10/10] staging: gasket: page_table: handle failed dma_map_page Todd Poynor
9 siblings, 0 replies; 11+ messages in thread
From: Todd Poynor @ 2018-09-17 12:39 UTC (permalink / raw)
To: Rob Springer, Ben Chan, Greg Kroah-Hartman
Cc: devel, linux-kernel, Nick Ewalt, Todd Poynor
From: Nick Ewalt <nicholasewalt@google.com>
Previously pages would have never been unmapped in this case.
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
---
drivers/staging/gasket/gasket_page_table.c | 33 +++++++++++++---------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c
index c1ce8f984f8e0..779ad2f23ef9b 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -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.
--
2.19.0.397.gdd90340f6a-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 09/10] staging: gasket: page_table: use total_entries for max ext lvl0 page idx
2018-09-17 12:38 [PATCH 00/10] staging: gasket: Apex uncloaks, plus fixes Todd Poynor
` (7 preceding siblings ...)
2018-09-17 12:39 ` [PATCH 08/10] staging: gasket: cleanup if dma_map_page fails in gasket_perform_mapping Todd Poynor
@ 2018-09-17 12:39 ` Todd Poynor
2018-09-17 12:39 ` [PATCH 10/10] staging: gasket: page_table: handle failed dma_map_page Todd Poynor
9 siblings, 0 replies; 11+ messages in thread
From: Todd Poynor @ 2018-09-17 12:39 UTC (permalink / raw)
To: Rob Springer, Ben Chan, Greg Kroah-Hartman
Cc: devel, linux-kernel, Nick Ewalt, Todd Poynor
From: Nick Ewalt <nicholasewalt@google.com>
The maximum number of entries in the page table is configurable at
initialization time and should be used in gasket_extended_lvl0_page_idx.
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
---
drivers/staging/gasket/gasket_page_table.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c
index 779ad2f23ef9b..8364b49f147c2 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -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);
}
/*
--
2.19.0.397.gdd90340f6a-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 10/10] staging: gasket: page_table: handle failed dma_map_page
2018-09-17 12:38 [PATCH 00/10] staging: gasket: Apex uncloaks, plus fixes Todd Poynor
` (8 preceding siblings ...)
2018-09-17 12:39 ` [PATCH 09/10] staging: gasket: page_table: use total_entries for max ext lvl0 page idx Todd Poynor
@ 2018-09-17 12:39 ` Todd Poynor
9 siblings, 0 replies; 11+ messages in thread
From: Todd Poynor @ 2018-09-17 12:39 UTC (permalink / raw)
To: Rob Springer, Ben Chan, Greg Kroah-Hartman
Cc: devel, linux-kernel, Nick Ewalt, Todd Poynor
From: Nick Ewalt <nicholasewalt@google.com>
Handle dma_map_page failing in gasket_alloc_extended_subtable: free
memory, don't add invalid page table entry.
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
---
drivers/staging/gasket/gasket_page_table.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/staging/gasket/gasket_page_table.c b/drivers/staging/gasket/gasket_page_table.c
index 8364b49f147c2..964146f0df526 100644
--- a/drivers/staging/gasket/gasket_page_table.c
+++ b/drivers/staging/gasket/gasket_page_table.c
@@ -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;
--
2.19.0.397.gdd90340f6a-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread