Commit Graph

52 Commits

Author SHA1 Message Date
Jonas Larsson
64728f3114 staging: gasket: fix compilation on 5.1+
https://lore.kernel.org/patchwork/patch/1039724/

Bug: 158716452
Change-Id: I3c90a6524d3859e5518b7aece5a2817ed1f3efed
(cherry picked from commit 0aacc629f48459a1f8169120afc868cdb48f0593)
2020-06-11 19:47:07 +00:00
Waqar Hameed
3b6740a1d4 staging: gasket: Remove unused local variables
The variables "mapping" and "tmp" are unused in
gasket_page_table_unmap_dmabuf().

Signed-off-by: Waqar Hameed <waqarh@axis.com>
Change-Id: I0da67e5e91fb8c8f34b13e7227afb8410bcbc138
2020-04-17 09:38:04 -07:00
Waqar Hameed
cf41759771 staging: gasket: Fix formatting
Add a space before the open parentheses in an if-statement, to follow
Linux kernel coding style.

Signed-off-by: Waqar Hameed <waqarh@axis.com>
Change-Id: Ic6658aecdde508762117364669872d69dcb0e8e6
2020-04-17 09:37:45 -07:00
Jonas Larsson
fa575cdad7 staging: gasket: don't require all pages to be writable
Buffers to be mapped as DMA_TO_DEVICE must be writable due to the
'write' argument to get_user_pages_fast being hard coded to 1.
This prevents userspace from passing in pointers returned from
mmap(fd, PROT_READ), instead mmap(fd, PROT_READ | PROT_WRITE)
must be used even if the buffer is supposed to be read only.

Instead set writable to non zero iff direction != DMA_TO_DEVICE,
ie only buffers with DMA_FROM_DEVICE or DMA_BIDIRECTIONAL are
required to be writable.

Change-Id: I21c97b2bb855e11ecaa6ae9e81cf8b463b4aedaa
Signed-off-by: Jonas Larsson <ljonas@google.com>
2020-04-17 09:36:21 -07:00
Jonas Larsson
0d361c0493 staging: gasket: support mapping of dma-bufs.
This allows userspace to pass in dma-buf file descriptors for
mapping in addition to userspace virtual memory pointers,
leaving cache maintenance to the dma-buf exporter and userspace
application.

Bug: 149764192
Change-Id: Iee8b581db0a461fe13ee8712d47d66f8fb16e7c9
Signed-off-by: Jonas Larsson <ljonas@google.com>
2020-04-17 09:22:48 -07:00
Waqar Hameed
be43ad6a89 staging: gasket: Fix dev_addr truncation on 32-bit arch
The extended address bit is at position 63 (c.f. apex_driver.c:60). The
device address will thus not fit in a ulong on 32-bit ARM systems.
Use u64 instead.

[toddpoynor@google.com: more fixups, fix debug printk param order]
Bug: 137378503
Signed-off-by: Waqar Hameed <waqarh@axis.com>
Change-Id: If801b2b97d88c1329f3a359507e265837150571c
2019-09-23 22:43:36 +00:00
Nick Ewalt
975c81ef1d staging: gasket: cleanup extended page table map/unmap
Make sure to use dma_sync_single_for_device whenever updating the
contents of an extended page table. This performs the cache flush using
the correct function from the DMA-API. Also move this call outside of
the inner loop to improve performance.

Tested: Ran run_tests with inception, testfullyconnected with parameter
caching, and rnntransducerdecoderpie107m on AT Enterprise.

Change-Id: Ie3c63113dde8cafe448d515e8970810afc9564ac
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
2019-09-23 22:43:21 +00:00
Leonid Lobachev
0dc5779dd7 staging: gasket: Update device virtual address comment
Add that number of page table entries and extended address bit offset
are configurable. Update example virtual address format to be more
consistent with typical usage.

Change-Id: I73f9674df74b6d8ee5ed6e5d95ab12dcc56e29cc
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-09-23 22:43:12 +00:00
Leonid Lobachev
35113ccbb5 staging: gasket: page_table: handle failed dma_map_page
Handle dma_map_page failing in gasket_alloc_extended_subtable.

Change-Id: I082b0d1a44a9a7c749683cda8daea7e0920d55fc
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 22:42:44 +00:00
Leonid Lobachev
85c7608274 staging: gasket: page_table: simplify gasket_components_to_dev_address
Refactor gasket_components_to_dev_address to be faster and easier to
understand. The old implementation was unnecessarily complex and masked
the page_index for simple addresses but not extended ones. It makes the
most sense for this function to perform no such masking.

