2016-02-19 04:16:12 +00:00
|
|
|
/* Copyright (c) 2010-2012, 2016, The Linux Foundation. All rights reserved.
|
|
|
|
*
|
2010-08-25 01:31:10 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 and
|
|
|
|
* only version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/iommu.h>
|
2011-02-25 02:00:39 +00:00
|
|
|
#include <linux/clk.h>
|
2011-08-12 02:45:23 +00:00
|
|
|
#include <linux/scatterlist.h>
|
2010-08-25 01:31:10 +00:00
|
|
|
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
#include <asm/sizes.h>
|
|
|
|
|
|
|
|
#include <mach/iommu_hw-8xxx.h>
|
|
|
|
#include <mach/iommu.h>
|
2012-11-07 23:02:56 +00:00
|
|
|
#include <mach/msm_smsm.h>
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2010-11-16 02:20:08 +00:00
|
|
|
#define MRC(reg, processor, op1, crn, crm, op2) \
|
|
|
|
__asm__ __volatile__ ( \
|
|
|
|
" mrc " #processor "," #op1 ", %0," #crn "," #crm "," #op2 "\n" \
|
|
|
|
: "=r" (reg))
|
|
|
|
|
|
|
|
#define RCP15_PRRR(reg) MRC(reg, p15, 0, c10, c2, 0)
|
|
|
|
#define RCP15_NMRR(reg) MRC(reg, p15, 0, c10, c2, 1)
|
|
|
|
|
2011-11-08 23:24:53 +00:00
|
|
|
/* Sharability attributes of MSM IOMMU mappings */
|
|
|
|
#define MSM_IOMMU_ATTR_NON_SH 0x0
|
|
|
|
#define MSM_IOMMU_ATTR_SH 0x4
|
|
|
|
|
|
|
|
/* Cacheability attributes of MSM IOMMU mappings */
|
|
|
|
#define MSM_IOMMU_ATTR_NONCACHED 0x0
|
|
|
|
#define MSM_IOMMU_ATTR_CACHED_WB_WA 0x1
|
|
|
|
#define MSM_IOMMU_ATTR_CACHED_WB_NWA 0x2
|
|
|
|
#define MSM_IOMMU_ATTR_CACHED_WT 0x3
|
|
|
|
|
|
|
|
|
2013-04-19 19:45:03 +00:00
|
|
|
static int msm_iommu_unmap_range(struct iommu_domain *domain, unsigned int va,
|
|
|
|
unsigned int len);
|
|
|
|
|
msm: kgsl: implement server-side waits
msm: kgsl: Add device init function
Some device specific parameters need to be setup only once during
device initialization. Create an init function for this purpose
rather than re-doing this init everytime the device is started.
Change-Id: I45c7fcda8d61fd2b212044c9167b64f793eedcda
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 2nd commit message:
msm: kgsl: improve active_cnt and ACTIVE state management
Require any code path which intends to touch the hardware
to take a reference on active_cnt with kgsl_active_count_get()
and release it with kgsl_active_count_put() when finished.
These functions now do the wake / sleep steps that were
previously handled by kgsl_check_suspended() and
kgsl_check_idle().
Additionally, kgsl_pre_hwaccess() will no longer turn on
the clocks, it just enforces via BUG_ON that the clocks
are enabled before a register is touched.
Change-Id: I31b0d067e6d600f0228450dbd73f69caa919ce13
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 3rd commit message:
msm: kgsl: Sync memory with CFF from places where it was missing
Before submitting any indirect buffer to GPU via the ringbuffer,
the indirect buffer memory should be synced with CFF so that the
CFF capture will be complete. Add the syncing of memory with CFF
in places where this was missing
Change-Id: I18f506dd1ab7bdfb1a68181016e6f661a36ed5a2
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 4th commit message:
msm: kgsl: Export some kgsl-core functions to EXPORT_SYMBOLS
Export some functions in the KGSL core driver so they can
be seen by the leaf drivers.
Change-Id: Ic0dedbad5dbe562c2e674f8e885a3525b6feac7b
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 5th commit message:
msm: kgsl: Send the right IB size to adreno_find_ctxtmem
adreno_find_ctxtmem expects byte lengths and we were sending it
dword lengths which was about as effective as you would expect.
Change-Id: Ic0dedbad536ed377f6253c3a5e75e5d6cb838acf
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 6th commit message:
msm: kgsl: Add 8974 default GPR0 & clk gating values
Add correct clock gating values for A330, A305 and A320.
Add generic function to return the correct default clock
gating values for the respective gpu. Add default GPR0
value for A330.
Change-Id: I039e8e3622cbda04924b0510e410a9dc95bec598
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 7th commit message:
msm: kgsl: Move A3XX VBIF settings decision to a table
The vbif selection code is turning into a long series of if/else
clauses. Move the decision to a look up table that will be easier
to update and maintain when when we have eleventy A3XX GPUs.
Change-Id: Ic0dedbadd6b16734c91060d7e5fa50dcc9b8774d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 8th commit message:
msm: kgsl: Update settings for the A330v2 GPU in 8972v2
The new GPU spin in 8974v2 has some slightly different settings
then the 8974v1: add support for identifying a v2 spin, add a new
table of VBIF register settings and update the clock gating
registers.
Change-Id: Ic0dedbad22bd3ed391b02f6327267cf32f17af3d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 9th commit message:
msm: kgsl: Fix compilation errors when CFF is turned on
Fix the compilation errors when option MSM_KGSL_CFF_DUMP option
is turned on.
Change-Id: I59b0a7314ba77e2c2fef03338e061cd503e88714
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 10th commit message:
msm: kgsl: Convert the Adreno GPU cycle counters to run free
In anticipation of allowing multiple entities to share access to the
performance counters; make the few performance counters that KGSL
uses run free.
Change-Id: Ic0dedbadbefb400b04e4f3552eed395770ddbb7b
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 11th commit message:
msm: kgsl: Handle a possible ringbuffer allocspace error
In the GPU specific start functions, account for the possibility
that ringbuffer allocation routine might return NULL.
Change-Id: Ic0dedbadf6199fee78b6a8c8210a1e76961873a0
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 12th commit message:
msm: kgsl: Add a new API to allow sharing of GPU performance counters
Adreno uses programmable performance counters, meaning that while there
are a limited number of physical counters each counter can be programmed
to count a vast number of different measurements (we refer to these as
countables). This could cause problems if multiple apps want to use
the performance counters, so this API and infrastructure allows the
counters to be safely shared.
The kernel tracks which countable is selected for each of the physical
counters for each counter group (where groups closely match hardware
blocks). If the desired countable is already in use, or there is an
open physical counter, then the process is allowed to use the counter.
The get ioctl reserves the counter and returns the dword offset of the
register associated with that physical counter. The put ioctl
releases the physical counter. The query ioctl gets the countables
used for all of the counters in the block - up to 8 values can be
returned. The read ioctl gets the current hardware value in the counter
Change-Id: Ic0dedbadae1dedadba60f8a3e685e2ce7d84fb33
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
# This is the 13th commit message:
msm: kgsl: Print the nearest active GPU buffers to a faulting address
Print the two active GPU memory entries that bracket a faulting GPU
address. This will help diagnose premature frees and buffer ovverruns.
Check if the faulting GPU address was freed by the same process.
Change-Id: Ic0dedbadebf57be9abe925a45611de8e597447ea
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Vladimir Razgulin <vrazguli@codeaurora.org>
# This is the 14th commit message:
msm: kgsl: Remove an uneeded register write for A3XX GPUs
A3XX doesn't have the MH block and so the register at 0x40 points
somewhere else. Luckily the write was harmless but remove it anyway.
Change-Id: Ic0dedbadd1e043cd38bbaec8fcf0c490dcdedc8c
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 15th commit message:
msm: kgsl: clean up iommu/gpummu protflag handling
Make kgsl_memdesc_protflags() return the correct type of flags
for the type of mmu being used. Query the memdesc with this
function in kgsl_mmu_map(), rather than passing in the
protflags. This prevents translation at multiple layers of
the code and makes it easier to enforce that the mapping matches
the allocation flags.
Change-Id: I2a2f4a43026ae903dd134be00e646d258a83f79f
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 16th commit message:
msm: kgsl: remove kgsl_mem_entry.flags
The two flags fields in kgsl_memdesc should be enough for
anyone. Move the only flag using kgsl_mem_entry, the
FROZEN flag for snapshot procesing, to use kgsl_memdesc.priv.
Change-Id: Ia12b9a6e6c1f5b5e57fa461b04ecc3d1705f2eaf
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 17th commit message:
msm: kgsl: map the guard page readonly on the iommu
The guard page needs to be readable by the GPU, due to
a prefetch range issue, but it should never be writable.
Change the page fault message to indicate if nearby
buffers have a guard page.
Change-Id: I3955de1409cbf4ccdde92def894945267efa044d
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 18th commit message:
msm: kgsl: Add support for VBIF and VBIF_PWR performance counters
These 2 counter groups are also "special cases" that require
different programming sequences.
Change-Id: I73e3e76b340e6c5867c0909b3e0edc78aa62b9ee
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 19th commit message:
msm: kgsl: Only allow two counters for VBIF performance counters
There are only two VBIF counter groups so validate that the user
doesn't pass in > 1 and clean up the if/else clause.
Change-Id: Ic0dedbad3d5a54e4ceb1a7302762d6bf13b25da1
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 20th commit message:
msm: kgsl: Avoid an array overrun in the perfcounter API
Make sure the passed group is less than the size of the list of
performance counters.
Change-Id: Ic0dedbadf77edf35db78939d1b55a05830979f85
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 21st commit message:
msm: kgsl: Don't go to slumber if active_count is non zero
If active_cnt happens to be set when we go into
kgsl_early_suspend_driver() then don't go to SLUMBER. This
avoids trouble if we come back and and try to access the
hardware while it is off.
Change-Id: Ic0dedbadb13514a052af6199c8ad1982d7483b3f
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 22nd commit message:
msm: kgsl: Enable HLSQ registers in snapshot when available
Reading the HLSQ registers during a GPU hang recovery might cause
the device to hang depending on the state of the HLSQ block.
Enable the HLSQ register reads when we know that they will
succeed.
Change-Id: I69f498e6f67a15328d1d41cc64c43d6c44c54bad
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 23rd commit message:
msm: kgsl: snapshot: Don't keep parsing indirect buffers on failure
Stop parsing an indirect buffer if an error is encountered (such as
a missing buffer). This is a pretty good indication that the buffers
are not reliable and the further the parser goes with a unreliable
buffer the more likely it is to get confused.
Change-Id: Ic0dedbadf28ef374c9afe70613048d3c31078ec6
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 24th commit message:
msm: kgsl: snapshot: Only push the last IB1 and IB2 in the static space
Some IB1 buffers have hundreds of little IB2 buffers and only one of them
will actually be interesting enough to push into the static space. Only
push the last executed IB1 and IB2 into the static space.
Change-Id: Ic0dedbad26fb30fb5bf90c37c29061fd962dd746
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 25th commit message:
msm: kgsl: Save the last active context in snapshot
Save the last active context that was executing when the hang happened
in snapshot.
Change-Id: I2d32de6873154ec6c200268844fee7f3947b7395
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 26th commit message:
msm: kgsl: In snapshot track a larger object size if address is same
If the object being tracked has the same address as a previously
tracked object then only track a single object with larger size
as the smaller object will be a part of the larger one anyway.
Change-Id: I0e33bbaf267bc0ec580865b133917b3253f9e504
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 27th commit message:
msm: kgsl: Track memory address from 2 additional registers
Add tracking of memory referenced by VS_OBJ_START_REG and FS_OBJ_START_REG
registers in snapshot. This makes snapshot more complete in terms of
tracking data that is used by the GPU at the time of hang.
Change-Id: I7e5f3c94f0d6744cd6f2c6413bf7b7fac4a5a069
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 28th commit message:
msm: kgsl: Loop till correct index on type0 packets
When searching for memory addresses in type0 packet we were looping
from start of the type0 packet till it's end, but the first DWORD
is a header so we only need to loop till packet_size - 1. Fix this.
Change-Id: I278446c6ab380cf8ebb18d5f3ae192d3d7e7db62
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 29th commit message:
msm: kgsl: Add global timestamp information to snapshot
Make sure that we always add global timestamp information to
snapshot. This is needed in playbacks for searching whereabouts
of last executed IB.
Change-Id: Ica5b3b2ddff6fd45dbc5a911f42271ad5855a86a
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 30th commit message:
msm: kgsl: Skip cff dump for certain functions when its disabled
Certain functions were generating CFF when CFF was disabled. Make
sure these functions do not dump CFF when it is disabled.
Change-Id: Ib5485b03b8a4d12f190f188b80c11ec6f552731d
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 31st commit message:
msm: kgsl: Fix searching of memory object
Make sure that at least a size of 1 byte is searched when locating
the memory entry of a region. If size is 0 then a memory region
whose last address is equal to the start address of the memory being
searched will be returned which is wrong.
Change-Id: I643185d1fdd17296bd70fea483aa3c365e691bc5
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 32nd commit message:
msm: kgsl: If adreno start fails then restore state of device
Restore the state of the device back to what it was at the
start of the adreno_start function if this function fails to
execute successfully.
Change-Id: I5b279e5186b164d3361fba7c8f8d864395b794c8
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 33rd commit message:
msm: kgsl: Fix early exit condition in ringbuffer drain
The ringbuffer drain function can be called when the ringbuffer
start flag is not set. This happens on startup. Hence,
exiting the function early based on start flag is incorrect.
Simply execute this function regardless of the start flag.
Change-Id: Ibf2075847f8bb1a760bc1550309efb3c7aa1ca49
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 34th commit message:
msm: kgsl: Do not return an error on NULL gpu address
If a NULL gpu address is passed to snapshot object tracking
function then do not treat this as an error and return 0. NULL
objects may be present in an IB so just skip over these objects
instead of exiting due to an error.
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Change-Id: Ic253722c58b41f41d03f83c77017e58365da01a7
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 35th commit message:
msm: kgsl: Don't hold process list global mutex in process private create
Don't hold process list global mutex for long. Instead make
use of process specific spin_lock() to serialize access
to process private structure while creating it. Holding
process list global mutex could lead to deadlocks as other
functions depend on it.
CRs-fixed: 480732
Change-Id: Id54316770f911d0e23384f54ba5c14a1c9113680
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 36th commit message:
msm: kgsl: Use CPU path to program pagetable when active count is 0
When active count is 0 then we should use the CPU path to program
pagetables because the GPU path requires event registration. Events
can only be queued when active count is valid. Hence, if the active
count is NULL then use the CPU path.
Change-Id: I70f5894d20796bdc0f592db7dc2731195c0f7a82
CRs-fixed: 481887
Signed-off-by: Shubhrapralash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 37th commit message:
iommu: msm: prevent partial mappings on error
If msm_iommu_map_range() fails mid way through the va
range with an error, clean up the PTEs that have already
been created so they are not leaked.
Change-Id: Ie929343cd6e36cade7b2cc9b4b4408c3453e6b5f
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 38th commit message:
msm: kgsl: better handling of virtual address fragmentation
When KGSL_MEMFLAGS_USE_CPU_MAP is enabled, the mmap address
must try to match the GPU alignment requirements of the buffer,
as well as include space in the mapping for the guard page.
This can cause -ENOMEM to be returned from get_unmapped_area()
when there are a large number of mappings. When this happens,
fall back to page alignment and retry to avoid failure.
Change-Id: I2176fe57afc96d8cf1fe1c694836305ddc3c3420
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 39th commit message:
iommu: msm: Don't treat address 0 as an error case
Currently, the iommu page table code treats a scattergather
list with physical address 0 as an error. This may not be
correct in all cases. Physical address 0 is a valid part
of the system and may be used for valid page allocations.
Nothing else in the system checks for physical address 0
for error so don't treat it as an error.
Change-Id: Ie9f0dae9dace4fff3b1c3449bc89c3afdd2e63a0
CRs-Fixed: 478304
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 40th commit message:
msm: kgsl: prevent race between mmap() and free on timestamp
When KGSL_MEMFLAGS_USE_CPU_MAP is set, we must check that the
address from get_unmapped_area() is not used as part of a
mapping that is present only in the GPU pagetable and not the
CPU pagetable. These mappings can occur because when a buffer
is freed on timestamp, the CPU mapping is destroyed immediately
but the GPU mapping is not destroyed until the GPU timestamp
has passed.
Because kgsl_mem_entry_detach_process() removed the rbtree
entry before removing the iommu mapping, there was a window
of time where kgsl thought the address was available even
though it was still present in the iommu pagetable. This
could cause the address to get assigned to a new buffer,
which would cause iommu_map_range() to fail since the old
mapping was still in the pagetable. Prevent this race by
removing the iommu mapping before removing the rbtree entry
tracking the address.
Change-Id: I8f42d6d97833293b55fcbc272d180564862cef8a
CRs-Fixed: 480222
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 41st commit message:
msm: kgsl: add guard page support for imported memory
Imported memory buffers sometimes do not have enough
padding to prevent page faults due to overzealous
GPU prefetch. Attach guard pages to their mappings
to prevent these faults.
Because we don't create the scatterlist for some
types of imported memory, such as ion, the guard
page is no longer included as the last entry in
the scatterlist. Instead, it is handled by
size ajustments and a separate iommu_map() call
in the kgsl_mmu_map() and kgsl_mmu_unmap() paths.
Change-Id: I3af3c29c3983f8cacdc366a2423f90c8ecdc3059
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 42nd commit message:
msm: kgsl: fix kgsl_mem_entry refcounting
Make kgsl_sharedmem_find* return a reference to the
entry that was found. This makes using an entry
without the mem_lock held less race prone.
Change-Id: If6eb6470ecfea1332d3130d877922c70ca037467
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 43rd commit message:
msm: kgsl: add ftrace for cache operations
Add the event kgsl_mem_sync_cache. This event is
emitted when only a cache operation is actually
performed. Attempts to flush uncached memory,
which do nothing, do not cause this event.
Change-Id: Id4a940a6b50e08b54fbef0025c4b8aaa71641462
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 44th commit message:
msm: kgsl: Add support for bulk cache operations
Add a new ioctl, IOCTL_KGSL_GPUMEM_SYNC_CACHE_BULK, which can be used
to sync a number of memory ids at once. This gives the driver an
opportunity to optimize the cache operations based on the total
working set of memory that needs to be managed.
Change-Id: I9693c54cb6f12468b7d9abb0afaef348e631a114
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 45th commit message:
msm: kgsl: flush the entire cache when the bulk batch is large
On 8064 and 8974, flushing more than 16mb of virtual address
space is slower than flushing the entire cache. So flush
the entire cache when the working set is larger than this.
The threshold for full cache flush can be tuned at runtime via
the full_cache_threshold sysfs file.
Change-Id: If525e4c44eb043d0afc3fe42d7ef2c7de0ba2106
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 46th commit message:
msm: kgsl: Use a read/lock for the context idr
Everybody loves a rcu but in this case we are dangerously mixing rcus and
atomic operations. Add a read/write lock to explicitly protect the idr.
Also fix a few spots where the idr was used without protection.
Change-Id: Ic0dedbad517a9f89134cbcf7af29c8bf0f034708
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 47th commit message:
msm: kgsl: embed kgsl_context struct in adreno_context struct
Having a separate allocated struct for the device specific context
makes ownership unclear, which could lead to reference counting
problems or invalid pointers. Also, duplicate members were
starting to appear in adreno_context because there wasn't a safe
way to reach the kgsl_context from some parts of the adreno code.
This can now be done via container_of().
This change alters the lifecycle of the context->id, which is
now freed when the context reference count hits zero rather
than in kgsl_context_detach().
It also changes the context creation and destruction sequence.
The device specific code must allocate a structure containing
a struct kgsl_context and passes a pointer it to kgsl_init_context()
before doing any device specific initialization. There is also a
separate drawctxt_detach() callback for doing device specific
cleanup. This is separate from freeing memory, which is done
by the drawctxt_destroy() callback.
Change-Id: I7d238476a3bfec98fd8dbc28971cf3187a81dac2
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 48th commit message:
msm: kgsl: Take a reference count on the active adreno draw context
Take a reference count on the currently active draw context to keep
it from going away while we are maintaining a pointer to it in the
adreno device.
Change-Id: Ic0dedbade8c09ecacf822e9a3c5fbaf6e017ec0c
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 49th commit message:
msm: kgsl: Add a command dispatcher to manage the ringbuffer
Implements a centralized dispatcher for sending user commands
to the ringbuffer. Incoming commands are queued by context and
sent to the hardware on a round robin basis ensuring each context
a small burst of commands at a time. Each command is tracked
throughout the pipeline giving the dispatcher better knowledge
of how the hardware is being used. This will be the basis for
future per-context and cross context enhancements as priority
queuing and server-side syncronization.
Change-Id: Ic0dedbad49a43e8e6096d1362829c800266c2de3
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 50th commit message:
msm: kgsl: Only turn on the idle timer when active_cnt is 0
Only turn on the idle timer when the GPU expected to be quiet.
Change-Id: Ic0dedbad57846f1e7bf7820ec3152cd20598b448
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 51st commit message:
msm: kgsl: Add a ftrace event for active_cnt
Add a new ftrace event for watching the rise and fall of active_cnt:
echo 1 > /sys/kernel/debug/tracing/events/kgsl/kgsl_active_count/enable
This will give you the current active count and the caller of the function:
kgsl_active_count: d_name=kgsl-3d0 active_cnt=8e9 func=kgsl_ioctl
Change-Id: Ic0dedbadc80019e96ce759d9d4e0ad43bbcfedd2
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 52nd commit message:
msm: kgsl: Implement KGSL fault tolerance policy in the dispatcher
Implement the KGSL fault tolerance policy for faults in the dispatcher.
Replay (or skip) the inflight command batches as dictated by the policy,
iterating progressively through the various behaviors.
Change-Id: Ic0dedbade98cc3aa35b26813caf4265c74ccab56
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 53rd commit message:
msm: kgsl: Don't process events if the timestamp hasn't changed
Keep track of the global timestamp every time the event code runs.
If the timestamp hasn't changed then we are caught up and we can
politely bow out. This avoids the situation where multiple
interrupts queue the work queue multiple times:
IRQ
-> process events
IRQ
IRQ
-> process events
The actual retired timestamp in the first work item might be well
ahead of the delivered interrupts. The event loop will end up
processing every event that has been retired by the hardware
at that point. If the work item gets re-queued by a subesquent
interrupt then we might have already addressed all the pending
timestamps.
Change-Id: Ic0dedbad79722654cb17e82b7149e93d3c3f86a0
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 54th commit message:
msm: kgsl: Make active_cnt an atomic variable
In kgsl_active_cnt_light() the mutex was needed just to check and
increment the active_cnt value. Move active_cnt to an atomic to
begin the task of freeing ourselves from the grip of the device
mutex if we can avoid it.
Change-Id: Ic0dedbad78e086e3aa3559fab8ecebc43539f769
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 55th commit message:
msm: kgsl: Add a new command submission API
Add an new ioctl entry point for submitting commands to the GPU
called IOCTL_KGSL_SUBMIT_COMMANDS.
As with IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS the user passes a list of
indirect buffers, flags and optionally a user specified timestamp. The
old way of passing a list of indirect buffers is no longer supported.
IOCTL_KGSL_SUBMIT_COMMANDS also allows the user to define a
list of sync points for the command. Sync points are dependencies
on events that need to be satisfied before the command will be issued
to the hardware. Events are designed to be flexible. To start with
the only events that are supported are GPU events for a given context/
timestamp pair.
Pending events are stored in a list in the command batch. As each event is
expired it is deleted from the list. The adreno dispatcher won't send the
command until the list is empty. Sync points are not supported for Z180.
CRs-Fixed: 468770
Change-Id: Ic0dedbad5a5935f486acaeb033ae9a6010f82346
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 56th commit message:
msm: kgsl: add kgsl_sync_fence_waiter for server side sync
For server side sync the KGSL kernel module needs to perform
an asynchronous wait for a fence object prior to issuing
subsequent commands.
Change-Id: I1ee614aa3af84afc4813f1e47007f741beb3bc92
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 57th commit message:
msm: kgsl: Add support for KGSL_CMD_SYNCPOINT_TYPE_FENCE
Allow command batches to wait for external fence sync events.
Change-Id: Ic0dedbad3a211019e1cd3a3d62ab6a3e4d4eeb05
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 58th commit message:
msm: kgsl: fix potential double free of the kwaiter
Change-Id: Ic0dedbad66a0af6eaef52b2ad53c067110bdc6e4
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 59th commit message:
msm: kgsl: free an event only after canceling successfully
Change-Id: Ic0dedbade256443d090dd11df452dc9cdf65530b
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
2013-06-24 17:40:20 +00:00
|
|
|
static int msm_iommu_unmap_range(struct iommu_domain *domain, unsigned int va,
|
|
|
|
unsigned int len);
|
|
|
|
|
2012-05-12 01:43:02 +00:00
|
|
|
static inline void clean_pte(unsigned long *start, unsigned long *end,
|
|
|
|
int redirect)
|
2011-08-03 20:38:29 +00:00
|
|
|
{
|
2012-05-12 01:43:02 +00:00
|
|
|
if (!redirect)
|
|
|
|
dmac_flush_range(start, end);
|
2011-08-03 20:38:29 +00:00
|
|
|
}
|
|
|
|
|
2011-11-10 09:32:28 +00:00
|
|
|
/* bitmap of the page sizes currently supported */
|
|
|
|
#define MSM_IOMMU_PGSIZES (SZ_4K | SZ_64K | SZ_1M | SZ_16M)
|
|
|
|
|
2010-11-16 02:20:08 +00:00
|
|
|
static int msm_iommu_tex_class[4];
|
|
|
|
|
2012-02-14 23:42:05 +00:00
|
|
|
DEFINE_MUTEX(msm_iommu_lock);
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2012-11-07 23:02:56 +00:00
|
|
|
/**
|
|
|
|
* Remote spinlock implementation based on Peterson's algorithm to be used
|
|
|
|
* to synchronize IOMMU config port access between CPU and GPU.
|
|
|
|
* This implements Process 0 of the spin lock algorithm. GPU implements
|
|
|
|
* Process 1. Flag and turn is stored in shared memory to allow GPU to
|
|
|
|
* access these.
|
|
|
|
*/
|
|
|
|
struct msm_iommu_remote_lock {
|
|
|
|
int initialized;
|
|
|
|
struct remote_iommu_petersons_spinlock *lock;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct msm_iommu_remote_lock msm_iommu_remote_lock;
|
|
|
|
|
|
|
|
#ifdef CONFIG_MSM_IOMMU_GPU_SYNC
|
|
|
|
static void _msm_iommu_remote_spin_lock_init(void)
|
|
|
|
{
|
|
|
|
msm_iommu_remote_lock.lock = smem_alloc(SMEM_SPINLOCK_ARRAY, 32);
|
2016-02-19 04:16:12 +00:00
|
|
|
if (msm_iommu_remote_lock.lock) {
|
|
|
|
memset(msm_iommu_remote_lock.lock, 0,
|
2012-11-07 23:02:56 +00:00
|
|
|
sizeof(*msm_iommu_remote_lock.lock));
|
2016-02-19 04:16:12 +00:00
|
|
|
}
|
2012-11-07 23:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void msm_iommu_remote_p0_spin_lock(void)
|
|
|
|
{
|
|
|
|
msm_iommu_remote_lock.lock->flag[PROC_APPS] = 1;
|
|
|
|
msm_iommu_remote_lock.lock->turn = 1;
|
|
|
|
|
|
|
|
smp_mb();
|
|
|
|
|
|
|
|
while (msm_iommu_remote_lock.lock->flag[PROC_GPU] == 1 &&
|
|
|
|
msm_iommu_remote_lock.lock->turn == 1)
|
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
|
|
|
|
void msm_iommu_remote_p0_spin_unlock(void)
|
|
|
|
{
|
|
|
|
smp_mb();
|
|
|
|
|
|
|
|
msm_iommu_remote_lock.lock->flag[PROC_APPS] = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
inline void msm_iommu_mutex_lock(void)
|
|
|
|
{
|
|
|
|
mutex_lock(&msm_iommu_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void msm_iommu_mutex_unlock(void)
|
|
|
|
{
|
|
|
|
mutex_unlock(&msm_iommu_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *msm_iommu_lock_initialize(void)
|
|
|
|
{
|
|
|
|
mutex_lock(&msm_iommu_lock);
|
|
|
|
if (!msm_iommu_remote_lock.initialized) {
|
|
|
|
msm_iommu_remote_lock_init();
|
|
|
|
msm_iommu_remote_lock.initialized = 1;
|
|
|
|
}
|
|
|
|
mutex_unlock(&msm_iommu_lock);
|
|
|
|
return msm_iommu_remote_lock.lock;
|
|
|
|
}
|
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
struct msm_priv {
|
|
|
|
unsigned long *pgtable;
|
2011-09-01 00:16:19 +00:00
|
|
|
int redirect;
|
2010-08-25 01:31:10 +00:00
|
|
|
struct list_head list_attached;
|
|
|
|
};
|
|
|
|
|
2011-02-25 02:00:39 +00:00
|
|
|
static int __enable_clocks(struct msm_iommu_drvdata *drvdata)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2012-02-14 23:42:27 +00:00
|
|
|
ret = clk_prepare_enable(drvdata->pclk);
|
2011-02-25 02:00:39 +00:00
|
|
|
if (ret)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (drvdata->clk) {
|
2012-02-14 23:42:27 +00:00
|
|
|
ret = clk_prepare_enable(drvdata->clk);
|
2011-02-25 02:00:39 +00:00
|
|
|
if (ret)
|
2012-02-14 23:42:27 +00:00
|
|
|
clk_disable_unprepare(drvdata->pclk);
|
2011-02-25 02:00:39 +00:00
|
|
|
}
|
|
|
|
fail:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __disable_clocks(struct msm_iommu_drvdata *drvdata)
|
|
|
|
{
|
|
|
|
if (drvdata->clk)
|
2012-02-14 23:42:27 +00:00
|
|
|
clk_disable_unprepare(drvdata->clk);
|
|
|
|
clk_disable_unprepare(drvdata->pclk);
|
2011-02-25 02:00:39 +00:00
|
|
|
}
|
|
|
|
|
2011-08-03 23:24:54 +00:00
|
|
|
static int __flush_iotlb_va(struct iommu_domain *domain, unsigned int va)
|
|
|
|
{
|
|
|
|
struct msm_priv *priv = domain->priv;
|
|
|
|
struct msm_iommu_drvdata *iommu_drvdata;
|
|
|
|
struct msm_iommu_ctx_drvdata *ctx_drvdata;
|
|
|
|
int ret = 0;
|
|
|
|
int asid;
|
|
|
|
|
|
|
|
list_for_each_entry(ctx_drvdata, &priv->list_attached, attached_elm) {
|
|
|
|
if (!ctx_drvdata->pdev || !ctx_drvdata->pdev->dev.parent)
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
iommu_drvdata = dev_get_drvdata(ctx_drvdata->pdev->dev.parent);
|
|
|
|
if (!iommu_drvdata)
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
ret = __enable_clocks(iommu_drvdata);
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
|
|
|
|
2012-11-07 23:02:56 +00:00
|
|
|
msm_iommu_remote_spin_lock();
|
|
|
|
|
2011-08-03 23:24:54 +00:00
|
|
|
asid = GET_CONTEXTIDR_ASID(iommu_drvdata->base,
|
|
|
|
ctx_drvdata->num);
|
|
|
|
|
|
|
|
SET_TLBIVA(iommu_drvdata->base, ctx_drvdata->num,
|
|
|
|
asid | (va & TLBIVA_VA));
|
|
|
|
mb();
|
2012-11-07 23:02:56 +00:00
|
|
|
|
|
|
|
msm_iommu_remote_spin_unlock();
|
|
|
|
|
2011-08-03 23:24:54 +00:00
|
|
|
__disable_clocks(iommu_drvdata);
|
|
|
|
}
|
|
|
|
fail:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-08-12 02:45:23 +00:00
|
|
|
static int __flush_iotlb(struct iommu_domain *domain)
|
|
|
|
{
|
|
|
|
struct msm_priv *priv = domain->priv;
|
|
|
|
struct msm_iommu_drvdata *iommu_drvdata;
|
|
|
|
struct msm_iommu_ctx_drvdata *ctx_drvdata;
|
|
|
|
int ret = 0;
|
|
|
|
int asid;
|
|
|
|
|
|
|
|
list_for_each_entry(ctx_drvdata, &priv->list_attached, attached_elm) {
|
|
|
|
if (!ctx_drvdata->pdev || !ctx_drvdata->pdev->dev.parent)
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
iommu_drvdata = dev_get_drvdata(ctx_drvdata->pdev->dev.parent);
|
|
|
|
if (!iommu_drvdata)
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
ret = __enable_clocks(iommu_drvdata);
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
|
|
|
|
2012-11-07 23:02:56 +00:00
|
|
|
msm_iommu_remote_spin_lock();
|
|
|
|
|
2011-08-12 02:45:23 +00:00
|
|
|
asid = GET_CONTEXTIDR_ASID(iommu_drvdata->base,
|
|
|
|
ctx_drvdata->num);
|
|
|
|
|
|
|
|
SET_TLBIASID(iommu_drvdata->base, ctx_drvdata->num, asid);
|
|
|
|
mb();
|
2012-11-07 23:02:56 +00:00
|
|
|
|
|
|
|
msm_iommu_remote_spin_unlock();
|
|
|
|
|
2011-08-12 02:45:23 +00:00
|
|
|
__disable_clocks(iommu_drvdata);
|
|
|
|
}
|
|
|
|
fail:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
static void __reset_context(void __iomem *base, int ctx)
|
|
|
|
{
|
|
|
|
SET_BPRCOSH(base, ctx, 0);
|
|
|
|
SET_BPRCISH(base, ctx, 0);
|
|
|
|
SET_BPRCNSH(base, ctx, 0);
|
|
|
|
SET_BPSHCFG(base, ctx, 0);
|
|
|
|
SET_BPMTCFG(base, ctx, 0);
|
|
|
|
SET_ACTLR(base, ctx, 0);
|
|
|
|
SET_SCTLR(base, ctx, 0);
|
|
|
|
SET_FSRRESTORE(base, ctx, 0);
|
|
|
|
SET_TTBR0(base, ctx, 0);
|
|
|
|
SET_TTBR1(base, ctx, 0);
|
|
|
|
SET_TTBCR(base, ctx, 0);
|
|
|
|
SET_BFBCR(base, ctx, 0);
|
|
|
|
SET_PAR(base, ctx, 0);
|
|
|
|
SET_FAR(base, ctx, 0);
|
|
|
|
SET_TLBFLPTER(base, ctx, 0);
|
|
|
|
SET_TLBSLPTER(base, ctx, 0);
|
|
|
|
SET_TLBLKCR(base, ctx, 0);
|
|
|
|
SET_PRRR(base, ctx, 0);
|
|
|
|
SET_NMRR(base, ctx, 0);
|
2011-03-16 19:23:21 +00:00
|
|
|
mb();
|
2010-08-25 01:31:10 +00:00
|
|
|
}
|
|
|
|
|
2011-07-08 22:44:07 +00:00
|
|
|
static void __program_context(void __iomem *base, int ctx, int ncb,
|
2012-04-05 20:47:30 +00:00
|
|
|
phys_addr_t pgtable, int redirect,
|
|
|
|
int ttbr_split)
|
2010-08-25 01:31:10 +00:00
|
|
|
{
|
2010-11-16 02:20:08 +00:00
|
|
|
unsigned int prrr, nmrr;
|
2011-07-08 22:44:07 +00:00
|
|
|
int i, j, found;
|
2012-11-07 23:02:56 +00:00
|
|
|
|
|
|
|
msm_iommu_remote_spin_lock();
|
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
__reset_context(base, ctx);
|
|
|
|
|
|
|
|
/* Set up HTW mode */
|
|
|
|
/* TLB miss configuration: perform HTW on miss */
|
|
|
|
SET_TLBMCFG(base, ctx, 0x3);
|
|
|
|
|
|
|
|
/* V2P configuration: HTW for access */
|
|
|
|
SET_V2PCFG(base, ctx, 0x3);
|
|
|
|
|
2012-04-05 20:47:30 +00:00
|
|
|
SET_TTBCR(base, ctx, ttbr_split);
|
2011-07-08 22:44:07 +00:00
|
|
|
SET_TTBR0_PA(base, ctx, (pgtable >> TTBR0_PA_SHIFT));
|
2012-04-05 20:47:30 +00:00
|
|
|
if (ttbr_split)
|
|
|
|
SET_TTBR1_PA(base, ctx, (pgtable >> TTBR1_PA_SHIFT));
|
2010-08-25 01:31:10 +00:00
|
|
|
|
|
|
|
/* Enable context fault interrupt */
|
|
|
|
SET_CFEIE(base, ctx, 1);
|
|
|
|
|
|
|
|
/* Stall access on a context fault and let the handler deal with it */
|
|
|
|
SET_CFCFG(base, ctx, 1);
|
|
|
|
|
|
|
|
/* Redirect all cacheable requests to L2 slave port. */
|
|
|
|
SET_RCISH(base, ctx, 1);
|
|
|
|
SET_RCOSH(base, ctx, 1);
|
|
|
|
SET_RCNSH(base, ctx, 1);
|
|
|
|
|
|
|
|
/* Turn on TEX Remap */
|
|
|
|
SET_TRE(base, ctx, 1);
|
|
|
|
|
2010-11-16 02:20:08 +00:00
|
|
|
/* Set TEX remap attributes */
|
|
|
|
RCP15_PRRR(prrr);
|
|
|
|
RCP15_NMRR(nmrr);
|
|
|
|
SET_PRRR(base, ctx, prrr);
|
|
|
|
SET_NMRR(base, ctx, nmrr);
|
2010-08-25 01:31:10 +00:00
|
|
|
|
|
|
|
/* Turn on BFB prefetch */
|
|
|
|
SET_BFBDFE(base, ctx, 1);
|
|
|
|
|
|
|
|
/* Configure page tables as inner-cacheable and shareable to reduce
|
|
|
|
* the TLB miss penalty.
|
|
|
|
*/
|
2011-09-01 00:16:19 +00:00
|
|
|
if (redirect) {
|
|
|
|
SET_TTBR0_SH(base, ctx, 1);
|
|
|
|
SET_TTBR1_SH(base, ctx, 1);
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2011-09-01 00:16:19 +00:00
|
|
|
SET_TTBR0_NOS(base, ctx, 1);
|
|
|
|
SET_TTBR1_NOS(base, ctx, 1);
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2011-09-01 00:16:19 +00:00
|
|
|
SET_TTBR0_IRGNH(base, ctx, 0); /* WB, WA */
|
|
|
|
SET_TTBR0_IRGNL(base, ctx, 1);
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2011-09-01 00:16:19 +00:00
|
|
|
SET_TTBR1_IRGNH(base, ctx, 0); /* WB, WA */
|
|
|
|
SET_TTBR1_IRGNL(base, ctx, 1);
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2011-09-01 00:16:19 +00:00
|
|
|
SET_TTBR0_ORGN(base, ctx, 1); /* WB, WA */
|
|
|
|
SET_TTBR1_ORGN(base, ctx, 1); /* WB, WA */
|
|
|
|
}
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2011-07-08 22:44:07 +00:00
|
|
|
/* Find if this page table is used elsewhere, and re-use ASID */
|
|
|
|
found = 0;
|
|
|
|
for (i = 0; i < ncb; i++)
|
|
|
|
if (GET_TTBR0_PA(base, i) == (pgtable >> TTBR0_PA_SHIFT) &&
|
|
|
|
i != ctx) {
|
|
|
|
SET_CONTEXTIDR_ASID(base, ctx, \
|
|
|
|
GET_CONTEXTIDR_ASID(base, i));
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If page table is new, find an unused ASID */
|
|
|
|
if (!found) {
|
|
|
|
for (i = 0; i < ncb; i++) {
|
|
|
|
found = 0;
|
|
|
|
for (j = 0; j < ncb; j++) {
|
|
|
|
if (GET_CONTEXTIDR_ASID(base, j) == i &&
|
|
|
|
j != ctx)
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
SET_CONTEXTIDR_ASID(base, ctx, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BUG_ON(found);
|
|
|
|
}
|
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
/* Enable the MMU */
|
|
|
|
SET_M(base, ctx, 1);
|
2011-03-16 19:23:21 +00:00
|
|
|
mb();
|
2012-11-07 23:02:56 +00:00
|
|
|
|
|
|
|
msm_iommu_remote_spin_unlock();
|
2010-08-25 01:31:10 +00:00
|
|
|
}
|
|
|
|
|
2011-09-01 00:13:32 +00:00
|
|
|
static int msm_iommu_domain_init(struct iommu_domain *domain, int flags)
|
2010-08-25 01:31:10 +00:00
|
|
|
{
|
|
|
|
struct msm_priv *priv = kzalloc(sizeof(*priv), GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!priv)
|
|
|
|
goto fail_nomem;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&priv->list_attached);
|
|
|
|
priv->pgtable = (unsigned long *)__get_free_pages(GFP_KERNEL,
|
|
|
|
get_order(SZ_16K));
|
|
|
|
|
|
|
|
if (!priv->pgtable)
|
|
|
|
goto fail_nomem;
|
|
|
|
|
2011-09-01 00:16:19 +00:00
|
|
|
#ifdef CONFIG_IOMMU_PGTABLES_L2
|
|
|
|
priv->redirect = flags & MSM_IOMMU_DOMAIN_PT_CACHEABLE;
|
|
|
|
#endif
|
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
memset(priv->pgtable, 0, SZ_16K);
|
|
|
|
domain->priv = priv;
|
2012-05-12 00:30:08 +00:00
|
|
|
|
2012-05-12 01:43:02 +00:00
|
|
|
clean_pte(priv->pgtable, priv->pgtable + NUM_FL_PTE, priv->redirect);
|
2012-05-12 00:30:08 +00:00
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_nomem:
|
|
|
|
kfree(priv);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void msm_iommu_domain_destroy(struct iommu_domain *domain)
|
|
|
|
{
|
|
|
|
struct msm_priv *priv;
|
|
|
|
unsigned long *fl_table;
|
|
|
|
int i;
|
|
|
|
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_lock(&msm_iommu_lock);
|
2010-08-25 01:31:10 +00:00
|
|
|
priv = domain->priv;
|
|
|
|
domain->priv = NULL;
|
|
|
|
|
|
|
|
if (priv) {
|
|
|
|
fl_table = priv->pgtable;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_FL_PTE; i++)
|
|
|
|
if ((fl_table[i] & 0x03) == FL_TYPE_TABLE)
|
|
|
|
free_page((unsigned long) __va(((fl_table[i]) &
|
|
|
|
FL_BASE_MASK)));
|
|
|
|
|
|
|
|
free_pages((unsigned long)priv->pgtable, get_order(SZ_16K));
|
|
|
|
priv->pgtable = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(priv);
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_unlock(&msm_iommu_lock);
|
2010-08-25 01:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev)
|
|
|
|
{
|
|
|
|
struct msm_priv *priv;
|
|
|
|
struct msm_iommu_ctx_dev *ctx_dev;
|
|
|
|
struct msm_iommu_drvdata *iommu_drvdata;
|
|
|
|
struct msm_iommu_ctx_drvdata *ctx_drvdata;
|
|
|
|
struct msm_iommu_ctx_drvdata *tmp_drvdata;
|
|
|
|
int ret = 0;
|
|
|
|
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_lock(&msm_iommu_lock);
|
2010-08-25 01:31:10 +00:00
|
|
|
|
|
|
|
priv = domain->priv;
|
|
|
|
|
|
|
|
if (!priv || !dev) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
iommu_drvdata = dev_get_drvdata(dev->parent);
|
|
|
|
ctx_drvdata = dev_get_drvdata(dev);
|
|
|
|
ctx_dev = dev->platform_data;
|
|
|
|
|
|
|
|
if (!iommu_drvdata || !ctx_drvdata || !ctx_dev) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2010-11-13 03:29:56 +00:00
|
|
|
if (!list_empty(&ctx_drvdata->attached_elm)) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
list_for_each_entry(tmp_drvdata, &priv->list_attached, attached_elm)
|
|
|
|
if (tmp_drvdata == ctx_drvdata) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-02-25 02:00:39 +00:00
|
|
|
ret = __enable_clocks(iommu_drvdata);
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
|
|
|
|
2011-07-08 22:44:07 +00:00
|
|
|
__program_context(iommu_drvdata->base, ctx_dev->num, iommu_drvdata->ncb,
|
2012-04-05 20:47:30 +00:00
|
|
|
__pa(priv->pgtable), priv->redirect,
|
|
|
|
iommu_drvdata->ttbr_split);
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2011-02-25 02:00:39 +00:00
|
|
|
__disable_clocks(iommu_drvdata);
|
2010-08-25 01:31:10 +00:00
|
|
|
list_add(&(ctx_drvdata->attached_elm), &priv->list_attached);
|
|
|
|
|
2012-05-04 00:29:12 +00:00
|
|
|
ctx_drvdata->attached_domain = domain;
|
2010-08-25 01:31:10 +00:00
|
|
|
fail:
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_unlock(&msm_iommu_lock);
|
2010-08-25 01:31:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void msm_iommu_detach_dev(struct iommu_domain *domain,
|
|
|
|
struct device *dev)
|
|
|
|
{
|
|
|
|
struct msm_priv *priv;
|
|
|
|
struct msm_iommu_ctx_dev *ctx_dev;
|
|
|
|
struct msm_iommu_drvdata *iommu_drvdata;
|
|
|
|
struct msm_iommu_ctx_drvdata *ctx_drvdata;
|
2010-11-13 03:30:00 +00:00
|
|
|
int ret;
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_lock(&msm_iommu_lock);
|
2010-08-25 01:31:10 +00:00
|
|
|
priv = domain->priv;
|
|
|
|
|
|
|
|
if (!priv || !dev)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
iommu_drvdata = dev_get_drvdata(dev->parent);
|
|
|
|
ctx_drvdata = dev_get_drvdata(dev);
|
|
|
|
ctx_dev = dev->platform_data;
|
|
|
|
|
|
|
|
if (!iommu_drvdata || !ctx_drvdata || !ctx_dev)
|
|
|
|
goto fail;
|
|
|
|
|
2011-02-25 02:00:39 +00:00
|
|
|
ret = __enable_clocks(iommu_drvdata);
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
|
|
|
|
2012-11-07 23:02:56 +00:00
|
|
|
msm_iommu_remote_spin_lock();
|
|
|
|
|
2011-08-05 19:16:39 +00:00
|
|
|
SET_TLBIASID(iommu_drvdata->base, ctx_dev->num,
|
|
|
|
GET_CONTEXTIDR_ASID(iommu_drvdata->base, ctx_dev->num));
|
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
__reset_context(iommu_drvdata->base, ctx_dev->num);
|
2012-11-07 23:02:56 +00:00
|
|
|
|
|
|
|
msm_iommu_remote_spin_unlock();
|
|
|
|
|
2011-02-25 02:00:39 +00:00
|
|
|
__disable_clocks(iommu_drvdata);
|
2010-08-25 01:31:10 +00:00
|
|
|
list_del_init(&ctx_drvdata->attached_elm);
|
2012-05-04 00:29:12 +00:00
|
|
|
ctx_drvdata->attached_domain = NULL;
|
2010-08-25 01:31:10 +00:00
|
|
|
fail:
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_unlock(&msm_iommu_lock);
|
2010-08-25 01:31:10 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 02:45:23 +00:00
|
|
|
static int __get_pgprot(int prot, int len)
|
|
|
|
{
|
|
|
|
unsigned int pgprot;
|
2011-11-08 23:24:53 +00:00
|
|
|
int tex;
|
2011-08-12 02:45:23 +00:00
|
|
|
|
2012-03-15 22:23:48 +00:00
|
|
|
if (!(prot & (IOMMU_READ | IOMMU_WRITE))) {
|
|
|
|
prot |= IOMMU_READ | IOMMU_WRITE;
|
|
|
|
WARN_ONCE(1, "No attributes in iommu mapping; assuming RW\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((prot & IOMMU_WRITE) && !(prot & IOMMU_READ)) {
|
|
|
|
prot |= IOMMU_READ;
|
|
|
|
WARN_ONCE(1, "Write-only iommu mappings unsupported; falling back to RW\n");
|
|
|
|
}
|
|
|
|
|
2011-11-08 23:24:53 +00:00
|
|
|
if (prot & IOMMU_CACHE)
|
|
|
|
tex = (pgprot_kernel >> 2) & 0x07;
|
|
|
|
else
|
|
|
|
tex = msm_iommu_tex_class[MSM_IOMMU_ATTR_NONCACHED];
|
2011-08-12 02:45:23 +00:00
|
|
|
|
|
|
|
if (tex < 0 || tex > NUM_TEX_CLASS - 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (len == SZ_16M || len == SZ_1M) {
|
2011-11-08 23:24:53 +00:00
|
|
|
pgprot = FL_SHARED;
|
2011-08-12 02:45:23 +00:00
|
|
|
pgprot |= tex & 0x01 ? FL_BUFFERABLE : 0;
|
|
|
|
pgprot |= tex & 0x02 ? FL_CACHEABLE : 0;
|
|
|
|
pgprot |= tex & 0x04 ? FL_TEX0 : 0;
|
2012-03-15 22:23:48 +00:00
|
|
|
pgprot |= FL_AP0 | FL_AP1;
|
|
|
|
pgprot |= prot & IOMMU_WRITE ? 0 : FL_AP2;
|
2011-08-12 02:45:23 +00:00
|
|
|
} else {
|
2011-11-08 23:24:53 +00:00
|
|
|
pgprot = SL_SHARED;
|
2011-08-12 02:45:23 +00:00
|
|
|
pgprot |= tex & 0x01 ? SL_BUFFERABLE : 0;
|
|
|
|
pgprot |= tex & 0x02 ? SL_CACHEABLE : 0;
|
|
|
|
pgprot |= tex & 0x04 ? SL_TEX0 : 0;
|
2012-03-15 22:23:48 +00:00
|
|
|
pgprot |= SL_AP0 | SL_AP1;
|
|
|
|
pgprot |= prot & IOMMU_WRITE ? 0 : SL_AP2;
|
2011-08-12 02:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pgprot;
|
|
|
|
}
|
|
|
|
|
2012-07-09 19:27:07 +00:00
|
|
|
static unsigned long *make_second_level(struct msm_priv *priv,
|
|
|
|
unsigned long *fl_pte)
|
|
|
|
{
|
|
|
|
unsigned long *sl;
|
|
|
|
sl = (unsigned long *) __get_free_pages(GFP_KERNEL,
|
|
|
|
get_order(SZ_4K));
|
|
|
|
|
|
|
|
if (!sl) {
|
|
|
|
pr_debug("Could not allocate second level table\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
memset(sl, 0, SZ_4K);
|
|
|
|
clean_pte(sl, sl + NUM_SL_PTE, priv->redirect);
|
|
|
|
|
|
|
|
*fl_pte = ((((int)__pa(sl)) & FL_BASE_MASK) | \
|
|
|
|
FL_TYPE_TABLE);
|
|
|
|
|
|
|
|
clean_pte(fl_pte, fl_pte + 1, priv->redirect);
|
|
|
|
fail:
|
|
|
|
return sl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sl_4k(unsigned long *sl_pte, phys_addr_t pa, unsigned int pgprot)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (*sl_pte) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
*sl_pte = (pa & SL_BASE_MASK_SMALL) | SL_NG | SL_SHARED
|
|
|
|
| SL_TYPE_SMALL | pgprot;
|
|
|
|
fail:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sl_64k(unsigned long *sl_pte, phys_addr_t pa, unsigned int pgprot)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
if (*(sl_pte+i)) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
*(sl_pte+i) = (pa & SL_BASE_MASK_LARGE) | SL_NG
|
|
|
|
| SL_SHARED | SL_TYPE_LARGE | pgprot;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int fl_1m(unsigned long *fl_pte, phys_addr_t pa, int pgprot)
|
|
|
|
{
|
|
|
|
if (*fl_pte)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
*fl_pte = (pa & 0xFFF00000) | FL_NG | FL_TYPE_SECT | FL_SHARED
|
|
|
|
| pgprot;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline int fl_16m(unsigned long *fl_pte, phys_addr_t pa, int pgprot)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int ret = 0;
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
if (*(fl_pte+i)) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
*(fl_pte+i) = (pa & 0xFF000000) | FL_SUPERSECTION
|
|
|
|
| FL_TYPE_SECT | FL_SHARED | FL_NG | pgprot;
|
|
|
|
fail:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
static int msm_iommu_map(struct iommu_domain *domain, unsigned long va,
|
2011-11-10 09:32:25 +00:00
|
|
|
phys_addr_t pa, size_t len, int prot)
|
2010-08-25 01:31:10 +00:00
|
|
|
{
|
|
|
|
struct msm_priv *priv;
|
|
|
|
unsigned long *fl_table;
|
|
|
|
unsigned long *fl_pte;
|
|
|
|
unsigned long fl_offset;
|
|
|
|
unsigned long *sl_table;
|
|
|
|
unsigned long *sl_pte;
|
|
|
|
unsigned long sl_offset;
|
2010-11-16 02:20:08 +00:00
|
|
|
unsigned int pgprot;
|
2011-08-12 02:45:23 +00:00
|
|
|
int ret = 0;
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_lock(&msm_iommu_lock);
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2010-11-16 02:20:08 +00:00
|
|
|
priv = domain->priv;
|
2010-08-25 01:31:10 +00:00
|
|
|
if (!priv) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
fl_table = priv->pgtable;
|
|
|
|
|
|
|
|
if (len != SZ_16M && len != SZ_1M &&
|
|
|
|
len != SZ_64K && len != SZ_4K) {
|
|
|
|
pr_debug("Bad size: %d\n", len);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fl_table) {
|
|
|
|
pr_debug("Null page table\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2011-08-12 02:45:23 +00:00
|
|
|
pgprot = __get_pgprot(prot, len);
|
|
|
|
|
|
|
|
if (!pgprot) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
2010-11-16 02:20:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
fl_offset = FL_OFFSET(va); /* Upper 12 bits */
|
|
|
|
fl_pte = fl_table + fl_offset; /* int pointers, 4 bytes */
|
|
|
|
|
|
|
|
if (len == SZ_16M) {
|
2012-07-09 19:27:07 +00:00
|
|
|
ret = fl_16m(fl_pte, pa, pgprot);
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
2012-05-12 01:43:02 +00:00
|
|
|
clean_pte(fl_pte, fl_pte + 16, priv->redirect);
|
2010-08-25 01:31:10 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 02:30:35 +00:00
|
|
|
if (len == SZ_1M) {
|
2012-07-09 19:27:07 +00:00
|
|
|
ret = fl_1m(fl_pte, pa, pgprot);
|
|
|
|
if (ret)
|
2011-07-07 02:30:35 +00:00
|
|
|
goto fail;
|
2012-05-12 01:43:02 +00:00
|
|
|
clean_pte(fl_pte, fl_pte + 1, priv->redirect);
|
2011-07-07 02:30:35 +00:00
|
|
|
}
|
2010-08-25 01:31:10 +00:00
|
|
|
|
|
|
|
/* Need a 2nd level table */
|
2011-07-07 02:30:35 +00:00
|
|
|
if (len == SZ_4K || len == SZ_64K) {
|
|
|
|
|
|
|
|
if (*fl_pte == 0) {
|
2012-07-09 19:27:07 +00:00
|
|
|
if (make_second_level(priv, fl_pte) == NULL) {
|
2011-07-07 02:30:35 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-08-25 01:31:10 +00:00
|
|
|
}
|
|
|
|
|
2011-07-07 02:30:35 +00:00
|
|
|
if (!(*fl_pte & FL_TYPE_TABLE)) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-08-25 01:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sl_table = (unsigned long *) __va(((*fl_pte) & FL_BASE_MASK));
|
|
|
|
sl_offset = SL_OFFSET(va);
|
|
|
|
sl_pte = sl_table + sl_offset;
|
|
|
|
|
2011-07-07 02:30:35 +00:00
|
|
|
if (len == SZ_4K) {
|
2012-07-09 19:27:07 +00:00
|
|
|
ret = sl_4k(sl_pte, pa, pgprot);
|
|
|
|
if (ret)
|
2011-07-07 02:30:35 +00:00
|
|
|
goto fail;
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2012-05-12 01:43:02 +00:00
|
|
|
clean_pte(sl_pte, sl_pte + 1, priv->redirect);
|
2011-07-07 02:30:35 +00:00
|
|
|
}
|
2010-08-25 01:31:10 +00:00
|
|
|
|
|
|
|
if (len == SZ_64K) {
|
2012-07-09 19:27:07 +00:00
|
|
|
ret = sl_64k(sl_pte, pa, pgprot);
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
2012-05-12 01:43:02 +00:00
|
|
|
clean_pte(sl_pte, sl_pte + 16, priv->redirect);
|
2010-08-25 01:31:10 +00:00
|
|
|
}
|
|
|
|
|
2011-08-03 23:24:54 +00:00
|
|
|
ret = __flush_iotlb_va(domain, va);
|
2010-08-25 01:31:10 +00:00
|
|
|
fail:
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_unlock(&msm_iommu_lock);
|
2010-08-25 01:31:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-10 09:32:25 +00:00
|
|
|
static size_t msm_iommu_unmap(struct iommu_domain *domain, unsigned long va,
|
|
|
|
size_t len)
|
2010-08-25 01:31:10 +00:00
|
|
|
{
|
|
|
|
struct msm_priv *priv;
|
|
|
|
unsigned long *fl_table;
|
|
|
|
unsigned long *fl_pte;
|
|
|
|
unsigned long fl_offset;
|
|
|
|
unsigned long *sl_table;
|
|
|
|
unsigned long *sl_pte;
|
|
|
|
unsigned long sl_offset;
|
|
|
|
int i, ret = 0;
|
|
|
|
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_lock(&msm_iommu_lock);
|
2010-08-25 01:31:10 +00:00
|
|
|
|
|
|
|
priv = domain->priv;
|
|
|
|
|
2012-01-26 17:25:37 +00:00
|
|
|
if (!priv)
|
2010-08-25 01:31:10 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
fl_table = priv->pgtable;
|
|
|
|
|
|
|
|
if (len != SZ_16M && len != SZ_1M &&
|
|
|
|
len != SZ_64K && len != SZ_4K) {
|
|
|
|
pr_debug("Bad length: %d\n", len);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fl_table) {
|
|
|
|
pr_debug("Null page table\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
fl_offset = FL_OFFSET(va); /* Upper 12 bits */
|
|
|
|
fl_pte = fl_table + fl_offset; /* int pointers, 4 bytes */
|
|
|
|
|
|
|
|
if (*fl_pte == 0) {
|
|
|
|
pr_debug("First level PTE is 0\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Unmap supersection */
|
2011-08-03 20:38:29 +00:00
|
|
|
if (len == SZ_16M) {
|
2010-08-25 01:31:10 +00:00
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
*(fl_pte+i) = 0;
|
|
|
|
|
2012-05-12 01:43:02 +00:00
|
|
|
clean_pte(fl_pte, fl_pte + 16, priv->redirect);
|
2011-08-03 20:38:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (len == SZ_1M) {
|
2010-08-25 01:31:10 +00:00
|
|
|
*fl_pte = 0;
|
|
|
|
|
2012-05-12 01:43:02 +00:00
|
|
|
clean_pte(fl_pte, fl_pte + 1, priv->redirect);
|
2011-08-03 20:38:29 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
sl_table = (unsigned long *) __va(((*fl_pte) & FL_BASE_MASK));
|
|
|
|
sl_offset = SL_OFFSET(va);
|
|
|
|
sl_pte = sl_table + sl_offset;
|
|
|
|
|
|
|
|
if (len == SZ_64K) {
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
*(sl_pte+i) = 0;
|
2011-08-03 20:38:29 +00:00
|
|
|
|
2012-05-12 01:43:02 +00:00
|
|
|
clean_pte(sl_pte, sl_pte + 16, priv->redirect);
|
2010-08-25 01:31:10 +00:00
|
|
|
}
|
|
|
|
|
2011-08-03 20:38:29 +00:00
|
|
|
if (len == SZ_4K) {
|
2010-08-25 01:31:10 +00:00
|
|
|
*sl_pte = 0;
|
|
|
|
|
2012-05-12 01:43:02 +00:00
|
|
|
clean_pte(sl_pte, sl_pte + 1, priv->redirect);
|
2011-08-03 20:38:29 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
if (len == SZ_4K || len == SZ_64K) {
|
|
|
|
int used = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_SL_PTE; i++)
|
|
|
|
if (sl_table[i])
|
|
|
|
used = 1;
|
|
|
|
if (!used) {
|
|
|
|
free_page((unsigned long)sl_table);
|
|
|
|
*fl_pte = 0;
|
2011-08-03 20:38:29 +00:00
|
|
|
|
2012-05-12 01:43:02 +00:00
|
|
|
clean_pte(fl_pte, fl_pte + 1, priv->redirect);
|
2010-08-25 01:31:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-03 23:24:54 +00:00
|
|
|
ret = __flush_iotlb_va(domain, va);
|
2011-08-12 02:45:23 +00:00
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
fail:
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_unlock(&msm_iommu_lock);
|
2011-11-10 09:32:25 +00:00
|
|
|
|
|
|
|
/* the IOMMU API requires us to return how many bytes were unmapped */
|
|
|
|
len = ret ? 0 : len;
|
|
|
|
return len;
|
2010-08-25 01:31:10 +00:00
|
|
|
}
|
|
|
|
|
2012-03-23 16:26:11 +00:00
|
|
|
static unsigned int get_phys_addr(struct scatterlist *sg)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Try sg_dma_address first so that we can
|
|
|
|
* map carveout regions that do not have a
|
|
|
|
* struct page associated with them.
|
|
|
|
*/
|
|
|
|
unsigned int pa = sg_dma_address(sg);
|
|
|
|
if (pa == 0)
|
|
|
|
pa = sg_phys(sg);
|
|
|
|
return pa;
|
|
|
|
}
|
|
|
|
|
2012-07-09 19:27:07 +00:00
|
|
|
static inline int is_fully_aligned(unsigned int va, phys_addr_t pa, size_t len,
|
|
|
|
int align)
|
|
|
|
{
|
|
|
|
return IS_ALIGNED(va, align) && IS_ALIGNED(pa, align)
|
|
|
|
&& (len >= align);
|
|
|
|
}
|
|
|
|
|
2012-10-05 20:03:45 +00:00
|
|
|
static int check_range(unsigned long *fl_table, unsigned int va,
|
|
|
|
unsigned int len)
|
|
|
|
{
|
|
|
|
unsigned int offset = 0;
|
|
|
|
unsigned long *fl_pte;
|
|
|
|
unsigned long fl_offset;
|
|
|
|
unsigned long *sl_table;
|
|
|
|
unsigned long sl_start, sl_end;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
fl_offset = FL_OFFSET(va); /* Upper 12 bits */
|
|
|
|
fl_pte = fl_table + fl_offset; /* int pointers, 4 bytes */
|
|
|
|
|
|
|
|
while (offset < len) {
|
|
|
|
if (*fl_pte & FL_TYPE_TABLE) {
|
|
|
|
sl_start = SL_OFFSET(va);
|
|
|
|
sl_table = __va(((*fl_pte) & FL_BASE_MASK));
|
|
|
|
sl_end = ((len - offset) / SZ_4K) + sl_start;
|
|
|
|
|
|
|
|
if (sl_end > NUM_SL_PTE)
|
|
|
|
sl_end = NUM_SL_PTE;
|
|
|
|
|
|
|
|
for (i = sl_start; i < sl_end; i++) {
|
|
|
|
if (sl_table[i] != 0) {
|
|
|
|
pr_err("%08x - %08x already mapped\n",
|
|
|
|
va, va + SZ_4K);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
offset += SZ_4K;
|
|
|
|
va += SZ_4K;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sl_start = 0;
|
|
|
|
} else {
|
|
|
|
if (*fl_pte != 0) {
|
|
|
|
pr_err("%08x - %08x already mapped\n",
|
|
|
|
va, va + SZ_1M);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
va += SZ_1M;
|
|
|
|
offset += SZ_1M;
|
|
|
|
sl_start = 0;
|
|
|
|
}
|
|
|
|
fl_pte++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-12 02:45:23 +00:00
|
|
|
static int msm_iommu_map_range(struct iommu_domain *domain, unsigned int va,
|
|
|
|
struct scatterlist *sg, unsigned int len,
|
|
|
|
int prot)
|
|
|
|
{
|
|
|
|
unsigned int pa;
|
msm: kgsl: implement server-side waits
msm: kgsl: Add device init function
Some device specific parameters need to be setup only once during
device initialization. Create an init function for this purpose
rather than re-doing this init everytime the device is started.
Change-Id: I45c7fcda8d61fd2b212044c9167b64f793eedcda
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 2nd commit message:
msm: kgsl: improve active_cnt and ACTIVE state management
Require any code path which intends to touch the hardware
to take a reference on active_cnt with kgsl_active_count_get()
and release it with kgsl_active_count_put() when finished.
These functions now do the wake / sleep steps that were
previously handled by kgsl_check_suspended() and
kgsl_check_idle().
Additionally, kgsl_pre_hwaccess() will no longer turn on
the clocks, it just enforces via BUG_ON that the clocks
are enabled before a register is touched.
Change-Id: I31b0d067e6d600f0228450dbd73f69caa919ce13
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 3rd commit message:
msm: kgsl: Sync memory with CFF from places where it was missing
Before submitting any indirect buffer to GPU via the ringbuffer,
the indirect buffer memory should be synced with CFF so that the
CFF capture will be complete. Add the syncing of memory with CFF
in places where this was missing
Change-Id: I18f506dd1ab7bdfb1a68181016e6f661a36ed5a2
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 4th commit message:
msm: kgsl: Export some kgsl-core functions to EXPORT_SYMBOLS
Export some functions in the KGSL core driver so they can
be seen by the leaf drivers.
Change-Id: Ic0dedbad5dbe562c2e674f8e885a3525b6feac7b
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 5th commit message:
msm: kgsl: Send the right IB size to adreno_find_ctxtmem
adreno_find_ctxtmem expects byte lengths and we were sending it
dword lengths which was about as effective as you would expect.
Change-Id: Ic0dedbad536ed377f6253c3a5e75e5d6cb838acf
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 6th commit message:
msm: kgsl: Add 8974 default GPR0 & clk gating values
Add correct clock gating values for A330, A305 and A320.
Add generic function to return the correct default clock
gating values for the respective gpu. Add default GPR0
value for A330.
Change-Id: I039e8e3622cbda04924b0510e410a9dc95bec598
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 7th commit message:
msm: kgsl: Move A3XX VBIF settings decision to a table
The vbif selection code is turning into a long series of if/else
clauses. Move the decision to a look up table that will be easier
to update and maintain when when we have eleventy A3XX GPUs.
Change-Id: Ic0dedbadd6b16734c91060d7e5fa50dcc9b8774d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 8th commit message:
msm: kgsl: Update settings for the A330v2 GPU in 8972v2
The new GPU spin in 8974v2 has some slightly different settings
then the 8974v1: add support for identifying a v2 spin, add a new
table of VBIF register settings and update the clock gating
registers.
Change-Id: Ic0dedbad22bd3ed391b02f6327267cf32f17af3d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 9th commit message:
msm: kgsl: Fix compilation errors when CFF is turned on
Fix the compilation errors when option MSM_KGSL_CFF_DUMP option
is turned on.
Change-Id: I59b0a7314ba77e2c2fef03338e061cd503e88714
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 10th commit message:
msm: kgsl: Convert the Adreno GPU cycle counters to run free
In anticipation of allowing multiple entities to share access to the
performance counters; make the few performance counters that KGSL
uses run free.
Change-Id: Ic0dedbadbefb400b04e4f3552eed395770ddbb7b
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 11th commit message:
msm: kgsl: Handle a possible ringbuffer allocspace error
In the GPU specific start functions, account for the possibility
that ringbuffer allocation routine might return NULL.
Change-Id: Ic0dedbadf6199fee78b6a8c8210a1e76961873a0
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 12th commit message:
msm: kgsl: Add a new API to allow sharing of GPU performance counters
Adreno uses programmable performance counters, meaning that while there
are a limited number of physical counters each counter can be programmed
to count a vast number of different measurements (we refer to these as
countables). This could cause problems if multiple apps want to use
the performance counters, so this API and infrastructure allows the
counters to be safely shared.
The kernel tracks which countable is selected for each of the physical
counters for each counter group (where groups closely match hardware
blocks). If the desired countable is already in use, or there is an
open physical counter, then the process is allowed to use the counter.
The get ioctl reserves the counter and returns the dword offset of the
register associated with that physical counter. The put ioctl
releases the physical counter. The query ioctl gets the countables
used for all of the counters in the block - up to 8 values can be
returned. The read ioctl gets the current hardware value in the counter
Change-Id: Ic0dedbadae1dedadba60f8a3e685e2ce7d84fb33
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
# This is the 13th commit message:
msm: kgsl: Print the nearest active GPU buffers to a faulting address
Print the two active GPU memory entries that bracket a faulting GPU
address. This will help diagnose premature frees and buffer ovverruns.
Check if the faulting GPU address was freed by the same process.
Change-Id: Ic0dedbadebf57be9abe925a45611de8e597447ea
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Vladimir Razgulin <vrazguli@codeaurora.org>
# This is the 14th commit message:
msm: kgsl: Remove an uneeded register write for A3XX GPUs
A3XX doesn't have the MH block and so the register at 0x40 points
somewhere else. Luckily the write was harmless but remove it anyway.
Change-Id: Ic0dedbadd1e043cd38bbaec8fcf0c490dcdedc8c
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 15th commit message:
msm: kgsl: clean up iommu/gpummu protflag handling
Make kgsl_memdesc_protflags() return the correct type of flags
for the type of mmu being used. Query the memdesc with this
function in kgsl_mmu_map(), rather than passing in the
protflags. This prevents translation at multiple layers of
the code and makes it easier to enforce that the mapping matches
the allocation flags.
Change-Id: I2a2f4a43026ae903dd134be00e646d258a83f79f
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 16th commit message:
msm: kgsl: remove kgsl_mem_entry.flags
The two flags fields in kgsl_memdesc should be enough for
anyone. Move the only flag using kgsl_mem_entry, the
FROZEN flag for snapshot procesing, to use kgsl_memdesc.priv.
Change-Id: Ia12b9a6e6c1f5b5e57fa461b04ecc3d1705f2eaf
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 17th commit message:
msm: kgsl: map the guard page readonly on the iommu
The guard page needs to be readable by the GPU, due to
a prefetch range issue, but it should never be writable.
Change the page fault message to indicate if nearby
buffers have a guard page.
Change-Id: I3955de1409cbf4ccdde92def894945267efa044d
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 18th commit message:
msm: kgsl: Add support for VBIF and VBIF_PWR performance counters
These 2 counter groups are also "special cases" that require
different programming sequences.
Change-Id: I73e3e76b340e6c5867c0909b3e0edc78aa62b9ee
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 19th commit message:
msm: kgsl: Only allow two counters for VBIF performance counters
There are only two VBIF counter groups so validate that the user
doesn't pass in > 1 and clean up the if/else clause.
Change-Id: Ic0dedbad3d5a54e4ceb1a7302762d6bf13b25da1
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 20th commit message:
msm: kgsl: Avoid an array overrun in the perfcounter API
Make sure the passed group is less than the size of the list of
performance counters.
Change-Id: Ic0dedbadf77edf35db78939d1b55a05830979f85
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 21st commit message:
msm: kgsl: Don't go to slumber if active_count is non zero
If active_cnt happens to be set when we go into
kgsl_early_suspend_driver() then don't go to SLUMBER. This
avoids trouble if we come back and and try to access the
hardware while it is off.
Change-Id: Ic0dedbadb13514a052af6199c8ad1982d7483b3f
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 22nd commit message:
msm: kgsl: Enable HLSQ registers in snapshot when available
Reading the HLSQ registers during a GPU hang recovery might cause
the device to hang depending on the state of the HLSQ block.
Enable the HLSQ register reads when we know that they will
succeed.
Change-Id: I69f498e6f67a15328d1d41cc64c43d6c44c54bad
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 23rd commit message:
msm: kgsl: snapshot: Don't keep parsing indirect buffers on failure
Stop parsing an indirect buffer if an error is encountered (such as
a missing buffer). This is a pretty good indication that the buffers
are not reliable and the further the parser goes with a unreliable
buffer the more likely it is to get confused.
Change-Id: Ic0dedbadf28ef374c9afe70613048d3c31078ec6
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 24th commit message:
msm: kgsl: snapshot: Only push the last IB1 and IB2 in the static space
Some IB1 buffers have hundreds of little IB2 buffers and only one of them
will actually be interesting enough to push into the static space. Only
push the last executed IB1 and IB2 into the static space.
Change-Id: Ic0dedbad26fb30fb5bf90c37c29061fd962dd746
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 25th commit message:
msm: kgsl: Save the last active context in snapshot
Save the last active context that was executing when the hang happened
in snapshot.
Change-Id: I2d32de6873154ec6c200268844fee7f3947b7395
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 26th commit message:
msm: kgsl: In snapshot track a larger object size if address is same
If the object being tracked has the same address as a previously
tracked object then only track a single object with larger size
as the smaller object will be a part of the larger one anyway.
Change-Id: I0e33bbaf267bc0ec580865b133917b3253f9e504
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 27th commit message:
msm: kgsl: Track memory address from 2 additional registers
Add tracking of memory referenced by VS_OBJ_START_REG and FS_OBJ_START_REG
registers in snapshot. This makes snapshot more complete in terms of
tracking data that is used by the GPU at the time of hang.
Change-Id: I7e5f3c94f0d6744cd6f2c6413bf7b7fac4a5a069
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 28th commit message:
msm: kgsl: Loop till correct index on type0 packets
When searching for memory addresses in type0 packet we were looping
from start of the type0 packet till it's end, but the first DWORD
is a header so we only need to loop till packet_size - 1. Fix this.
Change-Id: I278446c6ab380cf8ebb18d5f3ae192d3d7e7db62
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 29th commit message:
msm: kgsl: Add global timestamp information to snapshot
Make sure that we always add global timestamp information to
snapshot. This is needed in playbacks for searching whereabouts
of last executed IB.
Change-Id: Ica5b3b2ddff6fd45dbc5a911f42271ad5855a86a
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 30th commit message:
msm: kgsl: Skip cff dump for certain functions when its disabled
Certain functions were generating CFF when CFF was disabled. Make
sure these functions do not dump CFF when it is disabled.
Change-Id: Ib5485b03b8a4d12f190f188b80c11ec6f552731d
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 31st commit message:
msm: kgsl: Fix searching of memory object
Make sure that at least a size of 1 byte is searched when locating
the memory entry of a region. If size is 0 then a memory region
whose last address is equal to the start address of the memory being
searched will be returned which is wrong.
Change-Id: I643185d1fdd17296bd70fea483aa3c365e691bc5
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 32nd commit message:
msm: kgsl: If adreno start fails then restore state of device
Restore the state of the device back to what it was at the
start of the adreno_start function if this function fails to
execute successfully.
Change-Id: I5b279e5186b164d3361fba7c8f8d864395b794c8
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 33rd commit message:
msm: kgsl: Fix early exit condition in ringbuffer drain
The ringbuffer drain function can be called when the ringbuffer
start flag is not set. This happens on startup. Hence,
exiting the function early based on start flag is incorrect.
Simply execute this function regardless of the start flag.
Change-Id: Ibf2075847f8bb1a760bc1550309efb3c7aa1ca49
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 34th commit message:
msm: kgsl: Do not return an error on NULL gpu address
If a NULL gpu address is passed to snapshot object tracking
function then do not treat this as an error and return 0. NULL
objects may be present in an IB so just skip over these objects
instead of exiting due to an error.
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Change-Id: Ic253722c58b41f41d03f83c77017e58365da01a7
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 35th commit message:
msm: kgsl: Don't hold process list global mutex in process private create
Don't hold process list global mutex for long. Instead make
use of process specific spin_lock() to serialize access
to process private structure while creating it. Holding
process list global mutex could lead to deadlocks as other
functions depend on it.
CRs-fixed: 480732
Change-Id: Id54316770f911d0e23384f54ba5c14a1c9113680
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 36th commit message:
msm: kgsl: Use CPU path to program pagetable when active count is 0
When active count is 0 then we should use the CPU path to program
pagetables because the GPU path requires event registration. Events
can only be queued when active count is valid. Hence, if the active
count is NULL then use the CPU path.
Change-Id: I70f5894d20796bdc0f592db7dc2731195c0f7a82
CRs-fixed: 481887
Signed-off-by: Shubhrapralash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 37th commit message:
iommu: msm: prevent partial mappings on error
If msm_iommu_map_range() fails mid way through the va
range with an error, clean up the PTEs that have already
been created so they are not leaked.
Change-Id: Ie929343cd6e36cade7b2cc9b4b4408c3453e6b5f
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 38th commit message:
msm: kgsl: better handling of virtual address fragmentation
When KGSL_MEMFLAGS_USE_CPU_MAP is enabled, the mmap address
must try to match the GPU alignment requirements of the buffer,
as well as include space in the mapping for the guard page.
This can cause -ENOMEM to be returned from get_unmapped_area()
when there are a large number of mappings. When this happens,
fall back to page alignment and retry to avoid failure.
Change-Id: I2176fe57afc96d8cf1fe1c694836305ddc3c3420
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 39th commit message:
iommu: msm: Don't treat address 0 as an error case
Currently, the iommu page table code treats a scattergather
list with physical address 0 as an error. This may not be
correct in all cases. Physical address 0 is a valid part
of the system and may be used for valid page allocations.
Nothing else in the system checks for physical address 0
for error so don't treat it as an error.
Change-Id: Ie9f0dae9dace4fff3b1c3449bc89c3afdd2e63a0
CRs-Fixed: 478304
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 40th commit message:
msm: kgsl: prevent race between mmap() and free on timestamp
When KGSL_MEMFLAGS_USE_CPU_MAP is set, we must check that the
address from get_unmapped_area() is not used as part of a
mapping that is present only in the GPU pagetable and not the
CPU pagetable. These mappings can occur because when a buffer
is freed on timestamp, the CPU mapping is destroyed immediately
but the GPU mapping is not destroyed until the GPU timestamp
has passed.
Because kgsl_mem_entry_detach_process() removed the rbtree
entry before removing the iommu mapping, there was a window
of time where kgsl thought the address was available even
though it was still present in the iommu pagetable. This
could cause the address to get assigned to a new buffer,
which would cause iommu_map_range() to fail since the old
mapping was still in the pagetable. Prevent this race by
removing the iommu mapping before removing the rbtree entry
tracking the address.
Change-Id: I8f42d6d97833293b55fcbc272d180564862cef8a
CRs-Fixed: 480222
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 41st commit message:
msm: kgsl: add guard page support for imported memory
Imported memory buffers sometimes do not have enough
padding to prevent page faults due to overzealous
GPU prefetch. Attach guard pages to their mappings
to prevent these faults.
Because we don't create the scatterlist for some
types of imported memory, such as ion, the guard
page is no longer included as the last entry in
the scatterlist. Instead, it is handled by
size ajustments and a separate iommu_map() call
in the kgsl_mmu_map() and kgsl_mmu_unmap() paths.
Change-Id: I3af3c29c3983f8cacdc366a2423f90c8ecdc3059
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 42nd commit message:
msm: kgsl: fix kgsl_mem_entry refcounting
Make kgsl_sharedmem_find* return a reference to the
entry that was found. This makes using an entry
without the mem_lock held less race prone.
Change-Id: If6eb6470ecfea1332d3130d877922c70ca037467
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 43rd commit message:
msm: kgsl: add ftrace for cache operations
Add the event kgsl_mem_sync_cache. This event is
emitted when only a cache operation is actually
performed. Attempts to flush uncached memory,
which do nothing, do not cause this event.
Change-Id: Id4a940a6b50e08b54fbef0025c4b8aaa71641462
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 44th commit message:
msm: kgsl: Add support for bulk cache operations
Add a new ioctl, IOCTL_KGSL_GPUMEM_SYNC_CACHE_BULK, which can be used
to sync a number of memory ids at once. This gives the driver an
opportunity to optimize the cache operations based on the total
working set of memory that needs to be managed.
Change-Id: I9693c54cb6f12468b7d9abb0afaef348e631a114
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 45th commit message:
msm: kgsl: flush the entire cache when the bulk batch is large
On 8064 and 8974, flushing more than 16mb of virtual address
space is slower than flushing the entire cache. So flush
the entire cache when the working set is larger than this.
The threshold for full cache flush can be tuned at runtime via
the full_cache_threshold sysfs file.
Change-Id: If525e4c44eb043d0afc3fe42d7ef2c7de0ba2106
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 46th commit message:
msm: kgsl: Use a read/lock for the context idr
Everybody loves a rcu but in this case we are dangerously mixing rcus and
atomic operations. Add a read/write lock to explicitly protect the idr.
Also fix a few spots where the idr was used without protection.
Change-Id: Ic0dedbad517a9f89134cbcf7af29c8bf0f034708
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 47th commit message:
msm: kgsl: embed kgsl_context struct in adreno_context struct
Having a separate allocated struct for the device specific context
makes ownership unclear, which could lead to reference counting
problems or invalid pointers. Also, duplicate members were
starting to appear in adreno_context because there wasn't a safe
way to reach the kgsl_context from some parts of the adreno code.
This can now be done via container_of().
This change alters the lifecycle of the context->id, which is
now freed when the context reference count hits zero rather
than in kgsl_context_detach().
It also changes the context creation and destruction sequence.
The device specific code must allocate a structure containing
a struct kgsl_context and passes a pointer it to kgsl_init_context()
before doing any device specific initialization. There is also a
separate drawctxt_detach() callback for doing device specific
cleanup. This is separate from freeing memory, which is done
by the drawctxt_destroy() callback.
Change-Id: I7d238476a3bfec98fd8dbc28971cf3187a81dac2
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 48th commit message:
msm: kgsl: Take a reference count on the active adreno draw context
Take a reference count on the currently active draw context to keep
it from going away while we are maintaining a pointer to it in the
adreno device.
Change-Id: Ic0dedbade8c09ecacf822e9a3c5fbaf6e017ec0c
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 49th commit message:
msm: kgsl: Add a command dispatcher to manage the ringbuffer
Implements a centralized dispatcher for sending user commands
to the ringbuffer. Incoming commands are queued by context and
sent to the hardware on a round robin basis ensuring each context
a small burst of commands at a time. Each command is tracked
throughout the pipeline giving the dispatcher better knowledge
of how the hardware is being used. This will be the basis for
future per-context and cross context enhancements as priority
queuing and server-side syncronization.
Change-Id: Ic0dedbad49a43e8e6096d1362829c800266c2de3
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 50th commit message:
msm: kgsl: Only turn on the idle timer when active_cnt is 0
Only turn on the idle timer when the GPU expected to be quiet.
Change-Id: Ic0dedbad57846f1e7bf7820ec3152cd20598b448
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 51st commit message:
msm: kgsl: Add a ftrace event for active_cnt
Add a new ftrace event for watching the rise and fall of active_cnt:
echo 1 > /sys/kernel/debug/tracing/events/kgsl/kgsl_active_count/enable
This will give you the current active count and the caller of the function:
kgsl_active_count: d_name=kgsl-3d0 active_cnt=8e9 func=kgsl_ioctl
Change-Id: Ic0dedbadc80019e96ce759d9d4e0ad43bbcfedd2
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 52nd commit message:
msm: kgsl: Implement KGSL fault tolerance policy in the dispatcher
Implement the KGSL fault tolerance policy for faults in the dispatcher.
Replay (or skip) the inflight command batches as dictated by the policy,
iterating progressively through the various behaviors.
Change-Id: Ic0dedbade98cc3aa35b26813caf4265c74ccab56
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 53rd commit message:
msm: kgsl: Don't process events if the timestamp hasn't changed
Keep track of the global timestamp every time the event code runs.
If the timestamp hasn't changed then we are caught up and we can
politely bow out. This avoids the situation where multiple
interrupts queue the work queue multiple times:
IRQ
-> process events
IRQ
IRQ
-> process events
The actual retired timestamp in the first work item might be well
ahead of the delivered interrupts. The event loop will end up
processing every event that has been retired by the hardware
at that point. If the work item gets re-queued by a subesquent
interrupt then we might have already addressed all the pending
timestamps.
Change-Id: Ic0dedbad79722654cb17e82b7149e93d3c3f86a0
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 54th commit message:
msm: kgsl: Make active_cnt an atomic variable
In kgsl_active_cnt_light() the mutex was needed just to check and
increment the active_cnt value. Move active_cnt to an atomic to
begin the task of freeing ourselves from the grip of the device
mutex if we can avoid it.
Change-Id: Ic0dedbad78e086e3aa3559fab8ecebc43539f769
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 55th commit message:
msm: kgsl: Add a new command submission API
Add an new ioctl entry point for submitting commands to the GPU
called IOCTL_KGSL_SUBMIT_COMMANDS.
As with IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS the user passes a list of
indirect buffers, flags and optionally a user specified timestamp. The
old way of passing a list of indirect buffers is no longer supported.
IOCTL_KGSL_SUBMIT_COMMANDS also allows the user to define a
list of sync points for the command. Sync points are dependencies
on events that need to be satisfied before the command will be issued
to the hardware. Events are designed to be flexible. To start with
the only events that are supported are GPU events for a given context/
timestamp pair.
Pending events are stored in a list in the command batch. As each event is
expired it is deleted from the list. The adreno dispatcher won't send the
command until the list is empty. Sync points are not supported for Z180.
CRs-Fixed: 468770
Change-Id: Ic0dedbad5a5935f486acaeb033ae9a6010f82346
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 56th commit message:
msm: kgsl: add kgsl_sync_fence_waiter for server side sync
For server side sync the KGSL kernel module needs to perform
an asynchronous wait for a fence object prior to issuing
subsequent commands.
Change-Id: I1ee614aa3af84afc4813f1e47007f741beb3bc92
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 57th commit message:
msm: kgsl: Add support for KGSL_CMD_SYNCPOINT_TYPE_FENCE
Allow command batches to wait for external fence sync events.
Change-Id: Ic0dedbad3a211019e1cd3a3d62ab6a3e4d4eeb05
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 58th commit message:
msm: kgsl: fix potential double free of the kwaiter
Change-Id: Ic0dedbad66a0af6eaef52b2ad53c067110bdc6e4
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 59th commit message:
msm: kgsl: free an event only after canceling successfully
Change-Id: Ic0dedbade256443d090dd11df452dc9cdf65530b
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
2013-06-24 17:40:20 +00:00
|
|
|
unsigned int start_va = va;
|
2011-08-12 02:45:23 +00:00
|
|
|
unsigned int offset = 0;
|
|
|
|
unsigned long *fl_table;
|
|
|
|
unsigned long *fl_pte;
|
|
|
|
unsigned long fl_offset;
|
2012-07-09 19:27:07 +00:00
|
|
|
unsigned long *sl_table = NULL;
|
2011-08-12 02:45:23 +00:00
|
|
|
unsigned long sl_offset, sl_start;
|
2012-07-09 19:27:07 +00:00
|
|
|
unsigned int chunk_size, chunk_offset = 0;
|
2011-08-12 02:45:23 +00:00
|
|
|
int ret = 0;
|
|
|
|
struct msm_priv *priv;
|
2012-07-09 19:27:07 +00:00
|
|
|
unsigned int pgprot4k, pgprot64k, pgprot1m, pgprot16m;
|
2011-08-12 02:45:23 +00:00
|
|
|
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_lock(&msm_iommu_lock);
|
2011-08-12 02:45:23 +00:00
|
|
|
|
|
|
|
BUG_ON(len & (SZ_4K - 1));
|
|
|
|
|
|
|
|
priv = domain->priv;
|
|
|
|
fl_table = priv->pgtable;
|
|
|
|
|
2012-07-09 19:27:07 +00:00
|
|
|
pgprot4k = __get_pgprot(prot, SZ_4K);
|
|
|
|
pgprot64k = __get_pgprot(prot, SZ_64K);
|
|
|
|
pgprot1m = __get_pgprot(prot, SZ_1M);
|
|
|
|
pgprot16m = __get_pgprot(prot, SZ_16M);
|
2011-08-12 02:45:23 +00:00
|
|
|
|
2012-07-09 19:27:07 +00:00
|
|
|
if (!pgprot4k || !pgprot64k || !pgprot1m || !pgprot16m) {
|
2011-08-12 02:45:23 +00:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-10-05 20:03:45 +00:00
|
|
|
ret = check_range(fl_table, va, len);
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
2011-08-12 02:45:23 +00:00
|
|
|
|
|
|
|
fl_offset = FL_OFFSET(va); /* Upper 12 bits */
|
|
|
|
fl_pte = fl_table + fl_offset; /* int pointers, 4 bytes */
|
2012-07-09 19:27:07 +00:00
|
|
|
pa = get_phys_addr(sg);
|
2011-08-12 02:45:23 +00:00
|
|
|
|
2012-07-09 19:27:07 +00:00
|
|
|
while (offset < len) {
|
|
|
|
chunk_size = SZ_4K;
|
|
|
|
|
|
|
|
if (is_fully_aligned(va, pa, sg->length - chunk_offset,
|
|
|
|
SZ_16M))
|
|
|
|
chunk_size = SZ_16M;
|
|
|
|
else if (is_fully_aligned(va, pa, sg->length - chunk_offset,
|
|
|
|
SZ_1M))
|
|
|
|
chunk_size = SZ_1M;
|
|
|
|
/* 64k or 4k determined later */
|
|
|
|
|
|
|
|
/* for 1M and 16M, only first level entries are required */
|
|
|
|
if (chunk_size >= SZ_1M) {
|
|
|
|
if (chunk_size == SZ_16M) {
|
|
|
|
ret = fl_16m(fl_pte, pa, pgprot16m);
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
|
|
|
clean_pte(fl_pte, fl_pte + 16, priv->redirect);
|
|
|
|
fl_pte += 16;
|
|
|
|
} else if (chunk_size == SZ_1M) {
|
|
|
|
ret = fl_1m(fl_pte, pa, pgprot1m);
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
|
|
|
clean_pte(fl_pte, fl_pte + 1, priv->redirect);
|
|
|
|
fl_pte++;
|
|
|
|
}
|
2011-08-12 02:45:23 +00:00
|
|
|
|
2012-07-09 19:27:07 +00:00
|
|
|
offset += chunk_size;
|
|
|
|
chunk_offset += chunk_size;
|
|
|
|
va += chunk_size;
|
|
|
|
pa += chunk_size;
|
2011-08-12 02:45:23 +00:00
|
|
|
|
2012-07-09 19:27:07 +00:00
|
|
|
if (chunk_offset >= sg->length && offset < len) {
|
|
|
|
chunk_offset = 0;
|
|
|
|
sg = sg_next(sg);
|
|
|
|
pa = get_phys_addr(sg);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* for 4K or 64K, make sure there is a second level table */
|
2011-08-12 02:45:23 +00:00
|
|
|
if (*fl_pte == 0) {
|
2012-07-09 19:27:07 +00:00
|
|
|
if (!make_second_level(priv, fl_pte)) {
|
2011-08-12 02:45:23 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
2012-07-09 19:27:07 +00:00
|
|
|
}
|
|
|
|
if (!(*fl_pte & FL_TYPE_TABLE)) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
sl_table = __va(((*fl_pte) & FL_BASE_MASK));
|
|
|
|
sl_offset = SL_OFFSET(va);
|
2011-08-12 02:45:23 +00:00
|
|
|
/* Keep track of initial position so we
|
|
|
|
* don't clean more than we have to
|
|
|
|
*/
|
|
|
|
sl_start = sl_offset;
|
|
|
|
|
|
|
|
/* Build the 2nd level page table */
|
|
|
|
while (offset < len && sl_offset < NUM_SL_PTE) {
|
|
|
|
|
2012-07-09 19:27:07 +00:00
|
|
|
/* Map a large 64K page if the chunk is large enough and
|
|
|
|
* the pa and va are aligned
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (is_fully_aligned(va, pa, sg->length - chunk_offset,
|
|
|
|
SZ_64K))
|
|
|
|
chunk_size = SZ_64K;
|
|
|
|
else
|
|
|
|
chunk_size = SZ_4K;
|
|
|
|
|
|
|
|
if (chunk_size == SZ_4K) {
|
|
|
|
sl_4k(&sl_table[sl_offset], pa, pgprot4k);
|
|
|
|
sl_offset++;
|
|
|
|
} else {
|
|
|
|
BUG_ON(sl_offset + 16 > NUM_SL_PTE);
|
|
|
|
sl_64k(&sl_table[sl_offset], pa, pgprot64k);
|
|
|
|
sl_offset += 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
offset += chunk_size;
|
|
|
|
chunk_offset += chunk_size;
|
|
|
|
va += chunk_size;
|
|
|
|
pa += chunk_size;
|
2011-08-12 02:45:23 +00:00
|
|
|
|
|
|
|
if (chunk_offset >= sg->length && offset < len) {
|
|
|
|
chunk_offset = 0;
|
|
|
|
sg = sg_next(sg);
|
2012-07-09 19:27:07 +00:00
|
|
|
pa = get_phys_addr(sg);
|
2011-08-12 02:45:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-12 01:43:02 +00:00
|
|
|
clean_pte(sl_table + sl_start, sl_table + sl_offset,
|
2012-07-09 19:27:07 +00:00
|
|
|
priv->redirect);
|
2011-08-12 02:45:23 +00:00
|
|
|
|
|
|
|
fl_pte++;
|
|
|
|
sl_offset = 0;
|
|
|
|
}
|
|
|
|
__flush_iotlb(domain);
|
|
|
|
fail:
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_unlock(&msm_iommu_lock);
|
msm: kgsl: implement server-side waits
msm: kgsl: Add device init function
Some device specific parameters need to be setup only once during
device initialization. Create an init function for this purpose
rather than re-doing this init everytime the device is started.
Change-Id: I45c7fcda8d61fd2b212044c9167b64f793eedcda
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 2nd commit message:
msm: kgsl: improve active_cnt and ACTIVE state management
Require any code path which intends to touch the hardware
to take a reference on active_cnt with kgsl_active_count_get()
and release it with kgsl_active_count_put() when finished.
These functions now do the wake / sleep steps that were
previously handled by kgsl_check_suspended() and
kgsl_check_idle().
Additionally, kgsl_pre_hwaccess() will no longer turn on
the clocks, it just enforces via BUG_ON that the clocks
are enabled before a register is touched.
Change-Id: I31b0d067e6d600f0228450dbd73f69caa919ce13
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 3rd commit message:
msm: kgsl: Sync memory with CFF from places where it was missing
Before submitting any indirect buffer to GPU via the ringbuffer,
the indirect buffer memory should be synced with CFF so that the
CFF capture will be complete. Add the syncing of memory with CFF
in places where this was missing
Change-Id: I18f506dd1ab7bdfb1a68181016e6f661a36ed5a2
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 4th commit message:
msm: kgsl: Export some kgsl-core functions to EXPORT_SYMBOLS
Export some functions in the KGSL core driver so they can
be seen by the leaf drivers.
Change-Id: Ic0dedbad5dbe562c2e674f8e885a3525b6feac7b
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 5th commit message:
msm: kgsl: Send the right IB size to adreno_find_ctxtmem
adreno_find_ctxtmem expects byte lengths and we were sending it
dword lengths which was about as effective as you would expect.
Change-Id: Ic0dedbad536ed377f6253c3a5e75e5d6cb838acf
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 6th commit message:
msm: kgsl: Add 8974 default GPR0 & clk gating values
Add correct clock gating values for A330, A305 and A320.
Add generic function to return the correct default clock
gating values for the respective gpu. Add default GPR0
value for A330.
Change-Id: I039e8e3622cbda04924b0510e410a9dc95bec598
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 7th commit message:
msm: kgsl: Move A3XX VBIF settings decision to a table
The vbif selection code is turning into a long series of if/else
clauses. Move the decision to a look up table that will be easier
to update and maintain when when we have eleventy A3XX GPUs.
Change-Id: Ic0dedbadd6b16734c91060d7e5fa50dcc9b8774d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 8th commit message:
msm: kgsl: Update settings for the A330v2 GPU in 8972v2
The new GPU spin in 8974v2 has some slightly different settings
then the 8974v1: add support for identifying a v2 spin, add a new
table of VBIF register settings and update the clock gating
registers.
Change-Id: Ic0dedbad22bd3ed391b02f6327267cf32f17af3d
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 9th commit message:
msm: kgsl: Fix compilation errors when CFF is turned on
Fix the compilation errors when option MSM_KGSL_CFF_DUMP option
is turned on.
Change-Id: I59b0a7314ba77e2c2fef03338e061cd503e88714
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 10th commit message:
msm: kgsl: Convert the Adreno GPU cycle counters to run free
In anticipation of allowing multiple entities to share access to the
performance counters; make the few performance counters that KGSL
uses run free.
Change-Id: Ic0dedbadbefb400b04e4f3552eed395770ddbb7b
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 11th commit message:
msm: kgsl: Handle a possible ringbuffer allocspace error
In the GPU specific start functions, account for the possibility
that ringbuffer allocation routine might return NULL.
Change-Id: Ic0dedbadf6199fee78b6a8c8210a1e76961873a0
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 12th commit message:
msm: kgsl: Add a new API to allow sharing of GPU performance counters
Adreno uses programmable performance counters, meaning that while there
are a limited number of physical counters each counter can be programmed
to count a vast number of different measurements (we refer to these as
countables). This could cause problems if multiple apps want to use
the performance counters, so this API and infrastructure allows the
counters to be safely shared.
The kernel tracks which countable is selected for each of the physical
counters for each counter group (where groups closely match hardware
blocks). If the desired countable is already in use, or there is an
open physical counter, then the process is allowed to use the counter.
The get ioctl reserves the counter and returns the dword offset of the
register associated with that physical counter. The put ioctl
releases the physical counter. The query ioctl gets the countables
used for all of the counters in the block - up to 8 values can be
returned. The read ioctl gets the current hardware value in the counter
Change-Id: Ic0dedbadae1dedadba60f8a3e685e2ce7d84fb33
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
# This is the 13th commit message:
msm: kgsl: Print the nearest active GPU buffers to a faulting address
Print the two active GPU memory entries that bracket a faulting GPU
address. This will help diagnose premature frees and buffer ovverruns.
Check if the faulting GPU address was freed by the same process.
Change-Id: Ic0dedbadebf57be9abe925a45611de8e597447ea
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Vladimir Razgulin <vrazguli@codeaurora.org>
# This is the 14th commit message:
msm: kgsl: Remove an uneeded register write for A3XX GPUs
A3XX doesn't have the MH block and so the register at 0x40 points
somewhere else. Luckily the write was harmless but remove it anyway.
Change-Id: Ic0dedbadd1e043cd38bbaec8fcf0c490dcdedc8c
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 15th commit message:
msm: kgsl: clean up iommu/gpummu protflag handling
Make kgsl_memdesc_protflags() return the correct type of flags
for the type of mmu being used. Query the memdesc with this
function in kgsl_mmu_map(), rather than passing in the
protflags. This prevents translation at multiple layers of
the code and makes it easier to enforce that the mapping matches
the allocation flags.
Change-Id: I2a2f4a43026ae903dd134be00e646d258a83f79f
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 16th commit message:
msm: kgsl: remove kgsl_mem_entry.flags
The two flags fields in kgsl_memdesc should be enough for
anyone. Move the only flag using kgsl_mem_entry, the
FROZEN flag for snapshot procesing, to use kgsl_memdesc.priv.
Change-Id: Ia12b9a6e6c1f5b5e57fa461b04ecc3d1705f2eaf
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 17th commit message:
msm: kgsl: map the guard page readonly on the iommu
The guard page needs to be readable by the GPU, due to
a prefetch range issue, but it should never be writable.
Change the page fault message to indicate if nearby
buffers have a guard page.
Change-Id: I3955de1409cbf4ccdde92def894945267efa044d
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 18th commit message:
msm: kgsl: Add support for VBIF and VBIF_PWR performance counters
These 2 counter groups are also "special cases" that require
different programming sequences.
Change-Id: I73e3e76b340e6c5867c0909b3e0edc78aa62b9ee
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 19th commit message:
msm: kgsl: Only allow two counters for VBIF performance counters
There are only two VBIF counter groups so validate that the user
doesn't pass in > 1 and clean up the if/else clause.
Change-Id: Ic0dedbad3d5a54e4ceb1a7302762d6bf13b25da1
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 20th commit message:
msm: kgsl: Avoid an array overrun in the perfcounter API
Make sure the passed group is less than the size of the list of
performance counters.
Change-Id: Ic0dedbadf77edf35db78939d1b55a05830979f85
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 21st commit message:
msm: kgsl: Don't go to slumber if active_count is non zero
If active_cnt happens to be set when we go into
kgsl_early_suspend_driver() then don't go to SLUMBER. This
avoids trouble if we come back and and try to access the
hardware while it is off.
Change-Id: Ic0dedbadb13514a052af6199c8ad1982d7483b3f
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 22nd commit message:
msm: kgsl: Enable HLSQ registers in snapshot when available
Reading the HLSQ registers during a GPU hang recovery might cause
the device to hang depending on the state of the HLSQ block.
Enable the HLSQ register reads when we know that they will
succeed.
Change-Id: I69f498e6f67a15328d1d41cc64c43d6c44c54bad
Signed-off-by: Carter Cooper <ccooper@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 23rd commit message:
msm: kgsl: snapshot: Don't keep parsing indirect buffers on failure
Stop parsing an indirect buffer if an error is encountered (such as
a missing buffer). This is a pretty good indication that the buffers
are not reliable and the further the parser goes with a unreliable
buffer the more likely it is to get confused.
Change-Id: Ic0dedbadf28ef374c9afe70613048d3c31078ec6
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 24th commit message:
msm: kgsl: snapshot: Only push the last IB1 and IB2 in the static space
Some IB1 buffers have hundreds of little IB2 buffers and only one of them
will actually be interesting enough to push into the static space. Only
push the last executed IB1 and IB2 into the static space.
Change-Id: Ic0dedbad26fb30fb5bf90c37c29061fd962dd746
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 25th commit message:
msm: kgsl: Save the last active context in snapshot
Save the last active context that was executing when the hang happened
in snapshot.
Change-Id: I2d32de6873154ec6c200268844fee7f3947b7395
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 26th commit message:
msm: kgsl: In snapshot track a larger object size if address is same
If the object being tracked has the same address as a previously
tracked object then only track a single object with larger size
as the smaller object will be a part of the larger one anyway.
Change-Id: I0e33bbaf267bc0ec580865b133917b3253f9e504
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 27th commit message:
msm: kgsl: Track memory address from 2 additional registers
Add tracking of memory referenced by VS_OBJ_START_REG and FS_OBJ_START_REG
registers in snapshot. This makes snapshot more complete in terms of
tracking data that is used by the GPU at the time of hang.
Change-Id: I7e5f3c94f0d6744cd6f2c6413bf7b7fac4a5a069
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 28th commit message:
msm: kgsl: Loop till correct index on type0 packets
When searching for memory addresses in type0 packet we were looping
from start of the type0 packet till it's end, but the first DWORD
is a header so we only need to loop till packet_size - 1. Fix this.
Change-Id: I278446c6ab380cf8ebb18d5f3ae192d3d7e7db62
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 29th commit message:
msm: kgsl: Add global timestamp information to snapshot
Make sure that we always add global timestamp information to
snapshot. This is needed in playbacks for searching whereabouts
of last executed IB.
Change-Id: Ica5b3b2ddff6fd45dbc5a911f42271ad5855a86a
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 30th commit message:
msm: kgsl: Skip cff dump for certain functions when its disabled
Certain functions were generating CFF when CFF was disabled. Make
sure these functions do not dump CFF when it is disabled.
Change-Id: Ib5485b03b8a4d12f190f188b80c11ec6f552731d
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 31st commit message:
msm: kgsl: Fix searching of memory object
Make sure that at least a size of 1 byte is searched when locating
the memory entry of a region. If size is 0 then a memory region
whose last address is equal to the start address of the memory being
searched will be returned which is wrong.
Change-Id: I643185d1fdd17296bd70fea483aa3c365e691bc5
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 32nd commit message:
msm: kgsl: If adreno start fails then restore state of device
Restore the state of the device back to what it was at the
start of the adreno_start function if this function fails to
execute successfully.
Change-Id: I5b279e5186b164d3361fba7c8f8d864395b794c8
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 33rd commit message:
msm: kgsl: Fix early exit condition in ringbuffer drain
The ringbuffer drain function can be called when the ringbuffer
start flag is not set. This happens on startup. Hence,
exiting the function early based on start flag is incorrect.
Simply execute this function regardless of the start flag.
Change-Id: Ibf2075847f8bb1a760bc1550309efb3c7aa1ca49
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 34th commit message:
msm: kgsl: Do not return an error on NULL gpu address
If a NULL gpu address is passed to snapshot object tracking
function then do not treat this as an error and return 0. NULL
objects may be present in an IB so just skip over these objects
instead of exiting due to an error.
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Change-Id: Ic253722c58b41f41d03f83c77017e58365da01a7
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 35th commit message:
msm: kgsl: Don't hold process list global mutex in process private create
Don't hold process list global mutex for long. Instead make
use of process specific spin_lock() to serialize access
to process private structure while creating it. Holding
process list global mutex could lead to deadlocks as other
functions depend on it.
CRs-fixed: 480732
Change-Id: Id54316770f911d0e23384f54ba5c14a1c9113680
Signed-off-by: Harsh Vardhan Dwivedi <hdwivedi@codeaurora.org>
Signed-off-by: Shubhraprakash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 36th commit message:
msm: kgsl: Use CPU path to program pagetable when active count is 0
When active count is 0 then we should use the CPU path to program
pagetables because the GPU path requires event registration. Events
can only be queued when active count is valid. Hence, if the active
count is NULL then use the CPU path.
Change-Id: I70f5894d20796bdc0f592db7dc2731195c0f7a82
CRs-fixed: 481887
Signed-off-by: Shubhrapralash Das <sadas@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 37th commit message:
iommu: msm: prevent partial mappings on error
If msm_iommu_map_range() fails mid way through the va
range with an error, clean up the PTEs that have already
been created so they are not leaked.
Change-Id: Ie929343cd6e36cade7b2cc9b4b4408c3453e6b5f
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 38th commit message:
msm: kgsl: better handling of virtual address fragmentation
When KGSL_MEMFLAGS_USE_CPU_MAP is enabled, the mmap address
must try to match the GPU alignment requirements of the buffer,
as well as include space in the mapping for the guard page.
This can cause -ENOMEM to be returned from get_unmapped_area()
when there are a large number of mappings. When this happens,
fall back to page alignment and retry to avoid failure.
Change-Id: I2176fe57afc96d8cf1fe1c694836305ddc3c3420
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 39th commit message:
iommu: msm: Don't treat address 0 as an error case
Currently, the iommu page table code treats a scattergather
list with physical address 0 as an error. This may not be
correct in all cases. Physical address 0 is a valid part
of the system and may be used for valid page allocations.
Nothing else in the system checks for physical address 0
for error so don't treat it as an error.
Change-Id: Ie9f0dae9dace4fff3b1c3449bc89c3afdd2e63a0
CRs-Fixed: 478304
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 40th commit message:
msm: kgsl: prevent race between mmap() and free on timestamp
When KGSL_MEMFLAGS_USE_CPU_MAP is set, we must check that the
address from get_unmapped_area() is not used as part of a
mapping that is present only in the GPU pagetable and not the
CPU pagetable. These mappings can occur because when a buffer
is freed on timestamp, the CPU mapping is destroyed immediately
but the GPU mapping is not destroyed until the GPU timestamp
has passed.
Because kgsl_mem_entry_detach_process() removed the rbtree
entry before removing the iommu mapping, there was a window
of time where kgsl thought the address was available even
though it was still present in the iommu pagetable. This
could cause the address to get assigned to a new buffer,
which would cause iommu_map_range() to fail since the old
mapping was still in the pagetable. Prevent this race by
removing the iommu mapping before removing the rbtree entry
tracking the address.
Change-Id: I8f42d6d97833293b55fcbc272d180564862cef8a
CRs-Fixed: 480222
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 41st commit message:
msm: kgsl: add guard page support for imported memory
Imported memory buffers sometimes do not have enough
padding to prevent page faults due to overzealous
GPU prefetch. Attach guard pages to their mappings
to prevent these faults.
Because we don't create the scatterlist for some
types of imported memory, such as ion, the guard
page is no longer included as the last entry in
the scatterlist. Instead, it is handled by
size ajustments and a separate iommu_map() call
in the kgsl_mmu_map() and kgsl_mmu_unmap() paths.
Change-Id: I3af3c29c3983f8cacdc366a2423f90c8ecdc3059
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 42nd commit message:
msm: kgsl: fix kgsl_mem_entry refcounting
Make kgsl_sharedmem_find* return a reference to the
entry that was found. This makes using an entry
without the mem_lock held less race prone.
Change-Id: If6eb6470ecfea1332d3130d877922c70ca037467
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 43rd commit message:
msm: kgsl: add ftrace for cache operations
Add the event kgsl_mem_sync_cache. This event is
emitted when only a cache operation is actually
performed. Attempts to flush uncached memory,
which do nothing, do not cause this event.
Change-Id: Id4a940a6b50e08b54fbef0025c4b8aaa71641462
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 44th commit message:
msm: kgsl: Add support for bulk cache operations
Add a new ioctl, IOCTL_KGSL_GPUMEM_SYNC_CACHE_BULK, which can be used
to sync a number of memory ids at once. This gives the driver an
opportunity to optimize the cache operations based on the total
working set of memory that needs to be managed.
Change-Id: I9693c54cb6f12468b7d9abb0afaef348e631a114
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 45th commit message:
msm: kgsl: flush the entire cache when the bulk batch is large
On 8064 and 8974, flushing more than 16mb of virtual address
space is slower than flushing the entire cache. So flush
the entire cache when the working set is larger than this.
The threshold for full cache flush can be tuned at runtime via
the full_cache_threshold sysfs file.
Change-Id: If525e4c44eb043d0afc3fe42d7ef2c7de0ba2106
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 46th commit message:
msm: kgsl: Use a read/lock for the context idr
Everybody loves a rcu but in this case we are dangerously mixing rcus and
atomic operations. Add a read/write lock to explicitly protect the idr.
Also fix a few spots where the idr was used without protection.
Change-Id: Ic0dedbad517a9f89134cbcf7af29c8bf0f034708
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 47th commit message:
msm: kgsl: embed kgsl_context struct in adreno_context struct
Having a separate allocated struct for the device specific context
makes ownership unclear, which could lead to reference counting
problems or invalid pointers. Also, duplicate members were
starting to appear in adreno_context because there wasn't a safe
way to reach the kgsl_context from some parts of the adreno code.
This can now be done via container_of().
This change alters the lifecycle of the context->id, which is
now freed when the context reference count hits zero rather
than in kgsl_context_detach().
It also changes the context creation and destruction sequence.
The device specific code must allocate a structure containing
a struct kgsl_context and passes a pointer it to kgsl_init_context()
before doing any device specific initialization. There is also a
separate drawctxt_detach() callback for doing device specific
cleanup. This is separate from freeing memory, which is done
by the drawctxt_destroy() callback.
Change-Id: I7d238476a3bfec98fd8dbc28971cf3187a81dac2
Signed-off-by: Jeremy Gebben <jgebben@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 48th commit message:
msm: kgsl: Take a reference count on the active adreno draw context
Take a reference count on the currently active draw context to keep
it from going away while we are maintaining a pointer to it in the
adreno device.
Change-Id: Ic0dedbade8c09ecacf822e9a3c5fbaf6e017ec0c
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 49th commit message:
msm: kgsl: Add a command dispatcher to manage the ringbuffer
Implements a centralized dispatcher for sending user commands
to the ringbuffer. Incoming commands are queued by context and
sent to the hardware on a round robin basis ensuring each context
a small burst of commands at a time. Each command is tracked
throughout the pipeline giving the dispatcher better knowledge
of how the hardware is being used. This will be the basis for
future per-context and cross context enhancements as priority
queuing and server-side syncronization.
Change-Id: Ic0dedbad49a43e8e6096d1362829c800266c2de3
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 50th commit message:
msm: kgsl: Only turn on the idle timer when active_cnt is 0
Only turn on the idle timer when the GPU expected to be quiet.
Change-Id: Ic0dedbad57846f1e7bf7820ec3152cd20598b448
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 51st commit message:
msm: kgsl: Add a ftrace event for active_cnt
Add a new ftrace event for watching the rise and fall of active_cnt:
echo 1 > /sys/kernel/debug/tracing/events/kgsl/kgsl_active_count/enable
This will give you the current active count and the caller of the function:
kgsl_active_count: d_name=kgsl-3d0 active_cnt=8e9 func=kgsl_ioctl
Change-Id: Ic0dedbadc80019e96ce759d9d4e0ad43bbcfedd2
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 52nd commit message:
msm: kgsl: Implement KGSL fault tolerance policy in the dispatcher
Implement the KGSL fault tolerance policy for faults in the dispatcher.
Replay (or skip) the inflight command batches as dictated by the policy,
iterating progressively through the various behaviors.
Change-Id: Ic0dedbade98cc3aa35b26813caf4265c74ccab56
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 53rd commit message:
msm: kgsl: Don't process events if the timestamp hasn't changed
Keep track of the global timestamp every time the event code runs.
If the timestamp hasn't changed then we are caught up and we can
politely bow out. This avoids the situation where multiple
interrupts queue the work queue multiple times:
IRQ
-> process events
IRQ
IRQ
-> process events
The actual retired timestamp in the first work item might be well
ahead of the delivered interrupts. The event loop will end up
processing every event that has been retired by the hardware
at that point. If the work item gets re-queued by a subesquent
interrupt then we might have already addressed all the pending
timestamps.
Change-Id: Ic0dedbad79722654cb17e82b7149e93d3c3f86a0
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 54th commit message:
msm: kgsl: Make active_cnt an atomic variable
In kgsl_active_cnt_light() the mutex was needed just to check and
increment the active_cnt value. Move active_cnt to an atomic to
begin the task of freeing ourselves from the grip of the device
mutex if we can avoid it.
Change-Id: Ic0dedbad78e086e3aa3559fab8ecebc43539f769
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 55th commit message:
msm: kgsl: Add a new command submission API
Add an new ioctl entry point for submitting commands to the GPU
called IOCTL_KGSL_SUBMIT_COMMANDS.
As with IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS the user passes a list of
indirect buffers, flags and optionally a user specified timestamp. The
old way of passing a list of indirect buffers is no longer supported.
IOCTL_KGSL_SUBMIT_COMMANDS also allows the user to define a
list of sync points for the command. Sync points are dependencies
on events that need to be satisfied before the command will be issued
to the hardware. Events are designed to be flexible. To start with
the only events that are supported are GPU events for a given context/
timestamp pair.
Pending events are stored in a list in the command batch. As each event is
expired it is deleted from the list. The adreno dispatcher won't send the
command until the list is empty. Sync points are not supported for Z180.
CRs-Fixed: 468770
Change-Id: Ic0dedbad5a5935f486acaeb033ae9a6010f82346
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 56th commit message:
msm: kgsl: add kgsl_sync_fence_waiter for server side sync
For server side sync the KGSL kernel module needs to perform
an asynchronous wait for a fence object prior to issuing
subsequent commands.
Change-Id: I1ee614aa3af84afc4813f1e47007f741beb3bc92
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 57th commit message:
msm: kgsl: Add support for KGSL_CMD_SYNCPOINT_TYPE_FENCE
Allow command batches to wait for external fence sync events.
Change-Id: Ic0dedbad3a211019e1cd3a3d62ab6a3e4d4eeb05
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 58th commit message:
msm: kgsl: fix potential double free of the kwaiter
Change-Id: Ic0dedbad66a0af6eaef52b2ad53c067110bdc6e4
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
# This is the 59th commit message:
msm: kgsl: free an event only after canceling successfully
Change-Id: Ic0dedbade256443d090dd11df452dc9cdf65530b
Signed-off-by: Jeff Boody <jboody@codeaurora.org>
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
2013-06-24 17:40:20 +00:00
|
|
|
if (ret && offset > 0)
|
|
|
|
msm_iommu_unmap_range(domain, start_va, offset);
|
2011-08-12 02:45:23 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int msm_iommu_unmap_range(struct iommu_domain *domain, unsigned int va,
|
|
|
|
unsigned int len)
|
|
|
|
{
|
|
|
|
unsigned int offset = 0;
|
|
|
|
unsigned long *fl_table;
|
|
|
|
unsigned long *fl_pte;
|
|
|
|
unsigned long fl_offset;
|
|
|
|
unsigned long *sl_table;
|
|
|
|
unsigned long sl_start, sl_end;
|
|
|
|
int used, i;
|
|
|
|
struct msm_priv *priv;
|
|
|
|
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_lock(&msm_iommu_lock);
|
2011-08-12 02:45:23 +00:00
|
|
|
|
|
|
|
BUG_ON(len & (SZ_4K - 1));
|
|
|
|
|
|
|
|
priv = domain->priv;
|
|
|
|
fl_table = priv->pgtable;
|
|
|
|
|
|
|
|
fl_offset = FL_OFFSET(va); /* Upper 12 bits */
|
|
|
|
fl_pte = fl_table + fl_offset; /* int pointers, 4 bytes */
|
|
|
|
|
|
|
|
while (offset < len) {
|
2012-07-09 19:27:07 +00:00
|
|
|
if (*fl_pte & FL_TYPE_TABLE) {
|
|
|
|
sl_start = SL_OFFSET(va);
|
|
|
|
sl_table = __va(((*fl_pte) & FL_BASE_MASK));
|
|
|
|
sl_end = ((len - offset) / SZ_4K) + sl_start;
|
|
|
|
|
|
|
|
if (sl_end > NUM_SL_PTE)
|
|
|
|
sl_end = NUM_SL_PTE;
|
|
|
|
|
|
|
|
memset(sl_table + sl_start, 0, (sl_end - sl_start) * 4);
|
|
|
|
clean_pte(sl_table + sl_start, sl_table + sl_end,
|
|
|
|
priv->redirect);
|
|
|
|
|
|
|
|
offset += (sl_end - sl_start) * SZ_4K;
|
|
|
|
va += (sl_end - sl_start) * SZ_4K;
|
|
|
|
|
|
|
|
/* Unmap and free the 2nd level table if all mappings
|
|
|
|
* in it were removed. This saves memory, but the table
|
|
|
|
* will need to be re-allocated the next time someone
|
|
|
|
* tries to map these VAs.
|
|
|
|
*/
|
|
|
|
used = 0;
|
|
|
|
|
|
|
|
/* If we just unmapped the whole table, don't bother
|
|
|
|
* seeing if there are still used entries left.
|
|
|
|
*/
|
|
|
|
if (sl_end - sl_start != NUM_SL_PTE)
|
|
|
|
for (i = 0; i < NUM_SL_PTE; i++)
|
|
|
|
if (sl_table[i]) {
|
|
|
|
used = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!used) {
|
|
|
|
free_page((unsigned long)sl_table);
|
|
|
|
*fl_pte = 0;
|
|
|
|
|
|
|
|
clean_pte(fl_pte, fl_pte + 1, priv->redirect);
|
|
|
|
}
|
2011-08-12 02:45:23 +00:00
|
|
|
|
2012-07-09 19:27:07 +00:00
|
|
|
sl_start = 0;
|
|
|
|
} else {
|
2011-08-12 02:45:23 +00:00
|
|
|
*fl_pte = 0;
|
2012-05-12 01:43:02 +00:00
|
|
|
clean_pte(fl_pte, fl_pte + 1, priv->redirect);
|
2012-07-09 19:27:07 +00:00
|
|
|
va += SZ_1M;
|
|
|
|
offset += SZ_1M;
|
|
|
|
sl_start = 0;
|
2011-08-12 02:45:23 +00:00
|
|
|
}
|
|
|
|
fl_pte++;
|
|
|
|
}
|
|
|
|
|
|
|
|
__flush_iotlb(domain);
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_unlock(&msm_iommu_lock);
|
2011-08-12 02:45:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
static phys_addr_t msm_iommu_iova_to_phys(struct iommu_domain *domain,
|
|
|
|
unsigned long va)
|
|
|
|
{
|
|
|
|
struct msm_priv *priv;
|
|
|
|
struct msm_iommu_drvdata *iommu_drvdata;
|
|
|
|
struct msm_iommu_ctx_drvdata *ctx_drvdata;
|
|
|
|
unsigned int par;
|
|
|
|
void __iomem *base;
|
|
|
|
phys_addr_t ret = 0;
|
|
|
|
int ctx;
|
|
|
|
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_lock(&msm_iommu_lock);
|
2010-08-25 01:31:10 +00:00
|
|
|
|
|
|
|
priv = domain->priv;
|
|
|
|
if (list_empty(&priv->list_attached))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
ctx_drvdata = list_entry(priv->list_attached.next,
|
|
|
|
struct msm_iommu_ctx_drvdata, attached_elm);
|
|
|
|
iommu_drvdata = dev_get_drvdata(ctx_drvdata->pdev->dev.parent);
|
|
|
|
|
|
|
|
base = iommu_drvdata->base;
|
|
|
|
ctx = ctx_drvdata->num;
|
|
|
|
|
2011-02-25 02:00:39 +00:00
|
|
|
ret = __enable_clocks(iommu_drvdata);
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
|
|
|
|
2012-11-07 23:02:56 +00:00
|
|
|
msm_iommu_remote_spin_lock();
|
|
|
|
|
2011-03-01 00:04:55 +00:00
|
|
|
SET_V2PPR(base, ctx, va & V2Pxx_VA);
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2011-03-16 19:23:21 +00:00
|
|
|
mb();
|
2010-08-25 01:31:10 +00:00
|
|
|
par = GET_PAR(base, ctx);
|
|
|
|
|
|
|
|
/* We are dealing with a supersection */
|
|
|
|
if (GET_NOFAULT_SS(base, ctx))
|
|
|
|
ret = (par & 0xFF000000) | (va & 0x00FFFFFF);
|
|
|
|
else /* Upper 20 bits from PAR, lower 12 from VA */
|
|
|
|
ret = (par & 0xFFFFF000) | (va & 0x00000FFF);
|
|
|
|
|
2010-11-13 03:30:00 +00:00
|
|
|
if (GET_FAULT(base, ctx))
|
|
|
|
ret = 0;
|
|
|
|
|
2012-11-07 23:02:56 +00:00
|
|
|
msm_iommu_remote_spin_unlock();
|
|
|
|
|
2011-02-25 02:00:39 +00:00
|
|
|
__disable_clocks(iommu_drvdata);
|
2010-08-25 01:31:10 +00:00
|
|
|
fail:
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_unlock(&msm_iommu_lock);
|
2010-08-25 01:31:10 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int msm_iommu_domain_has_cap(struct iommu_domain *domain,
|
|
|
|
unsigned long cap)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_ctx_regs(void __iomem *base, int ctx)
|
|
|
|
{
|
|
|
|
unsigned int fsr = GET_FSR(base, ctx);
|
|
|
|
pr_err("FAR = %08x PAR = %08x\n",
|
|
|
|
GET_FAR(base, ctx), GET_PAR(base, ctx));
|
|
|
|
pr_err("FSR = %08x [%s%s%s%s%s%s%s%s%s%s]\n", fsr,
|
|
|
|
(fsr & 0x02) ? "TF " : "",
|
|
|
|
(fsr & 0x04) ? "AFF " : "",
|
|
|
|
(fsr & 0x08) ? "APF " : "",
|
|
|
|
(fsr & 0x10) ? "TLBMF " : "",
|
|
|
|
(fsr & 0x20) ? "HTWDEEF " : "",
|
|
|
|
(fsr & 0x40) ? "HTWSEEF " : "",
|
|
|
|
(fsr & 0x80) ? "MHF " : "",
|
|
|
|
(fsr & 0x10000) ? "SL " : "",
|
|
|
|
(fsr & 0x40000000) ? "SS " : "",
|
|
|
|
(fsr & 0x80000000) ? "MULTI " : "");
|
|
|
|
|
|
|
|
pr_err("FSYNR0 = %08x FSYNR1 = %08x\n",
|
|
|
|
GET_FSYNR0(base, ctx), GET_FSYNR1(base, ctx));
|
|
|
|
pr_err("TTBR0 = %08x TTBR1 = %08x\n",
|
|
|
|
GET_TTBR0(base, ctx), GET_TTBR1(base, ctx));
|
|
|
|
pr_err("SCTLR = %08x ACTLR = %08x\n",
|
|
|
|
GET_SCTLR(base, ctx), GET_ACTLR(base, ctx));
|
|
|
|
pr_err("PRRR = %08x NMRR = %08x\n",
|
|
|
|
GET_PRRR(base, ctx), GET_NMRR(base, ctx));
|
|
|
|
}
|
|
|
|
|
|
|
|
irqreturn_t msm_iommu_fault_handler(int irq, void *dev_id)
|
|
|
|
{
|
2012-05-04 00:29:12 +00:00
|
|
|
struct msm_iommu_ctx_drvdata *ctx_drvdata = dev_id;
|
|
|
|
struct msm_iommu_drvdata *drvdata;
|
2010-08-25 01:31:10 +00:00
|
|
|
void __iomem *base;
|
2012-05-04 00:29:12 +00:00
|
|
|
unsigned int fsr, num;
|
|
|
|
int ret;
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_lock(&msm_iommu_lock);
|
2012-05-04 00:29:12 +00:00
|
|
|
BUG_ON(!ctx_drvdata);
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2012-05-04 00:29:12 +00:00
|
|
|
drvdata = dev_get_drvdata(ctx_drvdata->pdev->dev.parent);
|
|
|
|
BUG_ON(!drvdata);
|
2010-08-25 01:31:10 +00:00
|
|
|
|
|
|
|
base = drvdata->base;
|
2012-05-04 00:29:12 +00:00
|
|
|
num = ctx_drvdata->num;
|
2010-08-25 01:31:10 +00:00
|
|
|
|
2011-02-25 02:00:39 +00:00
|
|
|
ret = __enable_clocks(drvdata);
|
|
|
|
if (ret)
|
|
|
|
goto fail;
|
|
|
|
|
2012-11-07 23:02:56 +00:00
|
|
|
msm_iommu_remote_spin_lock();
|
|
|
|
|
2012-05-04 00:29:12 +00:00
|
|
|
fsr = GET_FSR(base, num);
|
|
|
|
|
|
|
|
if (fsr) {
|
|
|
|
if (!ctx_drvdata->attached_domain) {
|
|
|
|
pr_err("Bad domain in interrupt handler\n");
|
|
|
|
ret = -ENOSYS;
|
|
|
|
} else
|
|
|
|
ret = report_iommu_fault(ctx_drvdata->attached_domain,
|
|
|
|
&ctx_drvdata->pdev->dev,
|
|
|
|
GET_FAR(base, num), 0);
|
|
|
|
|
|
|
|
if (ret == -ENOSYS) {
|
|
|
|
pr_err("Unexpected IOMMU page fault!\n");
|
|
|
|
pr_err("name = %s\n", drvdata->name);
|
|
|
|
pr_err("context = %s (%d)\n", ctx_drvdata->name, num);
|
2010-08-25 01:31:10 +00:00
|
|
|
pr_err("Interesting registers:\n");
|
2012-05-04 00:29:12 +00:00
|
|
|
print_ctx_regs(base, num);
|
2010-08-25 01:31:10 +00:00
|
|
|
}
|
2012-05-04 00:29:12 +00:00
|
|
|
|
|
|
|
SET_FSR(base, num, fsr);
|
2012-10-09 23:14:28 +00:00
|
|
|
/*
|
|
|
|
* Only resume fetches if the registered fault handler
|
|
|
|
* allows it
|
|
|
|
*/
|
|
|
|
if (ret != -EBUSY)
|
|
|
|
SET_RESUME(base, num, 1);
|
2012-05-04 00:29:12 +00:00
|
|
|
|
|
|
|
ret = IRQ_HANDLED;
|
|
|
|
} else
|
|
|
|
ret = IRQ_NONE;
|
|
|
|
|
2012-11-07 23:02:56 +00:00
|
|
|
msm_iommu_remote_spin_unlock();
|
|
|
|
|
2011-02-25 02:00:39 +00:00
|
|
|
__disable_clocks(drvdata);
|
2010-08-25 01:31:10 +00:00
|
|
|
fail:
|
2012-02-14 23:42:05 +00:00
|
|
|
mutex_unlock(&msm_iommu_lock);
|
2012-05-04 00:29:12 +00:00
|
|
|
return ret;
|
2010-08-25 01:31:10 +00:00
|
|
|
}
|
|
|
|
|
2011-12-03 01:01:57 +00:00
|
|
|
static phys_addr_t msm_iommu_get_pt_base_addr(struct iommu_domain *domain)
|
|
|
|
{
|
|
|
|
struct msm_priv *priv = domain->priv;
|
|
|
|
return __pa(priv->pgtable);
|
|
|
|
}
|
|
|
|
|
2010-08-25 01:31:10 +00:00
|
|
|
static struct iommu_ops msm_iommu_ops = {
|
|
|
|
.domain_init = msm_iommu_domain_init,
|
|
|
|
.domain_destroy = msm_iommu_domain_destroy,
|
|
|
|
.attach_dev = msm_iommu_attach_dev,
|
|
|
|
.detach_dev = msm_iommu_detach_dev,
|
|
|
|
.map = msm_iommu_map,
|
|
|
|
.unmap = msm_iommu_unmap,
|
2011-08-12 02:45:23 +00:00
|
|
|
.map_range = msm_iommu_map_range,
|
|
|
|
.unmap_range = msm_iommu_unmap_range,
|
2010-08-25 01:31:10 +00:00
|
|
|
.iova_to_phys = msm_iommu_iova_to_phys,
|
2011-11-10 09:32:28 +00:00
|
|
|
.domain_has_cap = msm_iommu_domain_has_cap,
|
2011-12-03 01:01:57 +00:00
|
|
|
.get_pt_base_addr = msm_iommu_get_pt_base_addr,
|
2011-11-10 09:32:28 +00:00
|
|
|
.pgsize_bitmap = MSM_IOMMU_PGSIZES,
|
2010-08-25 01:31:10 +00:00
|
|
|
};
|
|
|
|
|
2010-11-16 02:20:08 +00:00
|
|
|
static int __init get_tex_class(int icp, int ocp, int mt, int nos)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
unsigned int prrr = 0;
|
|
|
|
unsigned int nmrr = 0;
|
|
|
|
int c_icp, c_ocp, c_mt, c_nos;
|
|
|
|
|
|
|
|
RCP15_PRRR(prrr);
|
|
|
|
RCP15_NMRR(nmrr);
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_TEX_CLASS; i++) {
|
|
|
|
c_nos = PRRR_NOS(prrr, i);
|
|
|
|
c_mt = PRRR_MT(prrr, i);
|
|
|
|
c_icp = NMRR_ICP(nmrr, i);
|
|
|
|
c_ocp = NMRR_OCP(nmrr, i);
|
|
|
|
|
|
|
|
if (icp == c_icp && ocp == c_ocp && c_mt == mt && c_nos == nos)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init setup_iommu_tex_classes(void)
|
|
|
|
{
|
|
|
|
msm_iommu_tex_class[MSM_IOMMU_ATTR_NONCACHED] =
|
|
|
|
get_tex_class(CP_NONCACHED, CP_NONCACHED, MT_NORMAL, 1);
|
|
|
|
|
|
|
|
msm_iommu_tex_class[MSM_IOMMU_ATTR_CACHED_WB_WA] =
|
|
|
|
get_tex_class(CP_WB_WA, CP_WB_WA, MT_NORMAL, 1);
|
|
|
|
|
|
|
|
msm_iommu_tex_class[MSM_IOMMU_ATTR_CACHED_WB_NWA] =
|
|
|
|
get_tex_class(CP_WB_NWA, CP_WB_NWA, MT_NORMAL, 1);
|
|
|
|
|
|
|
|
msm_iommu_tex_class[MSM_IOMMU_ATTR_CACHED_WT] =
|
|
|
|
get_tex_class(CP_WT, CP_WT, MT_NORMAL, 1);
|
|
|
|
}
|
|
|
|
|
2010-11-13 03:29:53 +00:00
|
|
|
static int __init msm_iommu_init(void)
|
2010-08-25 01:31:10 +00:00
|
|
|
{
|
2012-02-08 05:47:47 +00:00
|
|
|
if (!msm_soc_version_supports_iommu_v1())
|
2011-10-31 22:32:44 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
2012-11-07 23:02:56 +00:00
|
|
|
msm_iommu_lock_initialize();
|
|
|
|
|
2010-11-16 02:20:08 +00:00
|
|
|
setup_iommu_tex_classes();
|
2011-09-06 15:56:07 +00:00
|
|
|
bus_set_iommu(&platform_bus_type, &msm_iommu_ops);
|
2010-08-25 01:31:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
subsys_initcall(msm_iommu_init);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_AUTHOR("Stepan Moskovchenko <stepanm@codeaurora.org>");
|