Commit Graph

73 Commits

Author SHA1 Message Date
Shiraz Hashim 0a1dafa258 iommu: msm: Fix incorrect address list preparation
During secure map, the scatterlist is converted into a
simple array of 1MB chunk addresses. This array is then
passed to TZ. The code which does this incorrectly
increments physical base address each time, besides
adding chunk size. Fix this.

Change-Id: I82b3b4eb3b008af14450873b8d34867df81e6ca8
Signed-off-by: Shiraz Hashim <shashim@codeaurora.org>
2015-10-23 12:00:37 -07:00
Chintan Pandya c35ff72562 iommu: msm: consider only fault indicators from FSR
Bit[9] and Bit[10] of an FSR register indicates the
page table format of the context bank and can be
non-zero even if there is no fault recorded into FSR.
Only first 9 bits [8:0] indicates type of fault 'at'
the time of fault. So, fix the false positive by just
checking over fault indicator bits only.

Change-Id: Id7c37d8d0b26002156ae3b829e3a11fb7a631fed
Signed-off-by: Chintan Pandya <cpandya@codeaurora.org>
2015-05-04 16:36:46 +05:30
Chintan Pandya be3cde33e2 iommu: msm: Fix unclocked register access from fault handler
Now that non-secure CB faults also gets routed to secure
fault handler (when IOMMU is secure), we need to ensure
that custom fault handler also gets an access with clock
enabled. This was the BUG but no one earlier called
custom fault handler from secure fault handler and remained
uncaught. Fix it by maintaining clock until we return.

Also, ensure that only for valid FSR values we enter and
invoke custom fault handlers.

Change-Id: I9f883c96a8fc05409d5670c35c86301fab6c2f8c
Signed-off-by: Chintan Pandya <cpandya@codeaurora.org>
2015-05-04 16:22:32 +05:30
Vinayak Menon ab38a29dff iommu: msm: remove CONFIG_MSM_IOMMU_TLBINVAL_ON_MAP
Remove CONFIG_MSM_IOMMU_TLBINVAL_ON_MAP and the code
protected by it, since there is no known case now,
which requires a tlb invalidate during a map.

Change-Id: Ia9566dfadbb24345e4bcc66111dd0013a53e1b1c
Signed-off-by: Vinayak Menon <vinmenon@codeaurora.org>
2015-04-24 18:58:04 +05:30
Chintan Pandya d37962c71a iommu: msm: Add debug iova_to_phys in secure fault handler
Now that we route all non-secure CB fault also to the secure
fault handler, we want it to print debug info of iova_to_phys
for non-secure context banks. Add that debug feature in
secure fault handler.

Change-Id: Ie5a56c47d9e73d758daaf3d023774c32ac98dfe3
Signed-off-by: Chintan Pandya <cpandya@codeaurora.org>
2015-04-10 18:31:02 +05:30
Chintan Pandya e42549ecd2 iommu: msm: Correct the data type mis-matches in VA
MSM IOMMU driver presently supports mapping of virtual
addresses of 32-bit long only. Because of this, 32-bit
long virtual address was okay and some mis-matches were
silent. This is harmless but still buggy. Also, for
64-bit virtual address mapping, some API needs update.

Make input virtual address always 'unsigned long' and
trunk (if necessary) based on the page table format.

Change-Id: I5d761246b0e150d9a0d22a9ae25581b5205e0594
Signed-off-by: Chintan Pandya <cpandya@codeaurora.org>
2015-03-25 18:08:39 +05:30
Linux Build Service Account 4114f8ec47 Merge "drivers: iommu: Add iommu_map_sg for msm_iommu" 2015-03-18 15:04:51 -07:00
Laura Abbott b7c64d2138 drivers: iommu: Add iommu_map_sg for msm_iommu
iommu_map_sg is the newer, preferred API. Add a wrapper around
the existing map_range API for map_sg. Once all clients have been
successfully converted map_range can be removed.

Change-Id: Ib77c86f6b12b00b2bd83a4938465dc685faea624
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2015-03-12 16:58:54 -07:00
Vikram Mulukutla ed5d3ab589 iommu: msm_iommu_sec: Don't assume phys addresses can't exceed 4GB
Virtual and physical memory allocators may return buffers
that are at physical addresses higher than 4GB. When
passing addresses to TZ, don't assume otherwise. Fix the
code to not truncate down to 32 bits (the assignment operation
u64 = u32 = u64 truncates down 64 bit addresses to 32 bits)
unnecessarily; perform the assignment in two discrete steps
to allow the desc.args[X] field to store the full 64 bit
address.