Change-Id: If5f68cb6f1bf3000a5d5b77aab89cb8e391c3cf4
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 22:42:36 +00:00
Leonid Lobachev
0963c2f012 staging: gasket: page_table: fix comment in components_to_dev_address
Change-Id: Id343101cfdcad2354adb1fc03699e826b14192bb
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 22:42:29 +00:00
Leonid Lobachev
79b8ea00a1 staging: gasket: page_table: use total_entries for max ext lvl0 page idx
The maximum number of entries in the page table is configurable at
initialization time and should be used in gasket_extended_lvl0_page_idx.

Change-Id: I39f2dba48083a3eef3951ecd9659ee9f4901275e
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 22:42:21 +00:00
Leonid Lobachev
39d3974ac0 staging: gasket: page_table: fix debug log in gasket_perform_mapping
Change-Id: I841914a6d5362073d0b85732b38f52f93a3a51b3
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 22:42:14 +00:00
Leonid Lobachev
b2c7368909 staging: gasket: cleanup if dma_map_page fails in gasket_perform_mapping
Previously pages would have never been unmapped in this case.

Change-Id: I71b6447267933865ab23a3ba3830e7ce3d3e0e57
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 22:42:06 +00:00
Leonid Lobachev
355e45e64b staging: gasket: page table: fixup error path allocating coherent mem
Correctly clean up data structure state in gasket_alloc_coherent_memory
error path, to ensure no double free on the stale pointer value.

Change-Id: Ifbc426e857d6bd05a13a725f2c2fdb07dedc098c
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 22:41:57 +00:00
Leonid Lobachev
3ef19e3777 staging: gasket: page_table: don't unmap coherent pages
Only call dma_unmap_page if there was an associated dma_map_page.

Change-Id: I6234719f8ab6b1e5e069c21e2f639eee4f22b039
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 22:41:48 +00:00
Leonid Lobachev
bcf565dc81 staging: gasket: page_table: add mapping flags
This allows for more precise dma_direction in the dma_map_page requests.
Also leaves room for adding more flags later.

Change-Id: I46feecc2638b7ad0d34548cc10837549a3928011
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 22:41:39 +00:00
Leonid Lobachev
513c6336ef staging: gasket: page_table: remove unnecessary PTE status set to free
Remove unnecessary ptes[i].status update in gasket_perform_unmapping.
The vlaue will be cleared in the following memset.

Change-Id: I5aeafa1085203b5dc24b3303037ece1f37acd6c6
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 22:41:30 +00:00
Leonid Lobachev
7e99cc991a staging: gasket: page_table: rearrange gasket_page_table_entry
Rearrange gasket_page_table entry to reduce padding slop.

Change-Id: I1dab69344bb1974de0d67028e6f638ec5a849374
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 22:41:03 +00:00
Leonid Lobachev
06938d183c staging: gasket: page_table: fix dma_data_direction
Extended page tables can be mapped as DMA_TO_DEVICE.
Calls to dma_unmap_page should match corresponding dma_map_page.

Change-Id: I2d09fd5d66c364e190b073fabe089ce5eaf426f6
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 22:40:08 +00:00
Leonid Lobachev
3e21ff65d6 staging: gasket: page table: remove dead code in coherent mem alloc
gasket_alloc_coherent_memory() has some unnecessary code related to out
of memory checking that will never hit the condition checked, remove.

Change-Id: Ifb09e7ff31d8ae41a486639a2abc6ce26c4d85ef
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 11:50:56 -07:00
Leonid Lobachev
71591a83ad staging: gasket: page table: return valid error code on map fail
Return -EINVAL on mapping failures, instead of -1, which triggers a
checkpatch error.

Change-Id: I91a62a72caa5ca09e07bd4897e72f4919495c040
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 11:49:33 -07:00
Todd Poynor
5862a44ee2 staging: gasket: page table: use GFP_KERNEL for dma_alloc_coherent
Flags should be specified for dma_alloc_coherent() call.  Use
GFP_KERNEL, it's fine to sleep here.

Change-Id: Iec4ad9550e8829b67e99b22246e40e0b21600c54
Signed-off-by: Todd Poynor <toddpoynor@google.com>
2019-09-23 11:30:36 -07:00
Nick Ewalt
ad4c9a5893 staging: gasket: fix free in gasket_free_coherent_memory_all
Actually free gasket_coherent_page_entries and just call
gasket_free_coherent_memory_all from gasket_free_coherent_memory.

