Thomas Gleixner | 9952f69 | 2019-05-28 10:10:04 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Tegra host1x Syncpoints |
| 4 | * |
| 5 | * Copyright (c) 2010-2013, NVIDIA Corporation. |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef __HOST1X_SYNCPT_H |
| 9 | #define __HOST1X_SYNCPT_H |
| 10 | |
| 11 | #include <linux/atomic.h> |
Thierry Reding | 35d747a | 2013-09-24 16:30:32 +0200 | [diff] [blame] | 12 | #include <linux/host1x.h> |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 13 | #include <linux/kernel.h> |
Mikko Perttunen | 2aed4f5 | 2021-03-29 16:38:32 +0300 | [diff] [blame] | 14 | #include <linux/kref.h> |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 15 | #include <linux/sched.h> |
| 16 | |
Terje Bergstrom | 7ede0b0 | 2013-03-22 16:34:02 +0200 | [diff] [blame] | 17 | #include "intr.h" |
| 18 | |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 19 | struct host1x; |
| 20 | |
Terje Bergstrom | 6579324 | 2013-03-22 16:34:03 +0200 | [diff] [blame] | 21 | /* Reserved for replacing an expired wait with a NOP */ |
| 22 | #define HOST1X_SYNCPT_RESERVED 0 |
| 23 | |
Arto Merilainen | f5a954f | 2013-10-14 15:21:53 +0300 | [diff] [blame] | 24 | struct host1x_syncpt_base { |
| 25 | unsigned int id; |
| 26 | bool requested; |
| 27 | }; |
| 28 | |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 29 | struct host1x_syncpt { |
Mikko Perttunen | 2aed4f5 | 2021-03-29 16:38:32 +0300 | [diff] [blame] | 30 | struct kref ref; |
| 31 | |
Thierry Reding | 5c0d8d3 | 2016-06-23 11:19:00 +0200 | [diff] [blame] | 32 | unsigned int id; |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 33 | atomic_t min_val; |
| 34 | atomic_t max_val; |
| 35 | u32 base_val; |
| 36 | const char *name; |
Arto Merilainen | ece6689 | 2013-05-29 13:26:07 +0300 | [diff] [blame] | 37 | bool client_managed; |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 38 | struct host1x *host; |
Arto Merilainen | f5a954f | 2013-10-14 15:21:53 +0300 | [diff] [blame] | 39 | struct host1x_syncpt_base *base; |
Terje Bergstrom | 7ede0b0 | 2013-03-22 16:34:02 +0200 | [diff] [blame] | 40 | |
| 41 | /* interrupt data */ |
| 42 | struct host1x_syncpt_intr intr; |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | /* Initialize sync point array */ |
| 46 | int host1x_syncpt_init(struct host1x *host); |
| 47 | |
| 48 | /* Free sync point array */ |
| 49 | void host1x_syncpt_deinit(struct host1x *host); |
| 50 | |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 51 | /* Return number of sync point supported. */ |
Thierry Reding | 14c95fc | 2016-06-22 16:44:07 +0200 | [diff] [blame] | 52 | unsigned int host1x_syncpt_nb_pts(struct host1x *host); |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 53 | |
| 54 | /* Return number of wait bases supported. */ |
Thierry Reding | 14c95fc | 2016-06-22 16:44:07 +0200 | [diff] [blame] | 55 | unsigned int host1x_syncpt_nb_bases(struct host1x *host); |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 56 | |
| 57 | /* Return number of mlocks supported. */ |
Thierry Reding | 14c95fc | 2016-06-22 16:44:07 +0200 | [diff] [blame] | 58 | unsigned int host1x_syncpt_nb_mlocks(struct host1x *host); |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * Check sync point sanity. If max is larger than min, there have too many |
| 62 | * sync point increments. |
| 63 | * |
| 64 | * Client managed sync point are not tracked. |
| 65 | * */ |
| 66 | static inline bool host1x_syncpt_check_max(struct host1x_syncpt *sp, u32 real) |
| 67 | { |
| 68 | u32 max; |
| 69 | if (sp->client_managed) |
| 70 | return true; |
| 71 | max = host1x_syncpt_read_max(sp); |
| 72 | return (s32)(max - real) >= 0; |
| 73 | } |
| 74 | |
| 75 | /* Return true if sync point is client managed. */ |
Arto Merilainen | ece6689 | 2013-05-29 13:26:07 +0300 | [diff] [blame] | 76 | static inline bool host1x_syncpt_client_managed(struct host1x_syncpt *sp) |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 77 | { |
| 78 | return sp->client_managed; |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * Returns true if syncpoint min == max, which means that there are no |
| 83 | * outstanding operations. |
| 84 | */ |
| 85 | static inline bool host1x_syncpt_idle(struct host1x_syncpt *sp) |
| 86 | { |
| 87 | int min, max; |
| 88 | smp_rmb(); |
| 89 | min = atomic_read(&sp->min_val); |
| 90 | max = atomic_read(&sp->max_val); |
| 91 | return (min == max); |
| 92 | } |
| 93 | |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 94 | /* Load current value from hardware to the shadow register. */ |
| 95 | u32 host1x_syncpt_load(struct host1x_syncpt *sp); |
| 96 | |
Terje Bergstrom | 7ede0b0 | 2013-03-22 16:34:02 +0200 | [diff] [blame] | 97 | /* Check if the given syncpoint value has already passed */ |
| 98 | bool host1x_syncpt_is_expired(struct host1x_syncpt *sp, u32 thresh); |
| 99 | |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 100 | /* Save host1x sync point state into shadow registers. */ |
| 101 | void host1x_syncpt_save(struct host1x *host); |
| 102 | |
| 103 | /* Reset host1x sync point state from shadow registers. */ |
| 104 | void host1x_syncpt_restore(struct host1x *host); |
| 105 | |
| 106 | /* Read current wait base value into shadow register and return it. */ |
| 107 | u32 host1x_syncpt_load_wait_base(struct host1x_syncpt *sp); |
| 108 | |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 109 | /* Indicate future operations by incrementing the sync point max. */ |
| 110 | u32 host1x_syncpt_incr_max(struct host1x_syncpt *sp, u32 incrs); |
| 111 | |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 112 | /* Check if sync point id is valid. */ |
| 113 | static inline int host1x_syncpt_is_valid(struct host1x_syncpt *sp) |
| 114 | { |
| 115 | return sp->id < host1x_syncpt_nb_pts(sp->host); |
| 116 | } |
| 117 | |
Terje Bergstrom | 7547168 | 2013-03-22 16:34:01 +0200 | [diff] [blame] | 118 | #endif |