blob: 432ade0842f68724bc9fe2bdde77a8982f67593b [file] [log] [blame]
Alexander Shishkin50352fa2018-03-28 18:46:15 +03001// SPDX-License-Identifier: GPL-2.0
Alexander Shishkinba826642015-09-22 15:47:18 +03002/*
3 * Intel(R) Trace Hub Memory Storage Unit
4 *
5 * Copyright (C) 2014-2015 Intel Corporation.
Alexander Shishkinba826642015-09-22 15:47:18 +03006 */
7
8#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
10#include <linux/types.h>
11#include <linux/module.h>
12#include <linux/device.h>
13#include <linux/uaccess.h>
14#include <linux/sizes.h>
15#include <linux/printk.h>
16#include <linux/slab.h>
17#include <linux/mm.h>
18#include <linux/fs.h>
19#include <linux/io.h>
Alexander Shishkin615c1642019-07-05 17:14:21 +030020#include <linux/workqueue.h>
Alexander Shishkinba826642015-09-22 15:47:18 +030021#include <linux/dma-mapping.h>
22
Laura Abbott0c14dac2017-05-08 15:58:20 -070023#ifdef CONFIG_X86
24#include <asm/set_memory.h>
25#endif
Alexander Shishkinba826642015-09-22 15:47:18 +030026
Alexander Shishkin615c1642019-07-05 17:14:21 +030027#include <linux/intel_th.h>
Alexander Shishkinba826642015-09-22 15:47:18 +030028#include "intel_th.h"
29#include "msu.h"
30
31#define msc_dev(x) (&(x)->thdev->dev)
32
Alexander Shishkin615c1642019-07-05 17:14:21 +030033/*
34 * Lockout state transitions:
35 * READY -> INUSE -+-> LOCKED -+-> READY -> etc.
36 * \-----------/
37 * WIN_READY: window can be used by HW
38 * WIN_INUSE: window is in use
39 * WIN_LOCKED: window is filled up and is being processed by the buffer
40 * handling code
41 *
42 * All state transitions happen automatically, except for the LOCKED->READY,
43 * which needs to be signalled by the buffer code by calling
44 * intel_th_msc_window_unlock().
45 *
46 * When the interrupt handler has to switch to the next window, it checks
47 * whether it's READY, and if it is, it performs the switch and tracing
48 * continues. If it's LOCKED, it stops the trace.
49 */
50enum lockout_state {
51 WIN_READY = 0,
52 WIN_INUSE,
53 WIN_LOCKED
54};
55
Alexander Shishkinba826642015-09-22 15:47:18 +030056/**
Alexander Shishkinba826642015-09-22 15:47:18 +030057 * struct msc_window - multiblock mode window descriptor
58 * @entry: window list linkage (msc::win_list)
59 * @pgoff: page offset into the buffer that this window starts at
Alexander Shishkin615c1642019-07-05 17:14:21 +030060 * @lockout: lockout state, see comment below
61 * @lo_lock: lockout state serialization
Alexander Shishkinba826642015-09-22 15:47:18 +030062 * @nr_blocks: number of blocks (pages) in this window
Alexander Shishkinfa52b3f2019-06-27 15:51:45 +030063 * @nr_segs: number of segments in this window (<= @nr_blocks)
Alexander Shishkinbbbc08a2019-06-27 15:51:46 +030064 * @_sgt: array of block descriptors
Alexander Shishkinba39bd82019-05-03 11:44:44 +030065 * @sgt: array of block descriptors
Alexander Shishkinba826642015-09-22 15:47:18 +030066 */
67struct msc_window {
68 struct list_head entry;
69 unsigned long pgoff;
Alexander Shishkin615c1642019-07-05 17:14:21 +030070 enum lockout_state lockout;
71 spinlock_t lo_lock;
Alexander Shishkinba826642015-09-22 15:47:18 +030072 unsigned int nr_blocks;
Alexander Shishkinfa52b3f2019-06-27 15:51:45 +030073 unsigned int nr_segs;
Alexander Shishkinba826642015-09-22 15:47:18 +030074 struct msc *msc;
Alexander Shishkinbbbc08a2019-06-27 15:51:46 +030075 struct sg_table _sgt;
76 struct sg_table *sgt;
Alexander Shishkinba826642015-09-22 15:47:18 +030077};
78
79/**
80 * struct msc_iter - iterator for msc buffer
81 * @entry: msc::iter_list linkage
82 * @msc: pointer to the MSC device
83 * @start_win: oldest window
84 * @win: current window
85 * @offset: current logical offset into the buffer
86 * @start_block: oldest block in the window
87 * @block: block number in the window
88 * @block_off: offset into current block
89 * @wrap_count: block wrapping handling
90 * @eof: end of buffer reached
91 */
92struct msc_iter {
93 struct list_head entry;
94 struct msc *msc;
95 struct msc_window *start_win;
96 struct msc_window *win;
97 unsigned long offset;
Alexander Shishkin57b69a12019-07-05 17:14:23 +030098 struct scatterlist *start_block;
99 struct scatterlist *block;
Alexander Shishkinba826642015-09-22 15:47:18 +0300100 unsigned int block_off;
101 unsigned int wrap_count;
102 unsigned int eof;
103};
104
105/**
106 * struct msc - MSC device representation
107 * @reg_base: register window base address
108 * @thdev: intel_th_device pointer
Alexander Shishkin615c1642019-07-05 17:14:21 +0300109 * @mbuf: MSU buffer, if assigned
110 * @mbuf_priv MSU buffer's private data, if @mbuf
Alexander Shishkinba826642015-09-22 15:47:18 +0300111 * @win_list: list of windows in multiblock mode
Alexander Shishkin4e0eaf22019-05-03 11:44:34 +0300112 * @single_sgt: single mode buffer
Alexander Shishkinaad14ad2019-05-03 11:44:51 +0300113 * @cur_win: current window
Alexander Shishkinba826642015-09-22 15:47:18 +0300114 * @nr_pages: total number of pages allocated for this buffer
115 * @single_sz: amount of data in single mode
116 * @single_wrap: single mode wrap occurred
117 * @base: buffer's base pointer
118 * @base_addr: buffer's base address
119 * @user_count: number of users of the buffer
120 * @mmap_count: number of mappings
121 * @buf_mutex: mutex to serialize access to buffer-related bits
122
123 * @enabled: MSC is enabled
124 * @wrap: wrapping is enabled
125 * @mode: MSC operating mode
126 * @burst_len: write burst length
127 * @index: number of this MSC in the MSU
128 */
129struct msc {
130 void __iomem *reg_base;
Alexander Shishkinaac8da62019-05-03 11:44:41 +0300131 void __iomem *msu_base;
Alexander Shishkinba826642015-09-22 15:47:18 +0300132 struct intel_th_device *thdev;
133
Alexander Shishkin615c1642019-07-05 17:14:21 +0300134 const struct msu_buffer *mbuf;
135 void *mbuf_priv;
136
137 struct work_struct work;
Alexander Shishkinba826642015-09-22 15:47:18 +0300138 struct list_head win_list;
Alexander Shishkin4e0eaf22019-05-03 11:44:34 +0300139 struct sg_table single_sgt;
Alexander Shishkinaad14ad2019-05-03 11:44:51 +0300140 struct msc_window *cur_win;
Alexander Shishkin8622dfef2020-03-19 10:51:52 +0200141 struct msc_window *switch_on_unlock;
Alexander Shishkinba826642015-09-22 15:47:18 +0300142 unsigned long nr_pages;
143 unsigned long single_sz;
144 unsigned int single_wrap : 1;
145 void *base;
146 dma_addr_t base_addr;
Alexander Shishkin092f47c2019-07-05 17:14:25 +0300147 u32 orig_addr;
148 u32 orig_sz;
Alexander Shishkinba826642015-09-22 15:47:18 +0300149
150 /* <0: no buffer, 0: no users, >0: active users */
151 atomic_t user_count;
152
153 atomic_t mmap_count;
154 struct mutex buf_mutex;
155
Alexander Shishkinba826642015-09-22 15:47:18 +0300156 struct list_head iter_list;
157
Alexander Shishkin8622dfef2020-03-19 10:51:52 +0200158 bool stop_on_full;
159
Alexander Shishkinba826642015-09-22 15:47:18 +0300160 /* config */
161 unsigned int enabled : 1,
Alexander Shishkinaac8da62019-05-03 11:44:41 +0300162 wrap : 1,
Alexander Shishkin397c7722020-03-17 08:22:10 +0200163 do_irq : 1,
164 multi_is_broken : 1;
Alexander Shishkinba826642015-09-22 15:47:18 +0300165 unsigned int mode;
166 unsigned int burst_len;
167 unsigned int index;
168};
169
Alexander Shishkin615c1642019-07-05 17:14:21 +0300170static LIST_HEAD(msu_buffer_list);
Alexander Shishkine5a340f2019-10-28 09:06:46 +0200171static DEFINE_MUTEX(msu_buffer_mutex);
Alexander Shishkin615c1642019-07-05 17:14:21 +0300172
173/**
174 * struct msu_buffer_entry - internal MSU buffer bookkeeping
175 * @entry: link to msu_buffer_list
176 * @mbuf: MSU buffer object
177 * @owner: module that provides this MSU buffer
178 */
179struct msu_buffer_entry {
180 struct list_head entry;
181 const struct msu_buffer *mbuf;
182 struct module *owner;
183};
184
185static struct msu_buffer_entry *__msu_buffer_entry_find(const char *name)
186{
187 struct msu_buffer_entry *mbe;
188
189 lockdep_assert_held(&msu_buffer_mutex);
190
191 list_for_each_entry(mbe, &msu_buffer_list, entry) {
192 if (!strcmp(mbe->mbuf->name, name))
193 return mbe;
194 }
195
196 return NULL;
197}
198
199static const struct msu_buffer *
200msu_buffer_get(const char *name)
201{
202 struct msu_buffer_entry *mbe;
203
204 mutex_lock(&msu_buffer_mutex);
205 mbe = __msu_buffer_entry_find(name);
206 if (mbe && !try_module_get(mbe->owner))
207 mbe = NULL;
208 mutex_unlock(&msu_buffer_mutex);
209
210 return mbe ? mbe->mbuf : NULL;
211}
212
213static void msu_buffer_put(const struct msu_buffer *mbuf)
214{
215 struct msu_buffer_entry *mbe;
216
217 mutex_lock(&msu_buffer_mutex);
218 mbe = __msu_buffer_entry_find(mbuf->name);
219 if (mbe)
220 module_put(mbe->owner);
221 mutex_unlock(&msu_buffer_mutex);
222}
223
224int intel_th_msu_buffer_register(const struct msu_buffer *mbuf,
225 struct module *owner)
226{
227 struct msu_buffer_entry *mbe;
228 int ret = 0;
229
230 mbe = kzalloc(sizeof(*mbe), GFP_KERNEL);
231 if (!mbe)
232 return -ENOMEM;
233
234 mutex_lock(&msu_buffer_mutex);
235 if (__msu_buffer_entry_find(mbuf->name)) {
236 ret = -EEXIST;
237 kfree(mbe);
238 goto unlock;
239 }
240
241 mbe->mbuf = mbuf;
242 mbe->owner = owner;
243 list_add_tail(&mbe->entry, &msu_buffer_list);
244unlock:
245 mutex_unlock(&msu_buffer_mutex);
246
247 return ret;
248}
249EXPORT_SYMBOL_GPL(intel_th_msu_buffer_register);
250
251void intel_th_msu_buffer_unregister(const struct msu_buffer *mbuf)
252{
253 struct msu_buffer_entry *mbe;
254
255 mutex_lock(&msu_buffer_mutex);
256 mbe = __msu_buffer_entry_find(mbuf->name);
257 if (mbe) {
258 list_del(&mbe->entry);
259 kfree(mbe);
260 }
261 mutex_unlock(&msu_buffer_mutex);
262}
263EXPORT_SYMBOL_GPL(intel_th_msu_buffer_unregister);
264
Alexander Shishkinba826642015-09-22 15:47:18 +0300265static inline bool msc_block_is_empty(struct msc_block_desc *bdesc)
266{
267 /* header hasn't been written */
268 if (!bdesc->valid_dw)
269 return true;
270
271 /* valid_dw includes the header */
272 if (!msc_data_sz(bdesc))
273 return true;
274
275 return false;
276}
277
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300278static inline struct scatterlist *msc_win_base_sg(struct msc_window *win)
Alexander Shishkinba39bd82019-05-03 11:44:44 +0300279{
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300280 return win->sgt->sgl;
Alexander Shishkinba39bd82019-05-03 11:44:44 +0300281}
282
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300283static inline struct msc_block_desc *msc_win_base(struct msc_window *win)
Alexander Shishkinfa52b3f2019-06-27 15:51:45 +0300284{
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300285 return sg_virt(msc_win_base_sg(win));
Alexander Shishkinfa52b3f2019-06-27 15:51:45 +0300286}
287
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300288static inline dma_addr_t msc_win_base_dma(struct msc_window *win)
Alexander Shishkinba39bd82019-05-03 11:44:44 +0300289{
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300290 return sg_dma_address(msc_win_base_sg(win));
Alexander Shishkinba39bd82019-05-03 11:44:44 +0300291}
292
293static inline unsigned long
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300294msc_win_base_pfn(struct msc_window *win)
Alexander Shishkinba39bd82019-05-03 11:44:44 +0300295{
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300296 return PFN_DOWN(msc_win_base_dma(win));
Alexander Shishkinba39bd82019-05-03 11:44:44 +0300297}
298
Alexander Shishkinba826642015-09-22 15:47:18 +0300299/**
Alexander Shishkinaad14ad2019-05-03 11:44:51 +0300300 * msc_is_last_win() - check if a window is the last one for a given MSC
301 * @win: window
302 * Return: true if @win is the last window in MSC's multiblock buffer
303 */
304static inline bool msc_is_last_win(struct msc_window *win)
305{
306 return win->entry.next == &win->msc->win_list;
307}
308
309/**
310 * msc_next_window() - return next window in the multiblock buffer
311 * @win: current window
312 *
313 * Return: window following the current one
314 */
315static struct msc_window *msc_next_window(struct msc_window *win)
316{
317 if (msc_is_last_win(win))
318 return list_first_entry(&win->msc->win_list, struct msc_window,
319 entry);
320
321 return list_next_entry(win, entry);
322}
323
Alexander Shishkin615c1642019-07-05 17:14:21 +0300324static size_t msc_win_total_sz(struct msc_window *win)
325{
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300326 struct scatterlist *sg;
Alexander Shishkin615c1642019-07-05 17:14:21 +0300327 unsigned int blk;
328 size_t size = 0;
329
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300330 for_each_sg(win->sgt->sgl, sg, win->nr_segs, blk) {
331 struct msc_block_desc *bdesc = sg_virt(sg);
Alexander Shishkin615c1642019-07-05 17:14:21 +0300332
333 if (msc_block_wrapped(bdesc))
Colin Ian King8e3ef7b2019-10-28 09:06:48 +0200334 return (size_t)win->nr_blocks << PAGE_SHIFT;
Alexander Shishkin615c1642019-07-05 17:14:21 +0300335
336 size += msc_total_sz(bdesc);
337 if (msc_block_last_written(bdesc))
338 break;
339 }
340
341 return size;
342}
343
Alexander Shishkinaad14ad2019-05-03 11:44:51 +0300344/**
Alexander Shishkinf505e912019-06-27 15:51:47 +0300345 * msc_find_window() - find a window matching a given sg_table
Alexander Shishkinba826642015-09-22 15:47:18 +0300346 * @msc: MSC device
Alexander Shishkinf505e912019-06-27 15:51:47 +0300347 * @sgt: SG table of the window
348 * @nonempty: skip over empty windows
Alexander Shishkinba826642015-09-22 15:47:18 +0300349 *
Alexander Shishkinf505e912019-06-27 15:51:47 +0300350 * Return: MSC window structure pointer or NULL if the window
351 * could not be found.
Alexander Shishkinba826642015-09-22 15:47:18 +0300352 */
Alexander Shishkinf505e912019-06-27 15:51:47 +0300353static struct msc_window *
354msc_find_window(struct msc *msc, struct sg_table *sgt, bool nonempty)
Alexander Shishkinba826642015-09-22 15:47:18 +0300355{
Alexander Shishkinf505e912019-06-27 15:51:47 +0300356 struct msc_window *win;
Alexander Shishkinba826642015-09-22 15:47:18 +0300357 unsigned int found = 0;
358
359 if (list_empty(&msc->win_list))
360 return NULL;
361
362 /*
363 * we might need a radix tree for this, depending on how
364 * many windows a typical user would allocate; ideally it's
365 * something like 2, in which case we're good
366 */
367 list_for_each_entry(win, &msc->win_list, entry) {
Alexander Shishkinf505e912019-06-27 15:51:47 +0300368 if (win->sgt == sgt)
Alexander Shishkinba826642015-09-22 15:47:18 +0300369 found++;
370
371 /* skip the empty ones */
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300372 if (nonempty && msc_block_is_empty(msc_win_base(win)))
Alexander Shishkinba826642015-09-22 15:47:18 +0300373 continue;
374
375 if (found)
376 return win;
377 }
378
Alexander Shishkinf505e912019-06-27 15:51:47 +0300379 return NULL;
380}
381
382/**
383 * msc_oldest_window() - locate the window with oldest data
384 * @msc: MSC device
385 *
386 * This should only be used in multiblock mode. Caller should hold the
387 * msc::user_count reference.
388 *
389 * Return: the oldest window with valid data
390 */
391static struct msc_window *msc_oldest_window(struct msc *msc)
392{
393 struct msc_window *win;
394
395 if (list_empty(&msc->win_list))
396 return NULL;
397
398 win = msc_find_window(msc, msc_next_window(msc->cur_win)->sgt, true);
399 if (win)
400 return win;
401
Alexander Shishkin0de9e032019-05-03 11:44:43 +0300402 return list_first_entry(&msc->win_list, struct msc_window, entry);
Alexander Shishkinba826642015-09-22 15:47:18 +0300403}
404
405/**
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300406 * msc_win_oldest_sg() - locate the oldest block in a given window
Alexander Shishkinba826642015-09-22 15:47:18 +0300407 * @win: window to look at
408 *
409 * Return: index of the block with the oldest data
410 */
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300411static struct scatterlist *msc_win_oldest_sg(struct msc_window *win)
Alexander Shishkinba826642015-09-22 15:47:18 +0300412{
413 unsigned int blk;
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300414 struct scatterlist *sg;
415 struct msc_block_desc *bdesc = msc_win_base(win);
Alexander Shishkinba826642015-09-22 15:47:18 +0300416
417 /* without wrapping, first block is the oldest */
418 if (!msc_block_wrapped(bdesc))
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300419 return msc_win_base_sg(win);
Alexander Shishkinba826642015-09-22 15:47:18 +0300420
421 /*
422 * with wrapping, last written block contains both the newest and the
423 * oldest data for this window.
424 */
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300425 for_each_sg(win->sgt->sgl, sg, win->nr_segs, blk) {
426 struct msc_block_desc *bdesc = sg_virt(sg);
Alexander Shishkinba826642015-09-22 15:47:18 +0300427
428 if (msc_block_last_written(bdesc))
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300429 return sg;
Alexander Shishkinba826642015-09-22 15:47:18 +0300430 }
431
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300432 return msc_win_base_sg(win);
Alexander Shishkinba826642015-09-22 15:47:18 +0300433}
434
Alexander Shishkinba826642015-09-22 15:47:18 +0300435static struct msc_block_desc *msc_iter_bdesc(struct msc_iter *iter)
436{
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300437 return sg_virt(iter->block);
Alexander Shishkinba826642015-09-22 15:47:18 +0300438}
439
440static struct msc_iter *msc_iter_install(struct msc *msc)
441{
442 struct msc_iter *iter;
443
444 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
445 if (!iter)
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200446 return ERR_PTR(-ENOMEM);
447
448 mutex_lock(&msc->buf_mutex);
449
450 /*
451 * Reading and tracing are mutually exclusive; if msc is
452 * enabled, open() will fail; otherwise existing readers
453 * will prevent enabling the msc and the rest of fops don't
454 * need to worry about it.
455 */
456 if (msc->enabled) {
457 kfree(iter);
458 iter = ERR_PTR(-EBUSY);
459 goto unlock;
460 }
Alexander Shishkinba826642015-09-22 15:47:18 +0300461
Alexander Shishkinba826642015-09-22 15:47:18 +0300462 iter->msc = msc;
463
Alexander Shishkinba826642015-09-22 15:47:18 +0300464 list_add_tail(&iter->entry, &msc->iter_list);
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200465unlock:
466 mutex_unlock(&msc->buf_mutex);
Alexander Shishkinba826642015-09-22 15:47:18 +0300467
468 return iter;
469}
470
471static void msc_iter_remove(struct msc_iter *iter, struct msc *msc)
472{
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200473 mutex_lock(&msc->buf_mutex);
Alexander Shishkinba826642015-09-22 15:47:18 +0300474 list_del(&iter->entry);
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200475 mutex_unlock(&msc->buf_mutex);
Alexander Shishkinba826642015-09-22 15:47:18 +0300476
477 kfree(iter);
478}
479
480static void msc_iter_block_start(struct msc_iter *iter)
481{
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300482 if (iter->start_block)
Alexander Shishkinba826642015-09-22 15:47:18 +0300483 return;
484
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300485 iter->start_block = msc_win_oldest_sg(iter->win);
Alexander Shishkinba826642015-09-22 15:47:18 +0300486 iter->block = iter->start_block;
487 iter->wrap_count = 0;
488
489 /*
490 * start with the block with oldest data; if data has wrapped
491 * in this window, it should be in this block
492 */
493 if (msc_block_wrapped(msc_iter_bdesc(iter)))
494 iter->wrap_count = 2;
495
496}
497
498static int msc_iter_win_start(struct msc_iter *iter, struct msc *msc)
499{
500 /* already started, nothing to do */
501 if (iter->start_win)
502 return 0;
503
504 iter->start_win = msc_oldest_window(msc);
505 if (!iter->start_win)
506 return -EINVAL;
507
508 iter->win = iter->start_win;
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300509 iter->start_block = NULL;
Alexander Shishkinba826642015-09-22 15:47:18 +0300510
511 msc_iter_block_start(iter);
512
513 return 0;
514}
515
516static int msc_iter_win_advance(struct msc_iter *iter)
517{
518 iter->win = msc_next_window(iter->win);
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300519 iter->start_block = NULL;
Alexander Shishkinba826642015-09-22 15:47:18 +0300520
521 if (iter->win == iter->start_win) {
522 iter->eof++;
523 return 1;
524 }
525
526 msc_iter_block_start(iter);
527
528 return 0;
529}
530
531static int msc_iter_block_advance(struct msc_iter *iter)
532{
533 iter->block_off = 0;
534
535 /* wrapping */
536 if (iter->wrap_count && iter->block == iter->start_block) {
537 iter->wrap_count--;
538 if (!iter->wrap_count)
539 /* copied newest data from the wrapped block */
540 return msc_iter_win_advance(iter);
541 }
542
543 /* no wrapping, check for last written block */
544 if (!iter->wrap_count && msc_block_last_written(msc_iter_bdesc(iter)))
545 /* copied newest data for the window */
546 return msc_iter_win_advance(iter);
547
548 /* block advance */
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300549 if (sg_is_last(iter->block))
550 iter->block = msc_win_base_sg(iter->win);
551 else
552 iter->block = sg_next(iter->block);
Alexander Shishkinba826642015-09-22 15:47:18 +0300553
554 /* no wrapping, sanity check in case there is no last written block */
555 if (!iter->wrap_count && iter->block == iter->start_block)
556 return msc_iter_win_advance(iter);
557
558 return 0;
559}
560
561/**
562 * msc_buffer_iterate() - go through multiblock buffer's data
563 * @iter: iterator structure
564 * @size: amount of data to scan
565 * @data: callback's private data
566 * @fn: iterator callback
567 *
568 * This will start at the window which will be written to next (containing
569 * the oldest data) and work its way to the current window, calling @fn
570 * for each chunk of data as it goes.
571 *
572 * Caller should have msc::user_count reference to make sure the buffer
573 * doesn't disappear from under us.
574 *
575 * Return: amount of data actually scanned.
576 */
577static ssize_t
578msc_buffer_iterate(struct msc_iter *iter, size_t size, void *data,
579 unsigned long (*fn)(void *, void *, size_t))
580{
581 struct msc *msc = iter->msc;
582 size_t len = size;
583 unsigned int advance;
584
585 if (iter->eof)
586 return 0;
587
588 /* start with the oldest window */
589 if (msc_iter_win_start(iter, msc))
590 return 0;
591
592 do {
593 unsigned long data_bytes = msc_data_sz(msc_iter_bdesc(iter));
594 void *src = (void *)msc_iter_bdesc(iter) + MSC_BDESC;
595 size_t tocopy = data_bytes, copied = 0;
596 size_t remaining = 0;
597
598 advance = 1;
599
600 /*
601 * If block wrapping happened, we need to visit the last block
602 * twice, because it contains both the oldest and the newest
603 * data in this window.
604 *
605 * First time (wrap_count==2), in the very beginning, to collect
606 * the oldest data, which is in the range
607 * (data_bytes..DATA_IN_PAGE).
608 *
609 * Second time (wrap_count==1), it's just like any other block,
610 * containing data in the range of [MSC_BDESC..data_bytes].
611 */
Laurent FERTe4eca2a2016-02-15 19:11:56 +0200612 if (iter->block == iter->start_block && iter->wrap_count == 2) {
Alexander Shishkinba826642015-09-22 15:47:18 +0300613 tocopy = DATA_IN_PAGE - data_bytes;
614 src += data_bytes;
615 }
616
617 if (!tocopy)
618 goto next_block;
619
620 tocopy -= iter->block_off;
621 src += iter->block_off;
622
623 if (len < tocopy) {
624 tocopy = len;
625 advance = 0;
626 }
627
628 remaining = fn(data, src, tocopy);
629
630 if (remaining)
631 advance = 0;
632
633 copied = tocopy - remaining;
634 len -= copied;
635 iter->block_off += copied;
636 iter->offset += copied;
637
638 if (!advance)
639 break;
640
641next_block:
642 if (msc_iter_block_advance(iter))
643 break;
644
645 } while (len);
646
647 return size - len;
648}
649
650/**
651 * msc_buffer_clear_hw_header() - clear hw header for multiblock
652 * @msc: MSC device
653 */
654static void msc_buffer_clear_hw_header(struct msc *msc)
655{
656 struct msc_window *win;
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300657 struct scatterlist *sg;
Alexander Shishkinba826642015-09-22 15:47:18 +0300658
Alexander Shishkinba826642015-09-22 15:47:18 +0300659 list_for_each_entry(win, &msc->win_list, entry) {
660 unsigned int blk;
661 size_t hw_sz = sizeof(struct msc_block_desc) -
662 offsetof(struct msc_block_desc, hw_tag);
663
Alexander Shishkin57b69a12019-07-05 17:14:23 +0300664 for_each_sg(win->sgt->sgl, sg, win->nr_segs, blk) {
665 struct msc_block_desc *bdesc = sg_virt(sg);
Alexander Shishkinba826642015-09-22 15:47:18 +0300666
667 memset(&bdesc->hw_tag, 0, hw_sz);
668 }
669 }
Alexander Shishkinba826642015-09-22 15:47:18 +0300670}
671
Alexander Shishkinaac8da62019-05-03 11:44:41 +0300672static int intel_th_msu_init(struct msc *msc)
673{
674 u32 mintctl, msusts;
675
676 if (!msc->do_irq)
677 return 0;
678
Alexander Shishkin615c1642019-07-05 17:14:21 +0300679 if (!msc->mbuf)
680 return 0;
681
Alexander Shishkinaac8da62019-05-03 11:44:41 +0300682 mintctl = ioread32(msc->msu_base + REG_MSU_MINTCTL);
683 mintctl |= msc->index ? M1BLIE : M0BLIE;
684 iowrite32(mintctl, msc->msu_base + REG_MSU_MINTCTL);
685 if (mintctl != ioread32(msc->msu_base + REG_MSU_MINTCTL)) {
686 dev_info(msc_dev(msc), "MINTCTL ignores writes: no usable interrupts\n");
687 msc->do_irq = 0;
688 return 0;
689 }
690
691 msusts = ioread32(msc->msu_base + REG_MSU_MSUSTS);
692 iowrite32(msusts, msc->msu_base + REG_MSU_MSUSTS);
693
694 return 0;
695}
696
697static void intel_th_msu_deinit(struct msc *msc)
698{
699 u32 mintctl;
700
701 if (!msc->do_irq)
702 return;
703
704 mintctl = ioread32(msc->msu_base + REG_MSU_MINTCTL);
705 mintctl &= msc->index ? ~M1BLIE : ~M0BLIE;
706 iowrite32(mintctl, msc->msu_base + REG_MSU_MINTCTL);
707}
708
Alexander Shishkin615c1642019-07-05 17:14:21 +0300709static int msc_win_set_lockout(struct msc_window *win,
710 enum lockout_state expect,
711 enum lockout_state new)
712{
713 enum lockout_state old;
714 unsigned long flags;
715 int ret = 0;
716
717 if (!win->msc->mbuf)
718 return 0;
719
720 spin_lock_irqsave(&win->lo_lock, flags);
721 old = win->lockout;
722
723 if (old != expect) {
724 ret = -EINVAL;
Alexander Shishkin615c1642019-07-05 17:14:21 +0300725 goto unlock;
726 }
727
728 win->lockout = new;
729
Alexander Shishkined5207a2019-07-05 17:14:24 +0300730 if (old == expect && new == WIN_LOCKED)
731 atomic_inc(&win->msc->user_count);
732 else if (old == expect && old == WIN_LOCKED)
733 atomic_dec(&win->msc->user_count);
734
Alexander Shishkin615c1642019-07-05 17:14:21 +0300735unlock:
736 spin_unlock_irqrestore(&win->lo_lock, flags);
737
738 if (ret) {
739 if (expect == WIN_READY && old == WIN_LOCKED)
740 return -EBUSY;
741
742 /* from intel_th_msc_window_unlock(), don't warn if not locked */
743 if (expect == WIN_LOCKED && old == new)
744 return 0;
Alexander Shishkin885f1232020-03-17 08:22:13 +0200745
746 dev_warn_ratelimited(msc_dev(win->msc),
747 "expected lockout state %d, got %d\n",
748 expect, old);
Alexander Shishkin615c1642019-07-05 17:14:21 +0300749 }
750
751 return ret;
752}
Alexander Shishkinba826642015-09-22 15:47:18 +0300753/**
754 * msc_configure() - set up MSC hardware
755 * @msc: the MSC device to configure
756 *
757 * Program storage mode, wrapping, burst length and trace buffer address
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200758 * into a given MSC. Then, enable tracing and set msc::enabled.
759 * The latter is serialized on msc::buf_mutex, so make sure to hold it.
Alexander Shishkinba826642015-09-22 15:47:18 +0300760 */
761static int msc_configure(struct msc *msc)
762{
763 u32 reg;
764
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200765 lockdep_assert_held(&msc->buf_mutex);
766
Alexander Shishkinba826642015-09-22 15:47:18 +0300767 if (msc->mode > MSC_MODE_MULTI)
Alexander Shishkince666be2020-03-17 08:22:14 +0200768 return -EINVAL;
Alexander Shishkinba826642015-09-22 15:47:18 +0300769
Alexander Shishkin615c1642019-07-05 17:14:21 +0300770 if (msc->mode == MSC_MODE_MULTI) {
771 if (msc_win_set_lockout(msc->cur_win, WIN_READY, WIN_INUSE))
772 return -EBUSY;
773
Alexander Shishkinba826642015-09-22 15:47:18 +0300774 msc_buffer_clear_hw_header(msc);
Alexander Shishkin615c1642019-07-05 17:14:21 +0300775 }
Alexander Shishkinba826642015-09-22 15:47:18 +0300776
Alexander Shishkin092f47c2019-07-05 17:14:25 +0300777 msc->orig_addr = ioread32(msc->reg_base + REG_MSU_MSC0BAR);
778 msc->orig_sz = ioread32(msc->reg_base + REG_MSU_MSC0SIZE);
779
Alexander Shishkinba826642015-09-22 15:47:18 +0300780 reg = msc->base_addr >> PAGE_SHIFT;
781 iowrite32(reg, msc->reg_base + REG_MSU_MSC0BAR);
782
783 if (msc->mode == MSC_MODE_SINGLE) {
784 reg = msc->nr_pages;
785 iowrite32(reg, msc->reg_base + REG_MSU_MSC0SIZE);
786 }
787
788 reg = ioread32(msc->reg_base + REG_MSU_MSC0CTL);
789 reg &= ~(MSC_MODE | MSC_WRAPEN | MSC_EN | MSC_RD_HDR_OVRD);
790
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200791 reg |= MSC_EN;
Alexander Shishkinba826642015-09-22 15:47:18 +0300792 reg |= msc->mode << __ffs(MSC_MODE);
793 reg |= msc->burst_len << __ffs(MSC_LEN);
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200794
Alexander Shishkinba826642015-09-22 15:47:18 +0300795 if (msc->wrap)
796 reg |= MSC_WRAPEN;
Alexander Shishkinba826642015-09-22 15:47:18 +0300797
798 iowrite32(reg, msc->reg_base + REG_MSU_MSC0CTL);
799
Alexander Shishkin615c1642019-07-05 17:14:21 +0300800 intel_th_msu_init(msc);
801
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200802 msc->thdev->output.multiblock = msc->mode == MSC_MODE_MULTI;
803 intel_th_trace_enable(msc->thdev);
804 msc->enabled = 1;
805
Alexander Shishkin615c1642019-07-05 17:14:21 +0300806 if (msc->mbuf && msc->mbuf->activate)
807 msc->mbuf->activate(msc->mbuf_priv);
Alexander Shishkinba826642015-09-22 15:47:18 +0300808
809 return 0;
810}
811
812/**
813 * msc_disable() - disable MSC hardware
814 * @msc: MSC device to disable
815 *
816 * If @msc is enabled, disable tracing on the switch and then disable MSC
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200817 * storage. Caller must hold msc::buf_mutex.
Alexander Shishkinba826642015-09-22 15:47:18 +0300818 */
819static void msc_disable(struct msc *msc)
820{
Alexander Shishkin615c1642019-07-05 17:14:21 +0300821 struct msc_window *win = msc->cur_win;
Alexander Shishkinba826642015-09-22 15:47:18 +0300822 u32 reg;
823
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200824 lockdep_assert_held(&msc->buf_mutex);
Alexander Shishkinba826642015-09-22 15:47:18 +0300825
Alexander Shishkin615c1642019-07-05 17:14:21 +0300826 if (msc->mode == MSC_MODE_MULTI)
827 msc_win_set_lockout(win, WIN_INUSE, WIN_LOCKED);
828
829 if (msc->mbuf && msc->mbuf->deactivate)
830 msc->mbuf->deactivate(msc->mbuf_priv);
831 intel_th_msu_deinit(msc);
Alexander Shishkinba826642015-09-22 15:47:18 +0300832 intel_th_trace_disable(msc->thdev);
833
Alexander Shishkinba826642015-09-22 15:47:18 +0300834 if (msc->mode == MSC_MODE_SINGLE) {
Alexander Shishkin8d415512019-05-03 11:44:46 +0300835 reg = ioread32(msc->reg_base + REG_MSU_MSC0STS);
Alexander Shishkinba826642015-09-22 15:47:18 +0300836 msc->single_wrap = !!(reg & MSCSTS_WRAPSTAT);
837
838 reg = ioread32(msc->reg_base + REG_MSU_MSC0MWP);
839 msc->single_sz = reg & ((msc->nr_pages << PAGE_SHIFT) - 1);
840 dev_dbg(msc_dev(msc), "MSCnMWP: %08x/%08lx, wrap: %d\n",
841 reg, msc->single_sz, msc->single_wrap);
842 }
843
844 reg = ioread32(msc->reg_base + REG_MSU_MSC0CTL);
845 reg &= ~MSC_EN;
846 iowrite32(reg, msc->reg_base + REG_MSU_MSC0CTL);
Alexander Shishkin615c1642019-07-05 17:14:21 +0300847
848 if (msc->mbuf && msc->mbuf->ready)
849 msc->mbuf->ready(msc->mbuf_priv, win->sgt,
850 msc_win_total_sz(win));
851
Alexander Shishkinba826642015-09-22 15:47:18 +0300852 msc->enabled = 0;
853
Alexander Shishkin092f47c2019-07-05 17:14:25 +0300854 iowrite32(msc->orig_addr, msc->reg_base + REG_MSU_MSC0BAR);
855 iowrite32(msc->orig_sz, msc->reg_base + REG_MSU_MSC0SIZE);
Alexander Shishkinba826642015-09-22 15:47:18 +0300856
857 dev_dbg(msc_dev(msc), "MSCnNWSA: %08x\n",
858 ioread32(msc->reg_base + REG_MSU_MSC0NWSA));
859
860 reg = ioread32(msc->reg_base + REG_MSU_MSC0STS);
861 dev_dbg(msc_dev(msc), "MSCnSTS: %08x\n", reg);
Alexander Shishkin615c1642019-07-05 17:14:21 +0300862
863 reg = ioread32(msc->reg_base + REG_MSU_MSUSTS);
864 reg &= msc->index ? MSUSTS_MSC1BLAST : MSUSTS_MSC0BLAST;
865 iowrite32(reg, msc->reg_base + REG_MSU_MSUSTS);
Alexander Shishkinba826642015-09-22 15:47:18 +0300866}
867
868static int intel_th_msc_activate(struct intel_th_device *thdev)
869{
870 struct msc *msc = dev_get_drvdata(&thdev->dev);
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200871 int ret = -EBUSY;
Alexander Shishkinba826642015-09-22 15:47:18 +0300872
873 if (!atomic_inc_unless_negative(&msc->user_count))
874 return -ENODEV;
875
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200876 mutex_lock(&msc->buf_mutex);
Alexander Shishkinba826642015-09-22 15:47:18 +0300877
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200878 /* if there are readers, refuse */
879 if (list_empty(&msc->iter_list))
880 ret = msc_configure(msc);
881
882 mutex_unlock(&msc->buf_mutex);
883
884 if (ret)
Alexander Shishkinba826642015-09-22 15:47:18 +0300885 atomic_dec(&msc->user_count);
Alexander Shishkinba826642015-09-22 15:47:18 +0300886
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200887 return ret;
Alexander Shishkinba826642015-09-22 15:47:18 +0300888}
889
890static void intel_th_msc_deactivate(struct intel_th_device *thdev)
891{
892 struct msc *msc = dev_get_drvdata(&thdev->dev);
893
Alexander Shishkina45ff6e2016-03-10 18:21:14 +0200894 mutex_lock(&msc->buf_mutex);
895 if (msc->enabled) {
896 msc_disable(msc);
897 atomic_dec(&msc->user_count);
898 }
899 mutex_unlock(&msc->buf_mutex);
Alexander Shishkinba826642015-09-22 15:47:18 +0300900}
901
902/**
903 * msc_buffer_contig_alloc() - allocate a contiguous buffer for SINGLE mode
904 * @msc: MSC device
905 * @size: allocation size in bytes
906 *
907 * This modifies msc::base, which requires msc::buf_mutex to serialize, so the
908 * caller is expected to hold it.
909 *
910 * Return: 0 on success, -errno otherwise.
911 */
912static int msc_buffer_contig_alloc(struct msc *msc, unsigned long size)
913{
Alexander Shishkin4e0eaf22019-05-03 11:44:34 +0300914 unsigned long nr_pages = size >> PAGE_SHIFT;
Alexander Shishkinba826642015-09-22 15:47:18 +0300915 unsigned int order = get_order(size);
916 struct page *page;
Alexander Shishkin4e0eaf22019-05-03 11:44:34 +0300917 int ret;
Alexander Shishkinba826642015-09-22 15:47:18 +0300918
919 if (!size)
920 return 0;
921
Alexander Shishkin4e0eaf22019-05-03 11:44:34 +0300922 ret = sg_alloc_table(&msc->single_sgt, 1, GFP_KERNEL);
923 if (ret)
924 goto err_out;
925
926 ret = -ENOMEM;
Alexander Shishkin918b8642019-06-21 19:19:29 +0300927 page = alloc_pages(GFP_KERNEL | __GFP_ZERO | GFP_DMA32, order);
Alexander Shishkinba826642015-09-22 15:47:18 +0300928 if (!page)
Alexander Shishkin4e0eaf22019-05-03 11:44:34 +0300929 goto err_free_sgt;
Alexander Shishkinba826642015-09-22 15:47:18 +0300930
931 split_page(page, order);
Alexander Shishkin4e0eaf22019-05-03 11:44:34 +0300932 sg_set_buf(msc->single_sgt.sgl, page_address(page), size);
933
934 ret = dma_map_sg(msc_dev(msc)->parent->parent, msc->single_sgt.sgl, 1,
935 DMA_FROM_DEVICE);
936 if (ret < 0)
937 goto err_free_pages;
938
939 msc->nr_pages = nr_pages;
Alexander Shishkinba826642015-09-22 15:47:18 +0300940 msc->base = page_address(page);
Alexander Shishkin4e0eaf22019-05-03 11:44:34 +0300941 msc->base_addr = sg_dma_address(msc->single_sgt.sgl);
Alexander Shishkinba826642015-09-22 15:47:18 +0300942
943 return 0;
Alexander Shishkin4e0eaf22019-05-03 11:44:34 +0300944
945err_free_pages:
946 __free_pages(page, order);
947
948err_free_sgt:
949 sg_free_table(&msc->single_sgt);
950
951err_out:
952 return ret;
Alexander Shishkinba826642015-09-22 15:47:18 +0300953}
954
955/**
956 * msc_buffer_contig_free() - free a contiguous buffer
957 * @msc: MSC configured in SINGLE mode
958 */
959static void msc_buffer_contig_free(struct msc *msc)
960{
961 unsigned long off;
962
Alexander Shishkin4e0eaf22019-05-03 11:44:34 +0300963 dma_unmap_sg(msc_dev(msc)->parent->parent, msc->single_sgt.sgl,
964 1, DMA_FROM_DEVICE);
965 sg_free_table(&msc->single_sgt);
966
Alexander Shishkinba826642015-09-22 15:47:18 +0300967 for (off = 0; off < msc->nr_pages << PAGE_SHIFT; off += PAGE_SIZE) {
968 struct page *page = virt_to_page(msc->base + off);
969
970 page->mapping = NULL;
971 __free_page(page);
972 }
973
974 msc->nr_pages = 0;
975}
976
977/**
978 * msc_buffer_contig_get_page() - find a page at a given offset
979 * @msc: MSC configured in SINGLE mode
980 * @pgoff: page offset
981 *
982 * Return: page, if @pgoff is within the range, NULL otherwise.
983 */
984static struct page *msc_buffer_contig_get_page(struct msc *msc,
985 unsigned long pgoff)
986{
987 if (pgoff >= msc->nr_pages)
988 return NULL;
989
990 return virt_to_page(msc->base + (pgoff << PAGE_SHIFT));
991}
992
Alexander Shishkinba39bd82019-05-03 11:44:44 +0300993static int __msc_buffer_win_alloc(struct msc_window *win,
Alexander Shishkinfa52b3f2019-06-27 15:51:45 +0300994 unsigned int nr_segs)
Alexander Shishkinba39bd82019-05-03 11:44:44 +0300995{
996 struct scatterlist *sg_ptr;
997 void *block;
998 int i, ret;
999
Alexander Shishkinbbbc08a2019-06-27 15:51:46 +03001000 ret = sg_alloc_table(win->sgt, nr_segs, GFP_KERNEL);
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001001 if (ret)
1002 return -ENOMEM;
1003
Alexander Shishkinbbbc08a2019-06-27 15:51:46 +03001004 for_each_sg(win->sgt->sgl, sg_ptr, nr_segs, i) {
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001005 block = dma_alloc_coherent(msc_dev(win->msc)->parent->parent,
1006 PAGE_SIZE, &sg_dma_address(sg_ptr),
1007 GFP_KERNEL);
1008 if (!block)
1009 goto err_nomem;
1010
1011 sg_set_buf(sg_ptr, block, PAGE_SIZE);
1012 }
1013
Alexander Shishkinfa52b3f2019-06-27 15:51:45 +03001014 return nr_segs;
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001015
1016err_nomem:
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001017 for_each_sg(win->sgt->sgl, sg_ptr, i, ret)
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001018 dma_free_coherent(msc_dev(win->msc)->parent->parent, PAGE_SIZE,
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001019 sg_virt(sg_ptr), sg_dma_address(sg_ptr));
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001020
Alexander Shishkinbbbc08a2019-06-27 15:51:46 +03001021 sg_free_table(win->sgt);
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001022
1023 return -ENOMEM;
1024}
1025
Shaokun Zhangb96fb362019-06-21 19:19:27 +03001026#ifdef CONFIG_X86
Alexander Shishkin02ca71e2021-06-21 18:12:45 +03001027static void msc_buffer_set_uc(struct msc *msc)
Shaokun Zhangb96fb362019-06-21 19:19:27 +03001028{
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001029 struct scatterlist *sg_ptr;
Alexander Shishkin02ca71e2021-06-21 18:12:45 +03001030 struct msc_window *win;
Shaokun Zhangb96fb362019-06-21 19:19:27 +03001031 int i;
1032
Alexander Shishkin02ca71e2021-06-21 18:12:45 +03001033 if (msc->mode == MSC_MODE_SINGLE) {
1034 set_memory_uc((unsigned long)msc->base, msc->nr_pages);
1035 return;
1036 }
1037
1038 list_for_each_entry(win, &msc->win_list, entry) {
1039 for_each_sg(win->sgt->sgl, sg_ptr, win->nr_segs, i) {
1040 /* Set the page as uncached */
1041 set_memory_uc((unsigned long)sg_virt(sg_ptr),
1042 PFN_DOWN(sg_ptr->length));
1043 }
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001044 }
Shaokun Zhangb96fb362019-06-21 19:19:27 +03001045}
1046
Alexander Shishkin02ca71e2021-06-21 18:12:45 +03001047static void msc_buffer_set_wb(struct msc *msc)
Shaokun Zhangb96fb362019-06-21 19:19:27 +03001048{
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001049 struct scatterlist *sg_ptr;
Alexander Shishkin02ca71e2021-06-21 18:12:45 +03001050 struct msc_window *win;
Shaokun Zhangb96fb362019-06-21 19:19:27 +03001051 int i;
1052
Alexander Shishkin02ca71e2021-06-21 18:12:45 +03001053 if (msc->mode == MSC_MODE_SINGLE) {
1054 set_memory_wb((unsigned long)msc->base, msc->nr_pages);
1055 return;
1056 }
1057
1058 list_for_each_entry(win, &msc->win_list, entry) {
1059 for_each_sg(win->sgt->sgl, sg_ptr, win->nr_segs, i) {
1060 /* Reset the page to write-back */
1061 set_memory_wb((unsigned long)sg_virt(sg_ptr),
1062 PFN_DOWN(sg_ptr->length));
1063 }
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001064 }
Shaokun Zhangb96fb362019-06-21 19:19:27 +03001065}
1066#else /* !X86 */
1067static inline void
Alexander Shishkin02ca71e2021-06-21 18:12:45 +03001068msc_buffer_set_uc(struct msc *msc) {}
1069static inline void msc_buffer_set_wb(struct msc *msc) {}
Shaokun Zhangb96fb362019-06-21 19:19:27 +03001070#endif /* CONFIG_X86 */
1071
Alexander Shishkinba826642015-09-22 15:47:18 +03001072/**
1073 * msc_buffer_win_alloc() - alloc a window for a multiblock mode
1074 * @msc: MSC device
1075 * @nr_blocks: number of pages in this window
1076 *
1077 * This modifies msc::win_list and msc::base, which requires msc::buf_mutex
1078 * to serialize, so the caller is expected to hold it.
1079 *
1080 * Return: 0 on success, -errno otherwise.
1081 */
1082static int msc_buffer_win_alloc(struct msc *msc, unsigned int nr_blocks)
1083{
1084 struct msc_window *win;
Shaokun Zhangb96fb362019-06-21 19:19:27 +03001085 int ret = -ENOMEM;
Alexander Shishkinba826642015-09-22 15:47:18 +03001086
1087 if (!nr_blocks)
1088 return 0;
1089
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001090 win = kzalloc(sizeof(*win), GFP_KERNEL);
Alexander Shishkinba826642015-09-22 15:47:18 +03001091 if (!win)
1092 return -ENOMEM;
1093
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001094 win->msc = msc;
Alexander Shishkinbbbc08a2019-06-27 15:51:46 +03001095 win->sgt = &win->_sgt;
Alexander Shishkin615c1642019-07-05 17:14:21 +03001096 win->lockout = WIN_READY;
1097 spin_lock_init(&win->lo_lock);
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001098
Alexander Shishkinba826642015-09-22 15:47:18 +03001099 if (!list_empty(&msc->win_list)) {
Alexander Shishkin0de9e032019-05-03 11:44:43 +03001100 struct msc_window *prev = list_last_entry(&msc->win_list,
1101 struct msc_window,
1102 entry);
Alexander Shishkinba826642015-09-22 15:47:18 +03001103
1104 win->pgoff = prev->pgoff + prev->nr_blocks;
1105 }
1106
Alexander Shishkin615c1642019-07-05 17:14:21 +03001107 if (msc->mbuf && msc->mbuf->alloc_window)
1108 ret = msc->mbuf->alloc_window(msc->mbuf_priv, &win->sgt,
1109 nr_blocks << PAGE_SHIFT);
1110 else
1111 ret = __msc_buffer_win_alloc(win, nr_blocks);
1112
1113 if (ret <= 0)
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001114 goto err_nomem;
Alexander Shishkinba826642015-09-22 15:47:18 +03001115
Alexander Shishkinfa52b3f2019-06-27 15:51:45 +03001116 win->nr_segs = ret;
1117 win->nr_blocks = nr_blocks;
Alexander Shishkinba826642015-09-22 15:47:18 +03001118
1119 if (list_empty(&msc->win_list)) {
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001120 msc->base = msc_win_base(win);
1121 msc->base_addr = msc_win_base_dma(win);
Alexander Shishkinaad14ad2019-05-03 11:44:51 +03001122 msc->cur_win = win;
Alexander Shishkinba826642015-09-22 15:47:18 +03001123 }
1124
1125 list_add_tail(&win->entry, &msc->win_list);
1126 msc->nr_pages += nr_blocks;
1127
1128 return 0;
1129
1130err_nomem:
Alexander Shishkinba826642015-09-22 15:47:18 +03001131 kfree(win);
1132
1133 return ret;
1134}
1135
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001136static void __msc_buffer_win_free(struct msc *msc, struct msc_window *win)
1137{
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001138 struct scatterlist *sg;
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001139 int i;
1140
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001141 for_each_sg(win->sgt->sgl, sg, win->nr_segs, i) {
1142 struct page *page = sg_page(sg);
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001143
1144 page->mapping = NULL;
1145 dma_free_coherent(msc_dev(win->msc)->parent->parent, PAGE_SIZE,
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001146 sg_virt(sg), sg_dma_address(sg));
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001147 }
Alexander Shishkinbbbc08a2019-06-27 15:51:46 +03001148 sg_free_table(win->sgt);
Alexander Shishkinba39bd82019-05-03 11:44:44 +03001149}
1150
Alexander Shishkinba826642015-09-22 15:47:18 +03001151/**
1152 * msc_buffer_win_free() - free a window from MSC's window list
1153 * @msc: MSC device
1154 * @win: window to free
1155 *
1156 * This modifies msc::win_list and msc::base, which requires msc::buf_mutex
1157 * to serialize, so the caller is expected to hold it.
1158 */
1159static void msc_buffer_win_free(struct msc *msc, struct msc_window *win)
1160{
Alexander Shishkinba826642015-09-22 15:47:18 +03001161 msc->nr_pages -= win->nr_blocks;
1162
1163 list_del(&win->entry);
1164 if (list_empty(&msc->win_list)) {
1165 msc->base = NULL;
1166 msc->base_addr = 0;
1167 }
1168
Alexander Shishkin615c1642019-07-05 17:14:21 +03001169 if (msc->mbuf && msc->mbuf->free_window)
1170 msc->mbuf->free_window(msc->mbuf_priv, win->sgt);
1171 else
1172 __msc_buffer_win_free(msc, win);
Alexander Shishkinba826642015-09-22 15:47:18 +03001173
1174 kfree(win);
1175}
1176
1177/**
1178 * msc_buffer_relink() - set up block descriptors for multiblock mode
1179 * @msc: MSC device
1180 *
1181 * This traverses msc::win_list, which requires msc::buf_mutex to serialize,
1182 * so the caller is expected to hold it.
1183 */
1184static void msc_buffer_relink(struct msc *msc)
1185{
1186 struct msc_window *win, *next_win;
1187
1188 /* call with msc::mutex locked */
1189 list_for_each_entry(win, &msc->win_list, entry) {
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001190 struct scatterlist *sg;
Alexander Shishkinba826642015-09-22 15:47:18 +03001191 unsigned int blk;
1192 u32 sw_tag = 0;
1193
1194 /*
1195 * Last window's next_win should point to the first window
1196 * and MSC_SW_TAG_LASTWIN should be set.
1197 */
1198 if (msc_is_last_win(win)) {
1199 sw_tag |= MSC_SW_TAG_LASTWIN;
Alexander Shishkin0de9e032019-05-03 11:44:43 +03001200 next_win = list_first_entry(&msc->win_list,
1201 struct msc_window, entry);
Alexander Shishkinba826642015-09-22 15:47:18 +03001202 } else {
Alexander Shishkin0de9e032019-05-03 11:44:43 +03001203 next_win = list_next_entry(win, entry);
Alexander Shishkinba826642015-09-22 15:47:18 +03001204 }
1205
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001206 for_each_sg(win->sgt->sgl, sg, win->nr_segs, blk) {
1207 struct msc_block_desc *bdesc = sg_virt(sg);
Alexander Shishkinba826642015-09-22 15:47:18 +03001208
1209 memset(bdesc, 0, sizeof(*bdesc));
1210
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001211 bdesc->next_win = msc_win_base_pfn(next_win);
Alexander Shishkinba826642015-09-22 15:47:18 +03001212
1213 /*
1214 * Similarly to last window, last block should point
1215 * to the first one.
1216 */
Alexander Shishkinfa52b3f2019-06-27 15:51:45 +03001217 if (blk == win->nr_segs - 1) {
Alexander Shishkinba826642015-09-22 15:47:18 +03001218 sw_tag |= MSC_SW_TAG_LASTBLK;
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001219 bdesc->next_blk = msc_win_base_pfn(win);
Alexander Shishkinba826642015-09-22 15:47:18 +03001220 } else {
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001221 dma_addr_t addr = sg_dma_address(sg_next(sg));
1222
1223 bdesc->next_blk = PFN_DOWN(addr);
Alexander Shishkinba826642015-09-22 15:47:18 +03001224 }
1225
1226 bdesc->sw_tag = sw_tag;
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001227 bdesc->block_sz = sg->length / 64;
Alexander Shishkinba826642015-09-22 15:47:18 +03001228 }
1229 }
1230
1231 /*
1232 * Make the above writes globally visible before tracing is
1233 * enabled to make sure hardware sees them coherently.
1234 */
1235 wmb();
1236}
1237
1238static void msc_buffer_multi_free(struct msc *msc)
1239{
1240 struct msc_window *win, *iter;
1241
1242 list_for_each_entry_safe(win, iter, &msc->win_list, entry)
1243 msc_buffer_win_free(msc, win);
1244}
1245
1246static int msc_buffer_multi_alloc(struct msc *msc, unsigned long *nr_pages,
1247 unsigned int nr_wins)
1248{
1249 int ret, i;
1250
1251 for (i = 0; i < nr_wins; i++) {
1252 ret = msc_buffer_win_alloc(msc, nr_pages[i]);
1253 if (ret) {
1254 msc_buffer_multi_free(msc);
1255 return ret;
1256 }
1257 }
1258
1259 msc_buffer_relink(msc);
1260
1261 return 0;
1262}
1263
1264/**
1265 * msc_buffer_free() - free buffers for MSC
1266 * @msc: MSC device
1267 *
1268 * Free MSC's storage buffers.
1269 *
1270 * This modifies msc::win_list and msc::base, which requires msc::buf_mutex to
1271 * serialize, so the caller is expected to hold it.
1272 */
1273static void msc_buffer_free(struct msc *msc)
1274{
Alexander Shishkin02ca71e2021-06-21 18:12:45 +03001275 msc_buffer_set_wb(msc);
1276
Alexander Shishkinba826642015-09-22 15:47:18 +03001277 if (msc->mode == MSC_MODE_SINGLE)
1278 msc_buffer_contig_free(msc);
1279 else if (msc->mode == MSC_MODE_MULTI)
1280 msc_buffer_multi_free(msc);
1281}
1282
1283/**
1284 * msc_buffer_alloc() - allocate a buffer for MSC
1285 * @msc: MSC device
1286 * @size: allocation size in bytes
1287 *
1288 * Allocate a storage buffer for MSC, depending on the msc::mode, it will be
1289 * either done via msc_buffer_contig_alloc() for SINGLE operation mode or
1290 * msc_buffer_win_alloc() for multiblock operation. The latter allocates one
1291 * window per invocation, so in multiblock mode this can be called multiple
1292 * times for the same MSC to allocate multiple windows.
1293 *
1294 * This modifies msc::win_list and msc::base, which requires msc::buf_mutex
1295 * to serialize, so the caller is expected to hold it.
1296 *
1297 * Return: 0 on success, -errno otherwise.
1298 */
1299static int msc_buffer_alloc(struct msc *msc, unsigned long *nr_pages,
1300 unsigned int nr_wins)
1301{
1302 int ret;
1303
1304 /* -1: buffer not allocated */
1305 if (atomic_read(&msc->user_count) != -1)
1306 return -EBUSY;
1307
1308 if (msc->mode == MSC_MODE_SINGLE) {
1309 if (nr_wins != 1)
1310 return -EINVAL;
1311
1312 ret = msc_buffer_contig_alloc(msc, nr_pages[0] << PAGE_SHIFT);
1313 } else if (msc->mode == MSC_MODE_MULTI) {
1314 ret = msc_buffer_multi_alloc(msc, nr_pages, nr_wins);
1315 } else {
Alexander Shishkince666be2020-03-17 08:22:14 +02001316 ret = -EINVAL;
Alexander Shishkinba826642015-09-22 15:47:18 +03001317 }
1318
1319 if (!ret) {
Alexander Shishkin02ca71e2021-06-21 18:12:45 +03001320 msc_buffer_set_uc(msc);
1321
Alexander Shishkinba826642015-09-22 15:47:18 +03001322 /* allocation should be visible before the counter goes to 0 */
1323 smp_mb__before_atomic();
1324
1325 if (WARN_ON_ONCE(atomic_cmpxchg(&msc->user_count, -1, 0) != -1))
1326 return -EINVAL;
1327 }
1328
1329 return ret;
1330}
1331
1332/**
1333 * msc_buffer_unlocked_free_unless_used() - free a buffer unless it's in use
1334 * @msc: MSC device
1335 *
1336 * This will free MSC buffer unless it is in use or there is no allocated
1337 * buffer.
1338 * Caller needs to hold msc::buf_mutex.
1339 *
1340 * Return: 0 on successful deallocation or if there was no buffer to
1341 * deallocate, -EBUSY if there are active users.
1342 */
1343static int msc_buffer_unlocked_free_unless_used(struct msc *msc)
1344{
1345 int count, ret = 0;
1346
1347 count = atomic_cmpxchg(&msc->user_count, 0, -1);
1348
1349 /* > 0: buffer is allocated and has users */
1350 if (count > 0)
1351 ret = -EBUSY;
1352 /* 0: buffer is allocated, no users */
1353 else if (!count)
1354 msc_buffer_free(msc);
1355 /* < 0: no buffer, nothing to do */
1356
1357 return ret;
1358}
1359
1360/**
1361 * msc_buffer_free_unless_used() - free a buffer unless it's in use
1362 * @msc: MSC device
1363 *
1364 * This is a locked version of msc_buffer_unlocked_free_unless_used().
1365 */
1366static int msc_buffer_free_unless_used(struct msc *msc)
1367{
1368 int ret;
1369
1370 mutex_lock(&msc->buf_mutex);
1371 ret = msc_buffer_unlocked_free_unless_used(msc);
1372 mutex_unlock(&msc->buf_mutex);
1373
1374 return ret;
1375}
1376
1377/**
1378 * msc_buffer_get_page() - get MSC buffer page at a given offset
1379 * @msc: MSC device
1380 * @pgoff: page offset into the storage buffer
1381 *
1382 * This traverses msc::win_list, so holding msc::buf_mutex is expected from
1383 * the caller.
1384 *
1385 * Return: page if @pgoff corresponds to a valid buffer page or NULL.
1386 */
1387static struct page *msc_buffer_get_page(struct msc *msc, unsigned long pgoff)
1388{
1389 struct msc_window *win;
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001390 struct scatterlist *sg;
Alexander Shishkinfa52b3f2019-06-27 15:51:45 +03001391 unsigned int blk;
Alexander Shishkinba826642015-09-22 15:47:18 +03001392
1393 if (msc->mode == MSC_MODE_SINGLE)
1394 return msc_buffer_contig_get_page(msc, pgoff);
1395
1396 list_for_each_entry(win, &msc->win_list, entry)
1397 if (pgoff >= win->pgoff && pgoff < win->pgoff + win->nr_blocks)
1398 goto found;
1399
1400 return NULL;
1401
1402found:
1403 pgoff -= win->pgoff;
Alexander Shishkinfa52b3f2019-06-27 15:51:45 +03001404
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001405 for_each_sg(win->sgt->sgl, sg, win->nr_segs, blk) {
1406 struct page *page = sg_page(sg);
1407 size_t pgsz = PFN_DOWN(sg->length);
Alexander Shishkinfa52b3f2019-06-27 15:51:45 +03001408
1409 if (pgoff < pgsz)
1410 return page + pgoff;
1411
1412 pgoff -= pgsz;
1413 }
1414
1415 return NULL;
Alexander Shishkinba826642015-09-22 15:47:18 +03001416}
1417
1418/**
1419 * struct msc_win_to_user_struct - data for copy_to_user() callback
1420 * @buf: userspace buffer to copy data to
1421 * @offset: running offset
1422 */
1423struct msc_win_to_user_struct {
1424 char __user *buf;
1425 unsigned long offset;
1426};
1427
1428/**
1429 * msc_win_to_user() - iterator for msc_buffer_iterate() to copy data to user
1430 * @data: callback's private data
1431 * @src: source buffer
1432 * @len: amount of data to copy from the source buffer
1433 */
1434static unsigned long msc_win_to_user(void *data, void *src, size_t len)
1435{
1436 struct msc_win_to_user_struct *u = data;
1437 unsigned long ret;
1438
1439 ret = copy_to_user(u->buf + u->offset, src, len);
1440 u->offset += len - ret;
1441
1442 return ret;
1443}
1444
1445
1446/*
1447 * file operations' callbacks
1448 */
1449
1450static int intel_th_msc_open(struct inode *inode, struct file *file)
1451{
1452 struct intel_th_device *thdev = file->private_data;
1453 struct msc *msc = dev_get_drvdata(&thdev->dev);
1454 struct msc_iter *iter;
1455
1456 if (!capable(CAP_SYS_RAWIO))
1457 return -EPERM;
1458
1459 iter = msc_iter_install(msc);
Alexander Shishkina45ff6e2016-03-10 18:21:14 +02001460 if (IS_ERR(iter))
1461 return PTR_ERR(iter);
Alexander Shishkinba826642015-09-22 15:47:18 +03001462
1463 file->private_data = iter;
1464
1465 return nonseekable_open(inode, file);
1466}
1467
1468static int intel_th_msc_release(struct inode *inode, struct file *file)
1469{
1470 struct msc_iter *iter = file->private_data;
1471 struct msc *msc = iter->msc;
1472
1473 msc_iter_remove(iter, msc);
1474
1475 return 0;
1476}
1477
1478static ssize_t
1479msc_single_to_user(struct msc *msc, char __user *buf, loff_t off, size_t len)
1480{
Alexander Shishkined392682015-10-06 12:47:18 +03001481 unsigned long size = msc->nr_pages << PAGE_SHIFT, rem = len;
Alexander Shishkinba826642015-09-22 15:47:18 +03001482 unsigned long start = off, tocopy = 0;
1483
1484 if (msc->single_wrap) {
1485 start += msc->single_sz;
1486 if (start < size) {
1487 tocopy = min(rem, size - start);
1488 if (copy_to_user(buf, msc->base + start, tocopy))
1489 return -EFAULT;
1490
1491 buf += tocopy;
1492 rem -= tocopy;
1493 start += tocopy;
1494 }
1495
1496 start &= size - 1;
1497 if (rem) {
1498 tocopy = min(rem, msc->single_sz - start);
1499 if (copy_to_user(buf, msc->base + start, tocopy))
1500 return -EFAULT;
1501
1502 rem -= tocopy;
1503 }
1504
1505 return len - rem;
1506 }
1507
1508 if (copy_to_user(buf, msc->base + start, rem))
1509 return -EFAULT;
1510
1511 return len;
1512}
1513
1514static ssize_t intel_th_msc_read(struct file *file, char __user *buf,
1515 size_t len, loff_t *ppos)
1516{
1517 struct msc_iter *iter = file->private_data;
1518 struct msc *msc = iter->msc;
1519 size_t size;
1520 loff_t off = *ppos;
1521 ssize_t ret = 0;
1522
1523 if (!atomic_inc_unless_negative(&msc->user_count))
1524 return 0;
1525
Alexander Shishkinba826642015-09-22 15:47:18 +03001526 if (msc->mode == MSC_MODE_SINGLE && !msc->single_wrap)
1527 size = msc->single_sz;
1528 else
1529 size = msc->nr_pages << PAGE_SHIFT;
1530
1531 if (!size)
Alexander Shishkinba826642015-09-22 15:47:18 +03001532 goto put_count;
Laurent FERT2bed0742016-02-15 19:11:57 +02001533
1534 if (off >= size)
1535 goto put_count;
1536
Alexander Shishkinba826642015-09-22 15:47:18 +03001537 if (off + len >= size)
1538 len = size - off;
1539
1540 if (msc->mode == MSC_MODE_SINGLE) {
1541 ret = msc_single_to_user(msc, buf, off, len);
1542 if (ret >= 0)
1543 *ppos += ret;
1544 } else if (msc->mode == MSC_MODE_MULTI) {
1545 struct msc_win_to_user_struct u = {
1546 .buf = buf,
1547 .offset = 0,
1548 };
1549
1550 ret = msc_buffer_iterate(iter, len, &u, msc_win_to_user);
1551 if (ret >= 0)
1552 *ppos = iter->offset;
1553 } else {
Alexander Shishkince666be2020-03-17 08:22:14 +02001554 ret = -EINVAL;
Alexander Shishkinba826642015-09-22 15:47:18 +03001555 }
1556
1557put_count:
1558 atomic_dec(&msc->user_count);
1559
1560 return ret;
1561}
1562
1563/*
1564 * vm operations callbacks (vm_ops)
1565 */
1566
1567static void msc_mmap_open(struct vm_area_struct *vma)
1568{
1569 struct msc_iter *iter = vma->vm_file->private_data;
1570 struct msc *msc = iter->msc;
1571
1572 atomic_inc(&msc->mmap_count);
1573}
1574
1575static void msc_mmap_close(struct vm_area_struct *vma)
1576{
1577 struct msc_iter *iter = vma->vm_file->private_data;
1578 struct msc *msc = iter->msc;
1579 unsigned long pg;
1580
1581 if (!atomic_dec_and_mutex_lock(&msc->mmap_count, &msc->buf_mutex))
1582 return;
1583
Joonsoo Kim0139aa72016-05-19 17:10:49 -07001584 /* drop page _refcounts */
Alexander Shishkinba826642015-09-22 15:47:18 +03001585 for (pg = 0; pg < msc->nr_pages; pg++) {
1586 struct page *page = msc_buffer_get_page(msc, pg);
1587
1588 if (WARN_ON_ONCE(!page))
1589 continue;
1590
1591 if (page->mapping)
1592 page->mapping = NULL;
1593 }
1594
1595 /* last mapping -- drop user_count */
1596 atomic_dec(&msc->user_count);
1597 mutex_unlock(&msc->buf_mutex);
1598}
1599
Souptick Joarder42df0502018-08-23 17:00:45 -07001600static vm_fault_t msc_mmap_fault(struct vm_fault *vmf)
Alexander Shishkinba826642015-09-22 15:47:18 +03001601{
Dave Jiang11bac802017-02-24 14:56:41 -08001602 struct msc_iter *iter = vmf->vma->vm_file->private_data;
Alexander Shishkinba826642015-09-22 15:47:18 +03001603 struct msc *msc = iter->msc;
1604
1605 vmf->page = msc_buffer_get_page(msc, vmf->pgoff);
1606 if (!vmf->page)
1607 return VM_FAULT_SIGBUS;
1608
1609 get_page(vmf->page);
Dave Jiang11bac802017-02-24 14:56:41 -08001610 vmf->page->mapping = vmf->vma->vm_file->f_mapping;
Alexander Shishkinba826642015-09-22 15:47:18 +03001611 vmf->page->index = vmf->pgoff;
1612
1613 return 0;
1614}
1615
1616static const struct vm_operations_struct msc_mmap_ops = {
1617 .open = msc_mmap_open,
1618 .close = msc_mmap_close,
1619 .fault = msc_mmap_fault,
1620};
1621
1622static int intel_th_msc_mmap(struct file *file, struct vm_area_struct *vma)
1623{
1624 unsigned long size = vma->vm_end - vma->vm_start;
1625 struct msc_iter *iter = vma->vm_file->private_data;
1626 struct msc *msc = iter->msc;
1627 int ret = -EINVAL;
1628
1629 if (!size || offset_in_page(size))
1630 return -EINVAL;
1631
1632 if (vma->vm_pgoff)
1633 return -EINVAL;
1634
1635 /* grab user_count once per mmap; drop in msc_mmap_close() */
1636 if (!atomic_inc_unless_negative(&msc->user_count))
1637 return -EINVAL;
1638
1639 if (msc->mode != MSC_MODE_SINGLE &&
1640 msc->mode != MSC_MODE_MULTI)
1641 goto out;
1642
1643 if (size >> PAGE_SHIFT != msc->nr_pages)
1644 goto out;
1645
1646 atomic_set(&msc->mmap_count, 1);
1647 ret = 0;
1648
1649out:
1650 if (ret)
1651 atomic_dec(&msc->user_count);
1652
1653 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1654 vma->vm_flags |= VM_DONTEXPAND | VM_DONTCOPY;
1655 vma->vm_ops = &msc_mmap_ops;
1656 return ret;
1657}
1658
1659static const struct file_operations intel_th_msc_fops = {
1660 .open = intel_th_msc_open,
1661 .release = intel_th_msc_release,
1662 .read = intel_th_msc_read,
1663 .mmap = intel_th_msc_mmap,
1664 .llseek = no_llseek,
Alexander Shishkin8e9a2be2016-04-08 17:36:04 +03001665 .owner = THIS_MODULE,
Alexander Shishkinba826642015-09-22 15:47:18 +03001666};
1667
Alexander Shishkin8d415512019-05-03 11:44:46 +03001668static void intel_th_msc_wait_empty(struct intel_th_device *thdev)
1669{
1670 struct msc *msc = dev_get_drvdata(&thdev->dev);
1671 unsigned long count;
1672 u32 reg;
1673
1674 for (reg = 0, count = MSC_PLE_WAITLOOP_DEPTH;
1675 count && !(reg & MSCSTS_PLE); count--) {
1676 reg = __raw_readl(msc->reg_base + REG_MSU_MSC0STS);
1677 cpu_relax();
1678 }
1679
1680 if (!count)
1681 dev_dbg(msc_dev(msc), "timeout waiting for MSC0 PLE\n");
1682}
1683
Alexander Shishkinba826642015-09-22 15:47:18 +03001684static int intel_th_msc_init(struct msc *msc)
1685{
1686 atomic_set(&msc->user_count, -1);
1687
Alexander Shishkin397c7722020-03-17 08:22:10 +02001688 msc->mode = msc->multi_is_broken ? MSC_MODE_SINGLE : MSC_MODE_MULTI;
Alexander Shishkinba826642015-09-22 15:47:18 +03001689 mutex_init(&msc->buf_mutex);
1690 INIT_LIST_HEAD(&msc->win_list);
Alexander Shishkinba826642015-09-22 15:47:18 +03001691 INIT_LIST_HEAD(&msc->iter_list);
1692
1693 msc->burst_len =
1694 (ioread32(msc->reg_base + REG_MSU_MSC0CTL) & MSC_LEN) >>
1695 __ffs(MSC_LEN);
1696
1697 return 0;
1698}
1699
Alexander Shishkin05b686b2019-12-17 13:55:27 +02001700static int msc_win_switch(struct msc *msc)
Alexander Shishkinaad14ad2019-05-03 11:44:51 +03001701{
YueHaibing9800db22019-06-21 19:19:28 +03001702 struct msc_window *first;
Alexander Shishkinaad14ad2019-05-03 11:44:51 +03001703
Alexander Shishkin05b686b2019-12-17 13:55:27 +02001704 if (list_empty(&msc->win_list))
1705 return -EINVAL;
1706
Alexander Shishkinaad14ad2019-05-03 11:44:51 +03001707 first = list_first_entry(&msc->win_list, struct msc_window, entry);
Alexander Shishkinaad14ad2019-05-03 11:44:51 +03001708
1709 if (msc_is_last_win(msc->cur_win))
1710 msc->cur_win = first;
1711 else
1712 msc->cur_win = list_next_entry(msc->cur_win, entry);
1713
Alexander Shishkin57b69a12019-07-05 17:14:23 +03001714 msc->base = msc_win_base(msc->cur_win);
1715 msc->base_addr = msc_win_base_dma(msc->cur_win);
Alexander Shishkinaad14ad2019-05-03 11:44:51 +03001716
1717 intel_th_trace_switch(msc->thdev);
Alexander Shishkin05b686b2019-12-17 13:55:27 +02001718
1719 return 0;
Alexander Shishkinaad14ad2019-05-03 11:44:51 +03001720}
1721
Alexander Shishkin615c1642019-07-05 17:14:21 +03001722/**
1723 * intel_th_msc_window_unlock - put the window back in rotation
1724 * @dev: MSC device to which this relates
1725 * @sgt: buffer's sg_table for the window, does nothing if NULL
1726 */
1727void intel_th_msc_window_unlock(struct device *dev, struct sg_table *sgt)
1728{
1729 struct msc *msc = dev_get_drvdata(dev);
1730 struct msc_window *win;
1731
1732 if (!sgt)
1733 return;
1734
1735 win = msc_find_window(msc, sgt, false);
1736 if (!win)
1737 return;
1738
1739 msc_win_set_lockout(win, WIN_LOCKED, WIN_READY);
Alexander Shishkin8622dfef2020-03-19 10:51:52 +02001740 if (msc->switch_on_unlock == win) {
1741 msc->switch_on_unlock = NULL;
1742 msc_win_switch(msc);
1743 }
Alexander Shishkin615c1642019-07-05 17:14:21 +03001744}
1745EXPORT_SYMBOL_GPL(intel_th_msc_window_unlock);
1746
1747static void msc_work(struct work_struct *work)
1748{
1749 struct msc *msc = container_of(work, struct msc, work);
1750
1751 intel_th_msc_deactivate(msc->thdev);
1752}
1753
Alexander Shishkinaac8da62019-05-03 11:44:41 +03001754static irqreturn_t intel_th_msc_interrupt(struct intel_th_device *thdev)
1755{
1756 struct msc *msc = dev_get_drvdata(&thdev->dev);
1757 u32 msusts = ioread32(msc->msu_base + REG_MSU_MSUSTS);
1758 u32 mask = msc->index ? MSUSTS_MSC1BLAST : MSUSTS_MSC0BLAST;
Alexander Shishkin615c1642019-07-05 17:14:21 +03001759 struct msc_window *win, *next_win;
Alexander Shishkinaac8da62019-05-03 11:44:41 +03001760
Alexander Shishkin615c1642019-07-05 17:14:21 +03001761 if (!msc->do_irq || !msc->mbuf)
Alexander Shishkinaac8da62019-05-03 11:44:41 +03001762 return IRQ_NONE;
Alexander Shishkin615c1642019-07-05 17:14:21 +03001763
1764 msusts &= mask;
1765
1766 if (!msusts)
1767 return msc->enabled ? IRQ_HANDLED : IRQ_NONE;
1768
1769 iowrite32(msusts, msc->msu_base + REG_MSU_MSUSTS);
1770
1771 if (!msc->enabled)
1772 return IRQ_NONE;
1773
1774 /* grab the window before we do the switch */
1775 win = msc->cur_win;
1776 if (!win)
1777 return IRQ_HANDLED;
1778 next_win = msc_next_window(win);
1779 if (!next_win)
1780 return IRQ_HANDLED;
1781
1782 /* next window: if READY, proceed, if LOCKED, stop the trace */
1783 if (msc_win_set_lockout(next_win, WIN_READY, WIN_INUSE)) {
Alexander Shishkin8622dfef2020-03-19 10:51:52 +02001784 if (msc->stop_on_full)
1785 schedule_work(&msc->work);
1786 else
1787 msc->switch_on_unlock = next_win;
1788
Alexander Shishkin615c1642019-07-05 17:14:21 +03001789 return IRQ_HANDLED;
Alexander Shishkinaac8da62019-05-03 11:44:41 +03001790 }
1791
Alexander Shishkin615c1642019-07-05 17:14:21 +03001792 /* current window: INUSE -> LOCKED */
1793 msc_win_set_lockout(win, WIN_INUSE, WIN_LOCKED);
1794
1795 msc_win_switch(msc);
1796
1797 if (msc->mbuf && msc->mbuf->ready)
1798 msc->mbuf->ready(msc->mbuf_priv, win->sgt,
1799 msc_win_total_sz(win));
1800
Alexander Shishkinaac8da62019-05-03 11:44:41 +03001801 return IRQ_HANDLED;
1802}
1803
Alexander Shishkinba826642015-09-22 15:47:18 +03001804static const char * const msc_mode[] = {
1805 [MSC_MODE_SINGLE] = "single",
1806 [MSC_MODE_MULTI] = "multi",
1807 [MSC_MODE_EXI] = "ExI",
1808 [MSC_MODE_DEBUG] = "debug",
1809};
1810
1811static ssize_t
1812wrap_show(struct device *dev, struct device_attribute *attr, char *buf)
1813{
1814 struct msc *msc = dev_get_drvdata(dev);
1815
1816 return scnprintf(buf, PAGE_SIZE, "%d\n", msc->wrap);
1817}
1818
1819static ssize_t
1820wrap_store(struct device *dev, struct device_attribute *attr, const char *buf,
1821 size_t size)
1822{
1823 struct msc *msc = dev_get_drvdata(dev);
1824 unsigned long val;
1825 int ret;
1826
1827 ret = kstrtoul(buf, 10, &val);
1828 if (ret)
1829 return ret;
1830
1831 msc->wrap = !!val;
1832
1833 return size;
1834}
1835
1836static DEVICE_ATTR_RW(wrap);
1837
Alexander Shishkin615c1642019-07-05 17:14:21 +03001838static void msc_buffer_unassign(struct msc *msc)
1839{
1840 lockdep_assert_held(&msc->buf_mutex);
1841
1842 if (!msc->mbuf)
1843 return;
1844
1845 msc->mbuf->unassign(msc->mbuf_priv);
1846 msu_buffer_put(msc->mbuf);
1847 msc->mbuf_priv = NULL;
1848 msc->mbuf = NULL;
1849}
1850
Alexander Shishkinba826642015-09-22 15:47:18 +03001851static ssize_t
1852mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1853{
1854 struct msc *msc = dev_get_drvdata(dev);
Alexander Shishkin615c1642019-07-05 17:14:21 +03001855 const char *mode = msc_mode[msc->mode];
1856 ssize_t ret;
Alexander Shishkinba826642015-09-22 15:47:18 +03001857
Alexander Shishkin615c1642019-07-05 17:14:21 +03001858 mutex_lock(&msc->buf_mutex);
1859 if (msc->mbuf)
1860 mode = msc->mbuf->name;
1861 ret = scnprintf(buf, PAGE_SIZE, "%s\n", mode);
1862 mutex_unlock(&msc->buf_mutex);
1863
1864 return ret;
Alexander Shishkinba826642015-09-22 15:47:18 +03001865}
1866
1867static ssize_t
1868mode_store(struct device *dev, struct device_attribute *attr, const char *buf,
1869 size_t size)
1870{
Alexander Shishkin615c1642019-07-05 17:14:21 +03001871 const struct msu_buffer *mbuf = NULL;
Alexander Shishkinba826642015-09-22 15:47:18 +03001872 struct msc *msc = dev_get_drvdata(dev);
1873 size_t len = size;
Alexander Shishkin615c1642019-07-05 17:14:21 +03001874 char *cp, *mode;
Alexander Shishkinba826642015-09-22 15:47:18 +03001875 int i, ret;
1876
1877 if (!capable(CAP_SYS_RAWIO))
1878 return -EPERM;
1879
1880 cp = memchr(buf, '\n', len);
1881 if (cp)
1882 len = cp - buf;
1883
Alexander Shishkin615c1642019-07-05 17:14:21 +03001884 mode = kstrndup(buf, len, GFP_KERNEL);
Colin Ian King063f0972019-10-28 09:06:47 +02001885 if (!mode)
1886 return -ENOMEM;
1887
Alexander Shishkin615c1642019-07-05 17:14:21 +03001888 i = match_string(msc_mode, ARRAY_SIZE(msc_mode), mode);
Wei Yongjun1fa1b6c2019-10-28 09:06:49 +02001889 if (i >= 0) {
1890 kfree(mode);
Alexander Shishkin615c1642019-07-05 17:14:21 +03001891 goto found;
Wei Yongjun1fa1b6c2019-10-28 09:06:49 +02001892 }
Alexander Shishkin615c1642019-07-05 17:14:21 +03001893
1894 /* Buffer sinks only work with a usable IRQ */
1895 if (!msc->do_irq) {
1896 kfree(mode);
1897 return -EINVAL;
1898 }
1899
1900 mbuf = msu_buffer_get(mode);
1901 kfree(mode);
1902 if (mbuf)
1903 goto found;
Alexander Shishkinba826642015-09-22 15:47:18 +03001904
1905 return -EINVAL;
1906
1907found:
Alexander Shishkin397c7722020-03-17 08:22:10 +02001908 if (i == MSC_MODE_MULTI && msc->multi_is_broken)
1909 return -EOPNOTSUPP;
1910
Alexander Shishkinba826642015-09-22 15:47:18 +03001911 mutex_lock(&msc->buf_mutex);
Alexander Shishkin615c1642019-07-05 17:14:21 +03001912 ret = 0;
1913
1914 /* Same buffer: do nothing */
1915 if (mbuf && mbuf == msc->mbuf) {
1916 /* put the extra reference we just got */
1917 msu_buffer_put(mbuf);
1918 goto unlock;
1919 }
1920
Alexander Shishkinba826642015-09-22 15:47:18 +03001921 ret = msc_buffer_unlocked_free_unless_used(msc);
Alexander Shishkin615c1642019-07-05 17:14:21 +03001922 if (ret)
1923 goto unlock;
1924
1925 if (mbuf) {
1926 void *mbuf_priv = mbuf->assign(dev, &i);
1927
1928 if (!mbuf_priv) {
1929 ret = -ENOMEM;
1930 goto unlock;
1931 }
1932
1933 msc_buffer_unassign(msc);
1934 msc->mbuf_priv = mbuf_priv;
1935 msc->mbuf = mbuf;
1936 } else {
1937 msc_buffer_unassign(msc);
1938 }
1939
1940 msc->mode = i;
1941
1942unlock:
1943 if (ret && mbuf)
1944 msu_buffer_put(mbuf);
Alexander Shishkinba826642015-09-22 15:47:18 +03001945 mutex_unlock(&msc->buf_mutex);
1946
1947 return ret ? ret : size;
1948}
1949
1950static DEVICE_ATTR_RW(mode);
1951
1952static ssize_t
1953nr_pages_show(struct device *dev, struct device_attribute *attr, char *buf)
1954{
1955 struct msc *msc = dev_get_drvdata(dev);
1956 struct msc_window *win;
1957 size_t count = 0;
1958
1959 mutex_lock(&msc->buf_mutex);
1960
1961 if (msc->mode == MSC_MODE_SINGLE)
1962 count = scnprintf(buf, PAGE_SIZE, "%ld\n", msc->nr_pages);
1963 else if (msc->mode == MSC_MODE_MULTI) {
1964 list_for_each_entry(win, &msc->win_list, entry) {
1965 count += scnprintf(buf + count, PAGE_SIZE - count,
1966 "%d%c", win->nr_blocks,
1967 msc_is_last_win(win) ? '\n' : ',');
1968 }
1969 } else {
1970 count = scnprintf(buf, PAGE_SIZE, "unsupported\n");
1971 }
1972
1973 mutex_unlock(&msc->buf_mutex);
1974
1975 return count;
1976}
1977
1978static ssize_t
1979nr_pages_store(struct device *dev, struct device_attribute *attr,
1980 const char *buf, size_t size)
1981{
1982 struct msc *msc = dev_get_drvdata(dev);
1983 unsigned long val, *win = NULL, *rewin;
1984 size_t len = size;
1985 const char *p = buf;
1986 char *end, *s;
1987 int ret, nr_wins = 0;
1988
1989 if (!capable(CAP_SYS_RAWIO))
1990 return -EPERM;
1991
1992 ret = msc_buffer_free_unless_used(msc);
1993 if (ret)
1994 return ret;
1995
1996 /* scan the comma-separated list of allocation sizes */
1997 end = memchr(buf, '\n', len);
1998 if (end)
1999 len = end - buf;
2000
2001 do {
2002 end = memchr(p, ',', len);
2003 s = kstrndup(p, end ? end - p : len, GFP_KERNEL);
Alexander Shishkin6575cbd2016-03-04 16:16:31 +02002004 if (!s) {
2005 ret = -ENOMEM;
2006 goto free_win;
2007 }
2008
Alexander Shishkinba826642015-09-22 15:47:18 +03002009 ret = kstrtoul(s, 10, &val);
2010 kfree(s);
2011
2012 if (ret || !val)
2013 goto free_win;
2014
2015 if (nr_wins && msc->mode == MSC_MODE_SINGLE) {
2016 ret = -EINVAL;
2017 goto free_win;
2018 }
2019
2020 nr_wins++;
Bartosz Golaszewskif8f7e2b2020-12-14 19:04:21 -08002021 rewin = krealloc_array(win, nr_wins, sizeof(*win), GFP_KERNEL);
Alexander Shishkinba826642015-09-22 15:47:18 +03002022 if (!rewin) {
2023 kfree(win);
2024 return -ENOMEM;
2025 }
2026
2027 win = rewin;
2028 win[nr_wins - 1] = val;
2029
2030 if (!end)
2031 break;
2032
Alexander Shishkinec5b5ad2018-12-19 17:19:22 +02002033 /* consume the number and the following comma, hence +1 */
2034 len -= end - p + 1;
Alexander Shishkinba826642015-09-22 15:47:18 +03002035 p = end + 1;
2036 } while (len);
2037
2038 mutex_lock(&msc->buf_mutex);
2039 ret = msc_buffer_alloc(msc, win, nr_wins);
2040 mutex_unlock(&msc->buf_mutex);
2041
2042free_win:
2043 kfree(win);
2044
2045 return ret ? ret : size;
2046}
2047
2048static DEVICE_ATTR_RW(nr_pages);
2049
Alexander Shishkin6cac7862019-05-03 11:44:50 +03002050static ssize_t
2051win_switch_store(struct device *dev, struct device_attribute *attr,
2052 const char *buf, size_t size)
2053{
2054 struct msc *msc = dev_get_drvdata(dev);
2055 unsigned long val;
2056 int ret;
2057
2058 ret = kstrtoul(buf, 10, &val);
2059 if (ret)
2060 return ret;
2061
2062 if (val != 1)
2063 return -EINVAL;
2064
Alexander Shishkin05b686b2019-12-17 13:55:27 +02002065 ret = -EINVAL;
Alexander Shishkin6cac7862019-05-03 11:44:50 +03002066 mutex_lock(&msc->buf_mutex);
Alexander Shishkin615c1642019-07-05 17:14:21 +03002067 /*
2068 * Window switch can only happen in the "multi" mode.
2069 * If a external buffer is engaged, they have the full
2070 * control over window switching.
2071 */
Alexander Shishkin05b686b2019-12-17 13:55:27 +02002072 if (msc->mode == MSC_MODE_MULTI && !msc->mbuf)
2073 ret = msc_win_switch(msc);
Alexander Shishkin6cac7862019-05-03 11:44:50 +03002074 mutex_unlock(&msc->buf_mutex);
2075
2076 return ret ? ret : size;
2077}
2078
2079static DEVICE_ATTR_WO(win_switch);
2080
Alexander Shishkin8622dfef2020-03-19 10:51:52 +02002081static ssize_t stop_on_full_show(struct device *dev,
2082 struct device_attribute *attr, char *buf)
2083{
2084 struct msc *msc = dev_get_drvdata(dev);
2085
2086 return sprintf(buf, "%d\n", msc->stop_on_full);
2087}
2088
2089static ssize_t stop_on_full_store(struct device *dev,
2090 struct device_attribute *attr,
2091 const char *buf, size_t size)
2092{
2093 struct msc *msc = dev_get_drvdata(dev);
2094 int ret;
2095
2096 ret = kstrtobool(buf, &msc->stop_on_full);
2097 if (ret)
2098 return ret;
2099
2100 return size;
2101}
2102
2103static DEVICE_ATTR_RW(stop_on_full);
2104
Alexander Shishkinba826642015-09-22 15:47:18 +03002105static struct attribute *msc_output_attrs[] = {
2106 &dev_attr_wrap.attr,
2107 &dev_attr_mode.attr,
2108 &dev_attr_nr_pages.attr,
Alexander Shishkin6cac7862019-05-03 11:44:50 +03002109 &dev_attr_win_switch.attr,
Alexander Shishkin8622dfef2020-03-19 10:51:52 +02002110 &dev_attr_stop_on_full.attr,
Alexander Shishkinba826642015-09-22 15:47:18 +03002111 NULL,
2112};
2113
Rikard Falkebornd9962f62021-04-14 20:12:48 +03002114static const struct attribute_group msc_output_group = {
Alexander Shishkinba826642015-09-22 15:47:18 +03002115 .attrs = msc_output_attrs,
2116};
2117
2118static int intel_th_msc_probe(struct intel_th_device *thdev)
2119{
2120 struct device *dev = &thdev->dev;
2121 struct resource *res;
2122 struct msc *msc;
2123 void __iomem *base;
2124 int err;
2125
2126 res = intel_th_device_get_resource(thdev, IORESOURCE_MEM, 0);
2127 if (!res)
2128 return -ENODEV;
2129
2130 base = devm_ioremap(dev, res->start, resource_size(res));
Dan Carpenter73061da2015-10-16 17:09:13 +03002131 if (!base)
2132 return -ENOMEM;
Alexander Shishkinba826642015-09-22 15:47:18 +03002133
2134 msc = devm_kzalloc(dev, sizeof(*msc), GFP_KERNEL);
2135 if (!msc)
2136 return -ENOMEM;
2137
Alexander Shishkinaac8da62019-05-03 11:44:41 +03002138 res = intel_th_device_get_resource(thdev, IORESOURCE_IRQ, 1);
2139 if (!res)
2140 msc->do_irq = 1;
2141
Alexander Shishkin397c7722020-03-17 08:22:10 +02002142 if (INTEL_TH_CAP(to_intel_th(thdev), multi_is_broken))
2143 msc->multi_is_broken = 1;
2144
Alexander Shishkinba826642015-09-22 15:47:18 +03002145 msc->index = thdev->id;
2146
2147 msc->thdev = thdev;
2148 msc->reg_base = base + msc->index * 0x100;
Alexander Shishkinaac8da62019-05-03 11:44:41 +03002149 msc->msu_base = base;
2150
Alexander Shishkin615c1642019-07-05 17:14:21 +03002151 INIT_WORK(&msc->work, msc_work);
Alexander Shishkinba826642015-09-22 15:47:18 +03002152 err = intel_th_msc_init(msc);
2153 if (err)
2154 return err;
2155
Alexander Shishkinba826642015-09-22 15:47:18 +03002156 dev_set_drvdata(dev, msc);
2157
2158 return 0;
2159}
2160
2161static void intel_th_msc_remove(struct intel_th_device *thdev)
2162{
Alexander Shishkinf152dfe2016-04-08 17:37:40 +03002163 struct msc *msc = dev_get_drvdata(&thdev->dev);
2164 int ret;
2165
2166 intel_th_msc_deactivate(thdev);
2167
2168 /*
2169 * Buffers should not be used at this point except if the
2170 * output character device is still open and the parent
2171 * device gets detached from its bus, which is a FIXME.
2172 */
2173 ret = msc_buffer_free_unless_used(msc);
2174 WARN_ON_ONCE(ret);
Alexander Shishkinba826642015-09-22 15:47:18 +03002175}
2176
2177static struct intel_th_driver intel_th_msc_driver = {
2178 .probe = intel_th_msc_probe,
2179 .remove = intel_th_msc_remove,
Alexander Shishkinaac8da62019-05-03 11:44:41 +03002180 .irq = intel_th_msc_interrupt,
Alexander Shishkin8d415512019-05-03 11:44:46 +03002181 .wait_empty = intel_th_msc_wait_empty,
Alexander Shishkinba826642015-09-22 15:47:18 +03002182 .activate = intel_th_msc_activate,
2183 .deactivate = intel_th_msc_deactivate,
2184 .fops = &intel_th_msc_fops,
Alexander Shishkin9d482ae2016-03-04 19:55:10 +02002185 .attr_group = &msc_output_group,
Alexander Shishkinba826642015-09-22 15:47:18 +03002186 .driver = {
2187 .name = "msc",
2188 .owner = THIS_MODULE,
2189 },
2190};
2191
2192module_driver(intel_th_msc_driver,
2193 intel_th_driver_register,
2194 intel_th_driver_unregister);
2195
2196MODULE_LICENSE("GPL v2");
2197MODULE_DESCRIPTION("Intel(R) Trace Hub Memory Storage Unit driver");
2198MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@linux.intel.com>");