Change-Id: I1d016abd5f66e0620a37f6851e43fcfd6c96868a
Signed-off-by: Nick Ewalt <nicholasewalt@google.com>
2019-09-23 11:28:33 -07:00
Jae Yoo
75b8025f7e Add arm32 compatibility into gasket driver
Add a compat_ioctl handler for arm32 and replace ulong to u64.

Bug: 115850337, 117133232
Test: label_image runs correctly.
Change-Id: Ie17244faff2aa1461397e740fba4581c6b112f30
2018-10-23 10:40:30 +09:00
Todd Poynor
e14033cdb6 staging: gasket: page table: remove extraneous memory barriers
Some explicit memory barriers in the page table code are not necessary,
either because:

(a) The barrier follows a non-relaxed MMIO access that already performs
a read or write memory barrier.

(b) The barrier follows DMA API calls for which the device-visible
effects of IOMMU programming are guaranteed to be flushed to the IOMMU
prior to the call returning, and doesn't need to sync with normal memory
access.

Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 12:23:30 -07:00
Todd Poynor
72caabea8c staging: gasket: page table: use dma_mapping_error for error detection
gasket_perform_mapping() call dma_mapping_error() to determine if
mapping failed.

Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 12:22:12 -07:00
Sumit Kumar
1fa1af899a staging: gasket: remove null ptr check before kfree
Remove null ptr check before kfree because kfree is null ptr safe.
Issue found by checkpatch.

Signed-off-by: Sumit Kumar <sumit686215@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 12:17:50 -07:00
Sumit Pundir
71f099b4c1 staging: gasket: fix code indent for conditional statement
Fixed a coding style issue related to indentation. Reported by
checkpatch.pl

Signed-off-by: Sumit Pundir <pundirsumit11@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 12:16:39 -07:00
Todd Poynor
fe87548935 Revert "staging: gasket: page table: hold references to device and pci_dev"
gasket_free_dev() is called only from driver PCI probe and remove
function. It is guaranteed that that pci_dev structure is not going
anywhere during that time; there is no need to take this additional
reference.

This reverts commit dd9d1502feea3c23d412f289aad79e1d4e86d45d.

Reported-by: Dmitry Torokhov <dtor@chromium.org>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 12:01:02 -07:00
Todd Poynor
1babb38387 staging: gasket: page table: fix function param line continuation style
Fix multi-line alignment formatting to look like:
      int ret = long_function_name(device, VARIABLE1, VARIABLE2,
                                   VARIABLE3, VARIABLE4);

Many of these TODO items were previously cleaned up during the conversion
to standard logging functions.

Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 11:57:29 -07:00
Todd Poynor
9aed73349f staging: gasket: pg tbl: remove static function forward declarations
Remove forward declarations of static functions, move code to avoid
forward references, for kernel style.

Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 11:55:02 -07:00
Todd Poynor
710158f4ca staging: gasket: page table: simplify comments for static functions
Static functions don't need kernel doc formatting, can be simplified.
Reformat comments that can be single-line.  Remove extraneous text.

Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 11:44:29 -07:00
Todd Poynor
8719d43b7b staging: gasket: page table: hold references to device and pci_dev
Hold references to the struct device and the pci_dev for the page table
while the data structures contian pointers to these.

Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 11:40:47 -07:00
Dmitriy Cherkasov
1b13804ed5 staging: gasket: use NULL instead of 0 for null pointer
Fixes sparse warning: Using plain integer as NULL pointer

Signed-off-by: Dmitriy Cherkasov <dmitriy@oss-tech.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 11:39:01 -07:00
Todd Poynor
7ad8140be7 staging: gasket: page table: remove code for "no dma_ops"
Remove code with TODOs on it for working around apparent problems
previously seen in a qemu environment where dma_ops was not set
correctly.  There is no user of this in the current code.

Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 11:37:51 -07:00
Todd Poynor
5420904bf3 staging: gasket: don't print device addresses as kernel pointers
Print device addresses as unsigned long, not as kernel pointers.

Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 11:35:06 -07:00
Todd Poynor
213eabfa36 staging: gasket: page table: convert to standard logging
Replace gasket logging calls with standard logging calls.

Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 11:30:52 -07:00
Ivan Bornyakov
eb6c6b5f48 staging: gasket: use vzalloc instead of vmalloc/memset
Use vzalloc instead of vmalloc followed by memset with 0.