Change-Id: I27ee7f17dace8f9a59712f742f6f6219825c6b82
Signed-off-by: Vikram Mulukutla <markivx@codeaurora.org>
2015-03-11 01:49:55 -07:00
Mitchel Humpherys 6084872869 iommu: msm_iommu_sec: use dma_free_attrs to match dma_alloc_attrs
Currently we're using dma_free_coherent to free a DMA allocation that
was allocated with dma_alloc_attrs.  DMA allocation and free should
always use matching attributes.  Failure to do so could result in
instabilities.  Fix this by using dma_free_attrs.  Also fix an erroneous
comment regarding the dma_alloc_attrs piece.

Change-Id: I99fed0d27b14895a5a9099944a25ef9ee1072614
Suggested-by: Joseph Chang <joechang@qti.qualcomm.com>
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2015-01-15 22:28:38 -08:00
Neeti Desai 7481e4c8e7 msm: iommu: Correct the size passed to dmac_clean_range()
The size being passed to dmac_clean_range() inside
iommu_map_range is incorrect; instead of providing the
total length of all the chunks in the chunk list, we're
currently passing the length of just one chunk. Fix this
to pass in the right length.

Change-Id: Id9f4ce9be8a21da0e037da987b3e1fbd8d81dd2f
Signed-off-by: Neeti Desai <neetid@codeaurora.org>
2014-12-10 17:17:30 -08:00
Mitchel Humpherys 27df4148a6 iommu: msm: move L2 redirect to a domain attribute
We will soon be removing the `flags' parameter from iommu_domain_alloc
and iommu_ops.domain_init. In preparation for this, move the L2 redirect
flag to a domain attribute.

We now no longer need the extra parameter to iommu_domain_alloc which
was added in [8984b0e30df: "drivers: iommu: Add flags to
iommu_domain_alloc"] since we're changing the way L2 redirect is
configured. Remove it.

Change-Id: Ie0d15767ca08211740d22568683fae01e8123a26
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2014-12-03 15:45:23 -08:00
Shubhraprakash Das f57233cd12 iommu: msm: Ensure secure buffer mapping at 1MB
Secure buffer mappings should be 1MB aligned. Add checks
for this.

CRs-Fixed: 755014
Change-Id: I377e7beaeb21cce9a828590bab20cc1cf41fd8c6
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
2014-11-18 01:17:30 -08:00
Neeti Desai cf33e37fce iommu: msm_iommu_sec: Add support for new scm_call2 API
The scm_library has added support for a new secure world
interface which is more aligned to the ARMv8 SMC calling
convention. This new api support was missing for the
dump fault register dumping code.

CRs-Fixed: 749979
Change-Id: I2b6d4f65ee6a59af677dfd109976053768de2b80
Signed-off-by: Neeti Desai <neetid@codeaurora.org>
2014-11-04 11:03:11 -08:00
Mitchel Humpherys a9ed40b162 iommu: msm_iommu_sec: fix some overeager cache maintenance
In general, we must do some cache maintenance when sharing buffers with
TZ since our caches are not shared with TZ.  Specifically:

    (1) If we put some data into a buffer then share it with TZ for
        reading, the buffer must be flushed before sending it to TZ.

    (2) If TZ puts some data in a buffer for us to read, the buffer must
        be invalidated after receiving it from TZ.

In msm_iommu_sec_ptbl_map we are currently doing some cache maintenance
incorrectly.  We are invalidating a buffer that we shared with TZ even
though we're not reading from the buffer.  We're also flushing way more
than we need to.  We're only sharing a single buffer of size
sizeof(phys_addr_t) with TZ but we're flushing the size of the IOMMU
mapping (which could be anything up to 2^sizeof(size_t)).

Remove the unnecessary invalidate and only flush the size of the buffer
being shared, nothing more.

Change-Id: I46d2d95319364d197ae530001851ab819a6eb6fa
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2014-10-23 13:07:19 -07:00
Laura Abbott 29d05c1d51 iommu: msm_iommu: Return proper value from unmap_range
unmap_range should return an error code, not just zero.
Technially the return code should be the number of bytes
unmapped but certain kernel clients spew errors because
of incorrect error handling. Until that can be filed,
return negative error codes to indicate an error.

Change-Id: Iae0b561c99edc216d3d484107be5938f3775e11d
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2014-09-15 16:37:47 -07:00
Linux Build Service Account c92a6cd0ef Merge "iommu: msm_iommu_sec: Add support for the new scm_call2 API" 2014-08-25 08:21:44 -07:00
Linux Build Service Account b41fad46e1 Merge "qcom: scm: Provide an API that restores security configuration" 2014-08-25 08:21:38 -07:00
Vikram Mulukutla 2cfe3f092b iommu: msm_iommu_sec: Add support for the new scm_call2 API
The scm library has added support for a new secure world
interface that is more aligned to the ARMv8 SMC calling
convention. Use the new API while maintaining backward
compatibility.

Change-Id: Ib2a52aebf28ff4cb215d0726822411dde0c075ab
Signed-off-by: Vikram Mulukutla <markivx@codeaurora.org>
2014-08-22 15:33:12 -07:00
Vikram Mulukutla 9933a272db qcom: scm: Provide an API that restores security configuration
Drivers require an API to be able to inform the secure world
that their devices have resumed from power collapse and security
settings need to be re-relaxed.

Transition existing users to the new API.

Change-Id: Ia5b49176c797ec9d6d35350ea98964203d622516
Signed-off-by: Vikram Mulukutla <markivx@codeaurora.org>
2014-08-22 15:33:10 -07:00
Neeti Desai 21e5bca71b msm_iommu: Check for NULL pointer in msm_detach_dev
The device struct may be passed as NULL into the msm_detach_dev
function. Add check to prevent NULL pointer dereferencing.

Change-Id: I4123b60969358cd4ff9ad20b76257405aacc4257
Signed-off-by: Neeti Desai <neetid@codeaurora.org>
2014-08-18 16:57:36 -07:00
Linux Build Service Account a7ec2e7aa9 Merge "iommu: msm: Do not invalidate the TLB during iommu map" 2014-08-01 04:54:00 -07:00
Chintan Pandya d1832a566e iommu: msm: drop usage of arch specific cache line size
cache_line_size() may not be a static number for every
architecture but dynamically calculated size. Instead
use higher alignment of PAGE_SIZE for temporary
allocations.

Change-Id: Ib8a730a7f5eca650a5a98f20532ffeaa3b647491
Signed-off-by: Chintan Pandya <cpandya@codeaurora.org>
2014-07-31 15:00:19 +05:30
Neeti Desai 704097123c iommu: msm: Do not invalidate the TLB during iommu map
Due to a hardware bug the TLB has to be invalidated
during map and map_range operations. Newer targets
no longer see this issue. Add config option
to invalidate the TLB only for older targets.

Change-Id: I5bbe84e9dde23bcf960cf5409eed41c6cea41c16
Signed-off-by: Neeti Desai <neetid@codeaurora.org>
2014-07-28 12:36:59 -07:00
Neha Atri 1bd424de5e gpu: ion: add ftrace events for secure calls
Track secure heap allocations for debug purposes.

Change-Id: I1810fce8c48e6420a97bb9f3ac9dde19792e7903
CRs-Fixed: 686802
Signed-off-by: Neha Atri <natri@codeaurora.org>
2014-07-10 16:54:09 -07:00
Chintan Pandya 8e4ee38c07 iommu: msm: Fix for cache invalidation variance
In some architectures (at least observed on
Cortex-A53), CPU cache invalidation is not just pure
invalidation but clean + invalidation. If the cache
lines are *dirty*, then first clean will happen and DDR
gets updated with cached content and then invalidation
will be performed.

According to the above specification, we cannot just
handover buffer to non-Linux entity before cleaning its
CPU cache lines. Because, later invalidation will
overwrite the DDR content written by non-Linux.

Fix this by doing clean with proper range.

Change-Id: I8b3c6d13961e9e966a2241d5372584f59bdfbcf0
Signed-off-by: Chintan Pandya <cpandya@codeaurora.org>
2014-05-31 13:25:39 +05:30
Chintan Pandya f5ce1f2e14 iommu: msm: fix secure fault handler debug logs
Present debug log mechanism of secure context bank fault
handler doesn't behave well when it tries to obtain
register dumps from secure environment and fails to get a
sane response.

It is observed that the secure environment doesn't fill up
the register dump structure passed by the kernel correctly.
This leads to secure fault handler constantly dumping
default initialized values for these register making no
sense.

This patch intends to address this issue and fixes
following.

   * initialize dump holding structure and response variable
     to 0
   * return IRQ_NONE and do not proceed if secure
     environment response is 0 length
   * replace incorrect CB register address prints by
     actual context numbers and register offsets.

Change-Id: I07f329fd5dcb4fc56f7bb9a6dc182b73b806005c
Signed-off-by: Chintan Pandya <cpandya@codeaurora.org>
2014-05-28 17:06:00 +05:30
Chintan Pandya 0624c3128e iommu: msm: Enable aggregated CB interrupts for secure SMMUs also
Present logic of enabling aggregated CB interrupts works only
for non-secure SMMUs. Improvise that logic to enable interrupts
for secure SMMUs also.

Change-Id: I77f914de760562ce30b7ade512a12639eb84af6d
Signed-off-by: Chintan Pandya <cpandya@codeaurora.org>
2014-03-12 07:19:30 +05:30
Laura Abbott feedc93dc0 iommu: msm: Use dma memory for secure pagetable
Linux allocates memory for secure page tables which is passed to the secure
world. This memory is later protected from reads/writes from Linux. Using
kmalloc for this memory may allow speculative accesses to occur to
secured memory. Avoid speculative faults by using dma_alloc_coherent
with the NO_KERNEL_MAPPING attribute to avoid a non-secure mapping.

Change-Id: I3fcd82b2a1e5b82442641961c70306560ee778d8
CRs-Fixed: 621723
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2014-03-07 12:23:56 -08:00
Larry Bassel 9435beaa25 iommu: move iommu header files to new locations
Header files are no longer allowed in the directory
arch/arm/mach-msm/include/mach/ .

Move the iommu related header files to a more suitable place.

Change-Id: Ib7bbce1485d6185f669935b507040cac75368985
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>
2014-03-03 12:28:12 -08:00
Larry Bassel 76c5d9e1d9 iommu: clean up includes
The file mach/msm_bus.h should not be included,
instead the file linux/msm-bus.h should be.
Also remove an unneeded include.

Change-Id: I6e060739977f8604409f660c72c9a983eaddfa45
Signed-off-by: Larry Bassel <lbassel@codeaurora.org>
2014-02-25 16:24:17 -08:00
Olav Haugan 9916f48440 iommu: msm: Make VFE SMMU conditionally secure
VFE SMMU needs to be secure for new secure camera use
cases. Change the VFE to be secure and designate the
last context bank (CB) as secure. Also ensure backwards
compatability so that when running with old secure environment
we fall back to VFE SMMU being non-secure.

Change-Id: I25f31b0350ef0c1b16ebb0db531cc0e6bc556fcf
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2014-02-19 17:20:53 -08:00
Linux Build Service Account c31c51e967 Merge "iommu: msm: allow partial register dumps to be printed" 2014-02-13 02:17:40 -08:00
Linux Build Service Account a22be18036 Merge "iommu: msm: dump some global registers on page faults" 2014-02-13 02:17:35 -08:00
Linux Build Service Account b960e11646 Merge "iommu: msm: simplify address discovery in secure register dump code" 2014-02-13 02:17:07 -08:00
Linux Build Service Account e9360c2da9 Merge "iommu: msm: always use 32-bit physical addresses" 2014-02-13 02:17:00 -08:00
Mitchel Humpherys 854878cbfc iommu: msm: allow partial register dumps to be printed
If we get back a partial register dump from TZ we should go ahead and
print as much as we can, rather than bailing out and not printing
anything.

Change-Id: Idcc8b14a76bf1f23bdf00b52879b3ce0ca9afdcc
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2014-02-11 17:41:33 -08:00
Mitchel Humpherys b6cc994641 iommu: msm: dump some global registers on page faults
Add support for dumping registers from the global register space. Dump
CBAR_N and CBFRSYNRA_N.

Change-Id: If20605968fac75ad791d4e63e4d089ecaf8f7ebd
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2014-02-11 17:00:19 -08:00
Mitchel Humpherys eea2a9eaa1 iommu: msm: simplify address discovery in secure register dump code
Currently in the secure register dump code, we try to determine the
register in question by doing some reverse arithmetic on the full
address that TZ returns and matching that against known register
offsets. However, support was recently added for storing the base
physical address of the Iommu in `struct msm_iommu_drvdata'. Simplify
the code by calculating the offset of the registers being returned by TZ
by subtracting their values from the base address of the Iommu.

