Lines Matching refs:msc

58 	struct msc		*msc;  member
77 struct msc *msc; member
108 struct msc { struct
158 static struct msc_window *msc_oldest_window(struct msc *msc) in msc_oldest_window() argument
161 u32 reg = ioread32(msc->reg_base + REG_MSU_MSC0NWSA); in msc_oldest_window()
165 if (list_empty(&msc->win_list)) in msc_oldest_window()
173 list_for_each_entry(win, &msc->win_list, entry) { in msc_oldest_window()
185 return list_entry(msc->win_list.next, struct msc_window, entry); in msc_oldest_window()
224 return win->entry.next == &win->msc->win_list; in msc_is_last_win()
236 return list_entry(win->msc->win_list.next, struct msc_window, in msc_next_window()
254 static struct msc_iter *msc_iter_install(struct msc *msc) in msc_iter_install() argument
263 iter->msc = msc; in msc_iter_install()
265 mutex_lock(&msc->iter_mutex); in msc_iter_install()
266 list_add_tail(&iter->entry, &msc->iter_list); in msc_iter_install()
267 mutex_unlock(&msc->iter_mutex); in msc_iter_install()
272 static void msc_iter_remove(struct msc_iter *iter, struct msc *msc) in msc_iter_remove() argument
274 mutex_lock(&msc->iter_mutex); in msc_iter_remove()
276 mutex_unlock(&msc->iter_mutex); in msc_iter_remove()
299 static int msc_iter_win_start(struct msc_iter *iter, struct msc *msc) in msc_iter_win_start() argument
305 iter->start_win = msc_oldest_window(msc); in msc_iter_win_start()
380 struct msc *msc = iter->msc; in msc_buffer_iterate() local
388 if (msc_iter_win_start(iter, msc)) in msc_buffer_iterate()
453 static void msc_buffer_clear_hw_header(struct msc *msc) in msc_buffer_clear_hw_header() argument
457 mutex_lock(&msc->buf_mutex); in msc_buffer_clear_hw_header()
458 list_for_each_entry(win, &msc->win_list, entry) { in msc_buffer_clear_hw_header()
469 mutex_unlock(&msc->buf_mutex); in msc_buffer_clear_hw_header()
479 static int msc_configure(struct msc *msc) in msc_configure() argument
483 if (msc->mode > MSC_MODE_MULTI) in msc_configure()
486 if (msc->mode == MSC_MODE_MULTI) in msc_configure()
487 msc_buffer_clear_hw_header(msc); in msc_configure()
489 reg = msc->base_addr >> PAGE_SHIFT; in msc_configure()
490 iowrite32(reg, msc->reg_base + REG_MSU_MSC0BAR); in msc_configure()
492 if (msc->mode == MSC_MODE_SINGLE) { in msc_configure()
493 reg = msc->nr_pages; in msc_configure()
494 iowrite32(reg, msc->reg_base + REG_MSU_MSC0SIZE); in msc_configure()
497 reg = ioread32(msc->reg_base + REG_MSU_MSC0CTL); in msc_configure()
500 reg |= msc->mode << __ffs(MSC_MODE); in msc_configure()
501 reg |= msc->burst_len << __ffs(MSC_LEN); in msc_configure()
504 if (msc->wrap) in msc_configure()
506 if (msc->enabled) in msc_configure()
509 iowrite32(reg, msc->reg_base + REG_MSU_MSC0CTL); in msc_configure()
511 if (msc->enabled) { in msc_configure()
512 msc->thdev->output.multiblock = msc->mode == MSC_MODE_MULTI; in msc_configure()
513 intel_th_trace_enable(msc->thdev); in msc_configure()
526 static void msc_disable(struct msc *msc) in msc_disable() argument
531 if (!msc->enabled) in msc_disable()
534 intel_th_trace_disable(msc->thdev); in msc_disable()
538 reg = ioread32(msc->reg_base + REG_MSU_MSC0STS); in msc_disable()
543 dev_dbg(msc_dev(msc), "timeout waiting for MSC0 PLE\n"); in msc_disable()
545 if (msc->mode == MSC_MODE_SINGLE) { in msc_disable()
546 msc->single_wrap = !!(reg & MSCSTS_WRAPSTAT); in msc_disable()
548 reg = ioread32(msc->reg_base + REG_MSU_MSC0MWP); in msc_disable()
549 msc->single_sz = reg & ((msc->nr_pages << PAGE_SHIFT) - 1); in msc_disable()
550 dev_dbg(msc_dev(msc), "MSCnMWP: %08x/%08lx, wrap: %d\n", in msc_disable()
551 reg, msc->single_sz, msc->single_wrap); in msc_disable()
554 reg = ioread32(msc->reg_base + REG_MSU_MSC0CTL); in msc_disable()
556 iowrite32(reg, msc->reg_base + REG_MSU_MSC0CTL); in msc_disable()
557 msc->enabled = 0; in msc_disable()
559 iowrite32(0, msc->reg_base + REG_MSU_MSC0BAR); in msc_disable()
560 iowrite32(0, msc->reg_base + REG_MSU_MSC0SIZE); in msc_disable()
562 dev_dbg(msc_dev(msc), "MSCnNWSA: %08x\n", in msc_disable()
563 ioread32(msc->reg_base + REG_MSU_MSC0NWSA)); in msc_disable()
565 reg = ioread32(msc->reg_base + REG_MSU_MSC0STS); in msc_disable()
566 dev_dbg(msc_dev(msc), "MSCnSTS: %08x\n", reg); in msc_disable()
571 struct msc *msc = dev_get_drvdata(&thdev->dev); in intel_th_msc_activate() local
574 if (!atomic_inc_unless_negative(&msc->user_count)) in intel_th_msc_activate()
577 mutex_lock(&msc->iter_mutex); in intel_th_msc_activate()
578 if (!list_empty(&msc->iter_list)) in intel_th_msc_activate()
580 mutex_unlock(&msc->iter_mutex); in intel_th_msc_activate()
583 atomic_dec(&msc->user_count); in intel_th_msc_activate()
587 msc->enabled = 1; in intel_th_msc_activate()
589 return msc_configure(msc); in intel_th_msc_activate()
594 struct msc *msc = dev_get_drvdata(&thdev->dev); in intel_th_msc_deactivate() local
596 msc_disable(msc); in intel_th_msc_deactivate()
598 atomic_dec(&msc->user_count); in intel_th_msc_deactivate()
611 static int msc_buffer_contig_alloc(struct msc *msc, unsigned long size) in msc_buffer_contig_alloc() argument
624 msc->nr_pages = size >> PAGE_SHIFT; in msc_buffer_contig_alloc()
625 msc->base = page_address(page); in msc_buffer_contig_alloc()
626 msc->base_addr = page_to_phys(page); in msc_buffer_contig_alloc()
635 static void msc_buffer_contig_free(struct msc *msc) in msc_buffer_contig_free() argument
639 for (off = 0; off < msc->nr_pages << PAGE_SHIFT; off += PAGE_SIZE) { in msc_buffer_contig_free()
640 struct page *page = virt_to_page(msc->base + off); in msc_buffer_contig_free()
646 msc->nr_pages = 0; in msc_buffer_contig_free()
656 static struct page *msc_buffer_contig_get_page(struct msc *msc, in msc_buffer_contig_get_page() argument
659 if (pgoff >= msc->nr_pages) in msc_buffer_contig_get_page()
662 return virt_to_page(msc->base + (pgoff << PAGE_SHIFT)); in msc_buffer_contig_get_page()
675 static int msc_buffer_win_alloc(struct msc *msc, unsigned int nr_blocks) in msc_buffer_win_alloc() argument
689 if (!list_empty(&msc->win_list)) { in msc_buffer_win_alloc()
690 struct msc_window *prev = list_entry(msc->win_list.prev, in msc_buffer_win_alloc()
697 win->block[i].bdesc = dma_alloc_coherent(msc_dev(msc), size, in msc_buffer_win_alloc()
710 win->msc = msc; in msc_buffer_win_alloc()
713 if (list_empty(&msc->win_list)) { in msc_buffer_win_alloc()
714 msc->base = win->block[0].bdesc; in msc_buffer_win_alloc()
715 msc->base_addr = win->block[0].addr; in msc_buffer_win_alloc()
718 list_add_tail(&win->entry, &msc->win_list); in msc_buffer_win_alloc()
719 msc->nr_pages += nr_blocks; in msc_buffer_win_alloc()
729 dma_free_coherent(msc_dev(msc), size, win->block[i].bdesc, in msc_buffer_win_alloc()
745 static void msc_buffer_win_free(struct msc *msc, struct msc_window *win) in msc_buffer_win_free() argument
749 msc->nr_pages -= win->nr_blocks; in msc_buffer_win_free()
752 if (list_empty(&msc->win_list)) { in msc_buffer_win_free()
753 msc->base = NULL; in msc_buffer_win_free()
754 msc->base_addr = 0; in msc_buffer_win_free()
765 dma_free_coherent(msc_dev(win->msc), PAGE_SIZE, in msc_buffer_win_free()
779 static void msc_buffer_relink(struct msc *msc) in msc_buffer_relink() argument
784 list_for_each_entry(win, &msc->win_list, entry) { in msc_buffer_relink()
794 next_win = list_entry(msc->win_list.next, in msc_buffer_relink()
833 static void msc_buffer_multi_free(struct msc *msc) in msc_buffer_multi_free() argument
837 list_for_each_entry_safe(win, iter, &msc->win_list, entry) in msc_buffer_multi_free()
838 msc_buffer_win_free(msc, win); in msc_buffer_multi_free()
841 static int msc_buffer_multi_alloc(struct msc *msc, unsigned long *nr_pages, in msc_buffer_multi_alloc() argument
847 ret = msc_buffer_win_alloc(msc, nr_pages[i]); in msc_buffer_multi_alloc()
849 msc_buffer_multi_free(msc); in msc_buffer_multi_alloc()
854 msc_buffer_relink(msc); in msc_buffer_multi_alloc()
868 static void msc_buffer_free(struct msc *msc) in msc_buffer_free() argument
870 if (msc->mode == MSC_MODE_SINGLE) in msc_buffer_free()
871 msc_buffer_contig_free(msc); in msc_buffer_free()
872 else if (msc->mode == MSC_MODE_MULTI) in msc_buffer_free()
873 msc_buffer_multi_free(msc); in msc_buffer_free()
892 static int msc_buffer_alloc(struct msc *msc, unsigned long *nr_pages, in msc_buffer_alloc() argument
898 if (atomic_read(&msc->user_count) != -1) in msc_buffer_alloc()
901 if (msc->mode == MSC_MODE_SINGLE) { in msc_buffer_alloc()
905 ret = msc_buffer_contig_alloc(msc, nr_pages[0] << PAGE_SHIFT); in msc_buffer_alloc()
906 } else if (msc->mode == MSC_MODE_MULTI) { in msc_buffer_alloc()
907 ret = msc_buffer_multi_alloc(msc, nr_pages, nr_wins); in msc_buffer_alloc()
916 if (WARN_ON_ONCE(atomic_cmpxchg(&msc->user_count, -1, 0) != -1)) in msc_buffer_alloc()
934 static int msc_buffer_unlocked_free_unless_used(struct msc *msc) in msc_buffer_unlocked_free_unless_used() argument
938 count = atomic_cmpxchg(&msc->user_count, 0, -1); in msc_buffer_unlocked_free_unless_used()
945 msc_buffer_free(msc); in msc_buffer_unlocked_free_unless_used()
957 static int msc_buffer_free_unless_used(struct msc *msc) in msc_buffer_free_unless_used() argument
961 mutex_lock(&msc->buf_mutex); in msc_buffer_free_unless_used()
962 ret = msc_buffer_unlocked_free_unless_used(msc); in msc_buffer_free_unless_used()
963 mutex_unlock(&msc->buf_mutex); in msc_buffer_free_unless_used()
978 static struct page *msc_buffer_get_page(struct msc *msc, unsigned long pgoff) in msc_buffer_get_page() argument
982 if (msc->mode == MSC_MODE_SINGLE) in msc_buffer_get_page()
983 return msc_buffer_contig_get_page(msc, pgoff); in msc_buffer_get_page()
985 list_for_each_entry(win, &msc->win_list, entry) in msc_buffer_get_page()
1031 struct msc *msc = dev_get_drvdata(&thdev->dev); in intel_th_msc_open() local
1037 iter = msc_iter_install(msc); in intel_th_msc_open()
1049 struct msc *msc = iter->msc; in intel_th_msc_release() local
1051 msc_iter_remove(iter, msc); in intel_th_msc_release()
1057 msc_single_to_user(struct msc *msc, char __user *buf, loff_t off, size_t len) in msc_single_to_user() argument
1059 unsigned long size = msc->nr_pages << PAGE_SHIFT, rem = len; in msc_single_to_user()
1062 if (msc->single_wrap) { in msc_single_to_user()
1063 start += msc->single_sz; in msc_single_to_user()
1066 if (copy_to_user(buf, msc->base + start, tocopy)) in msc_single_to_user()
1076 tocopy = min(rem, msc->single_sz - start); in msc_single_to_user()
1077 if (copy_to_user(buf, msc->base + start, tocopy)) in msc_single_to_user()
1086 if (copy_to_user(buf, msc->base + start, rem)) in msc_single_to_user()
1096 struct msc *msc = iter->msc; in intel_th_msc_read() local
1101 if (!atomic_inc_unless_negative(&msc->user_count)) in intel_th_msc_read()
1104 if (msc->enabled) { in intel_th_msc_read()
1109 if (msc->mode == MSC_MODE_SINGLE && !msc->single_wrap) in intel_th_msc_read()
1110 size = msc->single_sz; in intel_th_msc_read()
1112 size = msc->nr_pages << PAGE_SHIFT; in intel_th_msc_read()
1124 if (msc->mode == MSC_MODE_SINGLE) { in intel_th_msc_read()
1125 ret = msc_single_to_user(msc, buf, off, len); in intel_th_msc_read()
1128 } else if (msc->mode == MSC_MODE_MULTI) { in intel_th_msc_read()
1142 atomic_dec(&msc->user_count); in intel_th_msc_read()
1154 struct msc *msc = iter->msc; in msc_mmap_open() local
1156 atomic_inc(&msc->mmap_count); in msc_mmap_open()
1162 struct msc *msc = iter->msc; in msc_mmap_close() local
1165 if (!atomic_dec_and_mutex_lock(&msc->mmap_count, &msc->buf_mutex)) in msc_mmap_close()
1169 for (pg = 0; pg < msc->nr_pages; pg++) { in msc_mmap_close()
1170 struct page *page = msc_buffer_get_page(msc, pg); in msc_mmap_close()
1180 atomic_dec(&msc->user_count); in msc_mmap_close()
1181 mutex_unlock(&msc->buf_mutex); in msc_mmap_close()
1187 struct msc *msc = iter->msc; in msc_mmap_fault() local
1189 vmf->page = msc_buffer_get_page(msc, vmf->pgoff); in msc_mmap_fault()
1210 struct msc *msc = iter->msc; in intel_th_msc_mmap() local
1220 if (!atomic_inc_unless_negative(&msc->user_count)) in intel_th_msc_mmap()
1223 if (msc->mode != MSC_MODE_SINGLE && in intel_th_msc_mmap()
1224 msc->mode != MSC_MODE_MULTI) in intel_th_msc_mmap()
1227 if (size >> PAGE_SHIFT != msc->nr_pages) in intel_th_msc_mmap()
1230 atomic_set(&msc->mmap_count, 1); in intel_th_msc_mmap()
1235 atomic_dec(&msc->user_count); in intel_th_msc_mmap()
1251 static int intel_th_msc_init(struct msc *msc) in intel_th_msc_init() argument
1253 atomic_set(&msc->user_count, -1); in intel_th_msc_init()
1255 msc->mode = MSC_MODE_MULTI; in intel_th_msc_init()
1256 mutex_init(&msc->buf_mutex); in intel_th_msc_init()
1257 INIT_LIST_HEAD(&msc->win_list); in intel_th_msc_init()
1259 mutex_init(&msc->iter_mutex); in intel_th_msc_init()
1260 INIT_LIST_HEAD(&msc->iter_list); in intel_th_msc_init()
1262 msc->burst_len = in intel_th_msc_init()
1263 (ioread32(msc->reg_base + REG_MSU_MSC0CTL) & MSC_LEN) >> in intel_th_msc_init()
1279 struct msc *msc = dev_get_drvdata(dev); in wrap_show() local
1281 return scnprintf(buf, PAGE_SIZE, "%d\n", msc->wrap); in wrap_show()
1288 struct msc *msc = dev_get_drvdata(dev); in wrap_store() local
1296 msc->wrap = !!val; in wrap_store()
1306 struct msc *msc = dev_get_drvdata(dev); in mode_show() local
1308 return scnprintf(buf, PAGE_SIZE, "%s\n", msc_mode[msc->mode]); in mode_show()
1315 struct msc *msc = dev_get_drvdata(dev); in mode_store() local
1334 mutex_lock(&msc->buf_mutex); in mode_store()
1335 ret = msc_buffer_unlocked_free_unless_used(msc); in mode_store()
1337 msc->mode = i; in mode_store()
1338 mutex_unlock(&msc->buf_mutex); in mode_store()
1348 struct msc *msc = dev_get_drvdata(dev); in nr_pages_show() local
1352 mutex_lock(&msc->buf_mutex); in nr_pages_show()
1354 if (msc->mode == MSC_MODE_SINGLE) in nr_pages_show()
1355 count = scnprintf(buf, PAGE_SIZE, "%ld\n", msc->nr_pages); in nr_pages_show()
1356 else if (msc->mode == MSC_MODE_MULTI) { in nr_pages_show()
1357 list_for_each_entry(win, &msc->win_list, entry) { in nr_pages_show()
1366 mutex_unlock(&msc->buf_mutex); in nr_pages_show()
1375 struct msc *msc = dev_get_drvdata(dev); in nr_pages_store() local
1385 ret = msc_buffer_free_unless_used(msc); in nr_pages_store()
1403 if (nr_wins && msc->mode == MSC_MODE_SINGLE) { in nr_pages_store()
1425 mutex_lock(&msc->buf_mutex); in nr_pages_store()
1426 ret = msc_buffer_alloc(msc, win, nr_wins); in nr_pages_store()
1427 mutex_unlock(&msc->buf_mutex); in nr_pages_store()
1452 struct msc *msc; in intel_th_msc_probe() local
1464 msc = devm_kzalloc(dev, sizeof(*msc), GFP_KERNEL); in intel_th_msc_probe()
1465 if (!msc) in intel_th_msc_probe()
1468 msc->index = thdev->id; in intel_th_msc_probe()
1470 msc->thdev = thdev; in intel_th_msc_probe()
1471 msc->reg_base = base + msc->index * 0x100; in intel_th_msc_probe()
1473 err = intel_th_msc_init(msc); in intel_th_msc_probe()
1481 dev_set_drvdata(dev, msc); in intel_th_msc_probe()