Signed-off-by: Ivan Bornyakov <brnkv.i1@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 11:28:04 -07:00
Todd Poynor
f6ac13d5f3 staging: gasket: page table: remove unnecessary logs
Some error logs in page table handling code could only be hit in
cases of programming errors not expected in the current code base, and
aren't likely to be useful on their own.  Remove these.

Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 11:26:53 -07:00
Todd Poynor
31e62a1e10 staging: gasket: page table: convert various logs to debug level
Debugging information is improperly logged at non-debug log level in a
number of places, and some logs regarding error conditions may be
generated too frequently, such that these could cause performance
problems and/or obscure other logs.  Convert these to debug log level.

Signed-off-by: Zhongze Hu <frankhu@chromium.org>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 11:26:18 -07:00
Todd Poynor
d99aa15f2e staging: gasket: remove unnecessary parens in page table code
gasket_alloc_coherent_memory() extra parentheses in statement.

Reported-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Simon Que <sque@chromium.org>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 11:09:20 -07:00
Todd Poynor
35ae6935e7 staging: gasket: remove else clause after return in if clause
Else after return is unnecessary and may cause static code checkers to
complain.

Reported-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Simon Que <sque@chromium.org>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 11:08:11 -07:00
Todd Poynor
b710f906c5 staging: gasket: gasket page table functions use bool return type
Convert from int to bool return type for gasket page table functions
that return values used as booleans.

Reported-by: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Simon Que <sque@chromium.org>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-04 11:07:36 -07:00
Todd Poynor
1563830458 staging: gasket: whitespace fix in gasket_page_table_init
Tab replaced with space.

Signed-off-by: Zhongze Hu <frankhu@chromium.org>
Signed-off-by: Todd Poynor <toddpoynor@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-23 16:08:21 -07:00
Greg Kroah-Hartman
8ab2804fad staging: gasket: remove gasket_page_table_num_extended_entries()
It is exported, yet no one calls it so just remove the dead code.

Cc: Rob Springer <rspringer@google.com>
Cc: John Joseph <jnjoseph@google.com>
Cc: Ben Chan <benchan@chromium.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-23 16:08:21 -07:00
Felix Siegel
b27f5c2e98 staging: gasket: Use __func__ instead of hardcoded string - Style
Changed logging statements to use %s and __func__ instead of hard coding
the function name in a string.

Signed-off-by: Felix Siegel <felix.siegel@posteo.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-23 16:08:20 -07:00
Greg Kroah-Hartman
653a5901f5 staging: gasket: remove redundant license information
Now that the SPDX tag is in all gasket files, that identifies the
license in a specific and legally-defined manner.  So the extra GPL text
wording can be removed as it is no longer needed at all.

This is done on a quest to remove the 700+ different ways that files in
the kernel describe the GPL license text.  And there's unneeded stuff
like the address (sometimes incorrect) for the FSF which is never
needed.

Cc: Rob Springer <rspringer@google.com>
Cc: John Joseph <jnjoseph@google.com>
Cc: Ben Chan <benchan@chromium.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-23 16:08:20 -07:00
Greg Kroah-Hartman
8ff3da62cb staging: gasket: add SPDX identifiers to all files.
It's good to have SPDX identifiers in all files to make it easier to
audit the kernel tree for correct licenses.

Fix up the all of the staging gasket files to have a proper SPDX
identifier, based on the license text in the file itself.  The SPDX
identifier is a legally binding shorthand, which can be used instead of
the full boiler plate text.

Cc: Rob Springer <rspringer@google.com>
Cc: John Joseph <jnjoseph@google.com>
Cc: Ben Chan <benchan@chromium.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-23 16:08:20 -07:00
Ivan Bornyakov
cc8a3327da staging: gasket: fix plain integer as NULL pointer warning
Trivial fix to remove sparse warnings:

  drivers/staging/gasket/gasket_page_table.c:884:40: warning: Using plain integer as NULL pointer
  drivers/staging/gasket/gasket_page_table.c:1743:57: warning: Using plain integer as NULL pointer
  drivers/staging/gasket/gasket_page_table.c:1768:57: warning: Using plain integer as NULL pointer

Signed-off-by: Ivan Bornyakov <brnkv.i1@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-07-23 16:08:20 -07:00