Change-Id: Icd6e4a35a48b808b0523ab4971cb9fb5b00125f5
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2014-02-11 16:07:16 -08:00
Mitchel Humpherys cf1464f7b9 iommu: msm: always use 32-bit physical addresses
TZ expects the physical address of the destination dump buffer to be
32-bits, even on LPAE targets. Always send a 32-bit integer. This
requires truncating the top 4 bytes of a 64-bit physical address, but
this shouldn't be a problem on current targets since all physical
addresses should be <4GB.

Change-Id: I486ed39e132be46ebfc80335024cb8d31d7ac1c2
Signed-off-by: Mitchel Humpherys <mitchelh@codeaurora.org>
2014-02-11 16:07:16 -08:00
Laura Abbott b86285d257 iommu: msm: Use standard caching APIs
There's no need to have cache wrappers anymore.
Call the appropriate cache API directly.

Change-Id: If31002ef8b3a6598700c2c59ca9a5cc19a188da6
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2014-02-11 09:47:08 -08:00
Chintan Pandya 8d5b1a4ea1 iommu: msm: Remove double programming on IMPL DFND registers
Implementation defined registers are now shifted to BFB registers
data. So, remove additional register writes to them.

Change-Id: Ic53c8c9c605aded616ffdc15b0b596105890a25d
Signed-off-by: Chintan Pandya <cpandya@codeaurora.org>
2014-02-06 12:13:20 +05:30
Neeti Desai 38ae91ef11 iommu: msm: Program non secure registers only in non secure environment
The non secure registers in IOMMU are programmed when
CONFIG_IOMMU_NON_SECURE is enabled. The programming of these registers
is no longer dependent on this config, but depends on a check to see
if the secure environment is available.

CONFIG_IOMMU_NON_SECURE is now only used to force all SMMUs to be
programmed by the Linux kernel SMMU driver for debugging purposes.

Change-Id: I367f92fd6e5198395b83e6ca8acde66b1b012620
Signed-off-by: Neeti Desai <neetid@codeaurora.org>
2014-01-28 08:55:46 -08:00
Vikram Mulukutla 1e635c644a msm: scm: Move the scm driver to drivers/soc/qcom
Architectural changes in the ARM Linux kernel tree mandate
the eventual removal of the mach-* directories. Move the
scm driver to drivers/soc/qcom and the scm header to
include/soc/qcom to support that removal.

Change-Id: Ie660d0566de35045c1ba73fcddeda99efacf057e
Signed-off-by: Vikram Mulukutla <markivx@codeaurora.org>
2014-01-24 11:49:11 -08:00
Chintan Pandya 52f75ed730 iommu: msm: Create secure page tables for SMMUv2 also
Secure page tables for SMMUs only look up for SMMUv1. Support
SMMUv2 also.

Change-Id: I802b7e3b8da8311c8f501ea939f66bd48f5649fd
Signed-off-by: Chintan Pandya <cpandya@codeaurora.org>
2014-01-23 17:14:16 +05:30
Laura Abbott 23bf65df71 iommu: msm: Add call to set maximum mapped size
In some cases, the secure world needs a hint as to the maximum
amount of memory that will ever be mapped. This is necessary to
optimize data structures in the secure world. Add a call to the
secure world to indicate the maximum mapped size.

Change-Id: I8d07ec2288e37057ff96777c96ed0680f75185f3
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2014-01-06 14:48:50 -08:00
Kumar Gala 2c6104b677 msm: iommu: Rename "qti" device tree prefix back to "qcom"
Rename properties and compatible strings to return to the old
naming convention.

Change-Id: I90c673e150bebf26dc0882416ece6bb7c36b98b8
Signed-off-by: Kumar Gala <galak@codeaurora.org>
2013-12-27 13:49:44 -06:00
Chintan Pandya a6490845dc msm: Change vendor name from 'qcom' to 'qti' for iommu
As we have recently moved to use 'qti' as vendor name,
reflect that change for all the code related to iommu,
including version 0 and 1.

Change-Id: If67f2a778c64fc5c49f7b07e19ec31fb0cda8d52
Signed-off-by: Chintan Pandya <cpandya@codeaurora.org>
2013-11-27 15:34:31 +05:30
Olav Haugan f472e82309 iommu: msm: Refactor use of remote spinlock
The remote spinlock was originally meant to synchronize access between
GPU and CPU accessing SMMU. However, there are more use cases that
this remote spinlock serves. This change decouples the spinlock from
GPU and adds support for taking the spinlock only for SMMUs that are
specified in the device tree.

CRs-fixed: 517873
Change-Id: Ic50992d0d1a102fbd05855e09e254e627f99ec33
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
2013-10-02 10:41:52 -07:00
Laura Abbott a2e52222a8 msm: iommu: Set reserved bits for IOMMU hardware
There are several hardware private bits that are required for
proper operations of IOMMU hardware blocks. Set those bits
appropriately.

Change-Id: I60bf08dc71f7081c03ac8b271e651714b70d26c7
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
2013-09-12 15:28:40 -07:00