Lines Matching refs:msc
52 struct msc *msc; member
71 struct msc *msc; member
102 struct msc { struct
151 static struct msc_window *msc_oldest_window(struct msc *msc) in msc_oldest_window() argument
154 u32 reg = ioread32(msc->reg_base + REG_MSU_MSC0NWSA); in msc_oldest_window()
158 if (list_empty(&msc->win_list)) in msc_oldest_window()
166 list_for_each_entry(win, &msc->win_list, entry) { in msc_oldest_window()
178 return list_entry(msc->win_list.next, struct msc_window, entry); in msc_oldest_window()
217 return win->entry.next == &win->msc->win_list; in msc_is_last_win()
229 return list_entry(win->msc->win_list.next, struct msc_window, in msc_next_window()
247 static struct msc_iter *msc_iter_install(struct msc *msc) in msc_iter_install() argument
255 mutex_lock(&msc->buf_mutex); in msc_iter_install()
263 if (msc->enabled) { in msc_iter_install()
270 iter->msc = msc; in msc_iter_install()
272 list_add_tail(&iter->entry, &msc->iter_list); in msc_iter_install()
274 mutex_unlock(&msc->buf_mutex); in msc_iter_install()
279 static void msc_iter_remove(struct msc_iter *iter, struct msc *msc) in msc_iter_remove() argument
281 mutex_lock(&msc->buf_mutex); in msc_iter_remove()
283 mutex_unlock(&msc->buf_mutex); in msc_iter_remove()
306 static int msc_iter_win_start(struct msc_iter *iter, struct msc *msc) in msc_iter_win_start() argument
312 iter->start_win = msc_oldest_window(msc); in msc_iter_win_start()
387 struct msc *msc = iter->msc; in msc_buffer_iterate() local
395 if (msc_iter_win_start(iter, msc)) in msc_buffer_iterate()
460 static void msc_buffer_clear_hw_header(struct msc *msc) in msc_buffer_clear_hw_header() argument
464 list_for_each_entry(win, &msc->win_list, entry) { in msc_buffer_clear_hw_header()
485 static int msc_configure(struct msc *msc) in msc_configure() argument
489 lockdep_assert_held(&msc->buf_mutex); in msc_configure()
491 if (msc->mode > MSC_MODE_MULTI) in msc_configure()
494 if (msc->mode == MSC_MODE_MULTI) in msc_configure()
495 msc_buffer_clear_hw_header(msc); in msc_configure()
497 reg = msc->base_addr >> PAGE_SHIFT; in msc_configure()
498 iowrite32(reg, msc->reg_base + REG_MSU_MSC0BAR); in msc_configure()
500 if (msc->mode == MSC_MODE_SINGLE) { in msc_configure()
501 reg = msc->nr_pages; in msc_configure()
502 iowrite32(reg, msc->reg_base + REG_MSU_MSC0SIZE); in msc_configure()
505 reg = ioread32(msc->reg_base + REG_MSU_MSC0CTL); in msc_configure()
509 reg |= msc->mode << __ffs(MSC_MODE); in msc_configure()
510 reg |= msc->burst_len << __ffs(MSC_LEN); in msc_configure()
512 if (msc->wrap) in msc_configure()
515 iowrite32(reg, msc->reg_base + REG_MSU_MSC0CTL); in msc_configure()
517 msc->thdev->output.multiblock = msc->mode == MSC_MODE_MULTI; in msc_configure()
518 intel_th_trace_enable(msc->thdev); in msc_configure()
519 msc->enabled = 1; in msc_configure()
532 static void msc_disable(struct msc *msc) in msc_disable() argument
537 lockdep_assert_held(&msc->buf_mutex); in msc_disable()
539 intel_th_trace_disable(msc->thdev); in msc_disable()
543 reg = ioread32(msc->reg_base + REG_MSU_MSC0STS); in msc_disable()
548 dev_dbg(msc_dev(msc), "timeout waiting for MSC0 PLE\n"); in msc_disable()
550 if (msc->mode == MSC_MODE_SINGLE) { in msc_disable()
551 msc->single_wrap = !!(reg & MSCSTS_WRAPSTAT); in msc_disable()
553 reg = ioread32(msc->reg_base + REG_MSU_MSC0MWP); in msc_disable()
554 msc->single_sz = reg & ((msc->nr_pages << PAGE_SHIFT) - 1); in msc_disable()
555 dev_dbg(msc_dev(msc), "MSCnMWP: %08x/%08lx, wrap: %d\n", in msc_disable()
556 reg, msc->single_sz, msc->single_wrap); in msc_disable()
559 reg = ioread32(msc->reg_base + REG_MSU_MSC0CTL); in msc_disable()
561 iowrite32(reg, msc->reg_base + REG_MSU_MSC0CTL); in msc_disable()
562 msc->enabled = 0; in msc_disable()
564 iowrite32(0, msc->reg_base + REG_MSU_MSC0BAR); in msc_disable()
565 iowrite32(0, msc->reg_base + REG_MSU_MSC0SIZE); in msc_disable()
567 dev_dbg(msc_dev(msc), "MSCnNWSA: %08x\n", in msc_disable()
568 ioread32(msc->reg_base + REG_MSU_MSC0NWSA)); in msc_disable()
570 reg = ioread32(msc->reg_base + REG_MSU_MSC0STS); in msc_disable()
571 dev_dbg(msc_dev(msc), "MSCnSTS: %08x\n", reg); in msc_disable()
576 struct msc *msc = dev_get_drvdata(&thdev->dev); in intel_th_msc_activate() local
579 if (!atomic_inc_unless_negative(&msc->user_count)) in intel_th_msc_activate()
582 mutex_lock(&msc->buf_mutex); in intel_th_msc_activate()
585 if (list_empty(&msc->iter_list)) in intel_th_msc_activate()
586 ret = msc_configure(msc); in intel_th_msc_activate()
588 mutex_unlock(&msc->buf_mutex); in intel_th_msc_activate()
591 atomic_dec(&msc->user_count); in intel_th_msc_activate()
598 struct msc *msc = dev_get_drvdata(&thdev->dev); in intel_th_msc_deactivate() local
600 mutex_lock(&msc->buf_mutex); in intel_th_msc_deactivate()
601 if (msc->enabled) { in intel_th_msc_deactivate()
602 msc_disable(msc); in intel_th_msc_deactivate()
603 atomic_dec(&msc->user_count); in intel_th_msc_deactivate()
605 mutex_unlock(&msc->buf_mutex); in intel_th_msc_deactivate()
618 static int msc_buffer_contig_alloc(struct msc *msc, unsigned long size) in msc_buffer_contig_alloc() argument
631 msc->nr_pages = size >> PAGE_SHIFT; in msc_buffer_contig_alloc()
632 msc->base = page_address(page); in msc_buffer_contig_alloc()
633 msc->base_addr = page_to_phys(page); in msc_buffer_contig_alloc()
642 static void msc_buffer_contig_free(struct msc *msc) in msc_buffer_contig_free() argument
646 for (off = 0; off < msc->nr_pages << PAGE_SHIFT; off += PAGE_SIZE) { in msc_buffer_contig_free()
647 struct page *page = virt_to_page(msc->base + off); in msc_buffer_contig_free()
653 msc->nr_pages = 0; in msc_buffer_contig_free()
663 static struct page *msc_buffer_contig_get_page(struct msc *msc, in msc_buffer_contig_get_page() argument
666 if (pgoff >= msc->nr_pages) in msc_buffer_contig_get_page()
669 return virt_to_page(msc->base + (pgoff << PAGE_SHIFT)); in msc_buffer_contig_get_page()
682 static int msc_buffer_win_alloc(struct msc *msc, unsigned int nr_blocks) in msc_buffer_win_alloc() argument
696 if (!list_empty(&msc->win_list)) { in msc_buffer_win_alloc()
697 struct msc_window *prev = list_entry(msc->win_list.prev, in msc_buffer_win_alloc()
705 dma_alloc_coherent(msc_dev(msc)->parent->parent, size, in msc_buffer_win_alloc()
717 win->msc = msc; in msc_buffer_win_alloc()
720 if (list_empty(&msc->win_list)) { in msc_buffer_win_alloc()
721 msc->base = win->block[0].bdesc; in msc_buffer_win_alloc()
722 msc->base_addr = win->block[0].addr; in msc_buffer_win_alloc()
725 list_add_tail(&win->entry, &msc->win_list); in msc_buffer_win_alloc()
726 msc->nr_pages += nr_blocks; in msc_buffer_win_alloc()
736 dma_free_coherent(msc_dev(msc)->parent->parent, size, in msc_buffer_win_alloc()
752 static void msc_buffer_win_free(struct msc *msc, struct msc_window *win) in msc_buffer_win_free() argument
756 msc->nr_pages -= win->nr_blocks; in msc_buffer_win_free()
759 if (list_empty(&msc->win_list)) { in msc_buffer_win_free()
760 msc->base = NULL; in msc_buffer_win_free()
761 msc->base_addr = 0; in msc_buffer_win_free()
772 dma_free_coherent(msc_dev(win->msc)->parent->parent, PAGE_SIZE, in msc_buffer_win_free()
786 static void msc_buffer_relink(struct msc *msc) in msc_buffer_relink() argument
791 list_for_each_entry(win, &msc->win_list, entry) { in msc_buffer_relink()
801 next_win = list_entry(msc->win_list.next, in msc_buffer_relink()
840 static void msc_buffer_multi_free(struct msc *msc) in msc_buffer_multi_free() argument
844 list_for_each_entry_safe(win, iter, &msc->win_list, entry) in msc_buffer_multi_free()
845 msc_buffer_win_free(msc, win); in msc_buffer_multi_free()
848 static int msc_buffer_multi_alloc(struct msc *msc, unsigned long *nr_pages, in msc_buffer_multi_alloc() argument
854 ret = msc_buffer_win_alloc(msc, nr_pages[i]); in msc_buffer_multi_alloc()
856 msc_buffer_multi_free(msc); in msc_buffer_multi_alloc()
861 msc_buffer_relink(msc); in msc_buffer_multi_alloc()
875 static void msc_buffer_free(struct msc *msc) in msc_buffer_free() argument
877 if (msc->mode == MSC_MODE_SINGLE) in msc_buffer_free()
878 msc_buffer_contig_free(msc); in msc_buffer_free()
879 else if (msc->mode == MSC_MODE_MULTI) in msc_buffer_free()
880 msc_buffer_multi_free(msc); in msc_buffer_free()
899 static int msc_buffer_alloc(struct msc *msc, unsigned long *nr_pages, in msc_buffer_alloc() argument
905 if (atomic_read(&msc->user_count) != -1) in msc_buffer_alloc()
908 if (msc->mode == MSC_MODE_SINGLE) { in msc_buffer_alloc()
912 ret = msc_buffer_contig_alloc(msc, nr_pages[0] << PAGE_SHIFT); in msc_buffer_alloc()
913 } else if (msc->mode == MSC_MODE_MULTI) { in msc_buffer_alloc()
914 ret = msc_buffer_multi_alloc(msc, nr_pages, nr_wins); in msc_buffer_alloc()
923 if (WARN_ON_ONCE(atomic_cmpxchg(&msc->user_count, -1, 0) != -1)) in msc_buffer_alloc()
941 static int msc_buffer_unlocked_free_unless_used(struct msc *msc) in msc_buffer_unlocked_free_unless_used() argument
945 count = atomic_cmpxchg(&msc->user_count, 0, -1); in msc_buffer_unlocked_free_unless_used()
952 msc_buffer_free(msc); in msc_buffer_unlocked_free_unless_used()
964 static int msc_buffer_free_unless_used(struct msc *msc) in msc_buffer_free_unless_used() argument
968 mutex_lock(&msc->buf_mutex); in msc_buffer_free_unless_used()
969 ret = msc_buffer_unlocked_free_unless_used(msc); in msc_buffer_free_unless_used()
970 mutex_unlock(&msc->buf_mutex); in msc_buffer_free_unless_used()
985 static struct page *msc_buffer_get_page(struct msc *msc, unsigned long pgoff) in msc_buffer_get_page() argument
989 if (msc->mode == MSC_MODE_SINGLE) in msc_buffer_get_page()
990 return msc_buffer_contig_get_page(msc, pgoff); in msc_buffer_get_page()
992 list_for_each_entry(win, &msc->win_list, entry) in msc_buffer_get_page()
1038 struct msc *msc = dev_get_drvdata(&thdev->dev); in intel_th_msc_open() local
1044 iter = msc_iter_install(msc); in intel_th_msc_open()
1056 struct msc *msc = iter->msc; in intel_th_msc_release() local
1058 msc_iter_remove(iter, msc); in intel_th_msc_release()
1064 msc_single_to_user(struct msc *msc, char __user *buf, loff_t off, size_t len) in msc_single_to_user() argument
1066 unsigned long size = msc->nr_pages << PAGE_SHIFT, rem = len; in msc_single_to_user()
1069 if (msc->single_wrap) { in msc_single_to_user()
1070 start += msc->single_sz; in msc_single_to_user()
1073 if (copy_to_user(buf, msc->base + start, tocopy)) in msc_single_to_user()
1083 tocopy = min(rem, msc->single_sz - start); in msc_single_to_user()
1084 if (copy_to_user(buf, msc->base + start, tocopy)) in msc_single_to_user()
1093 if (copy_to_user(buf, msc->base + start, rem)) in msc_single_to_user()
1103 struct msc *msc = iter->msc; in intel_th_msc_read() local
1108 if (!atomic_inc_unless_negative(&msc->user_count)) in intel_th_msc_read()
1111 if (msc->mode == MSC_MODE_SINGLE && !msc->single_wrap) in intel_th_msc_read()
1112 size = msc->single_sz; in intel_th_msc_read()
1114 size = msc->nr_pages << PAGE_SHIFT; in intel_th_msc_read()
1125 if (msc->mode == MSC_MODE_SINGLE) { in intel_th_msc_read()
1126 ret = msc_single_to_user(msc, buf, off, len); in intel_th_msc_read()
1129 } else if (msc->mode == MSC_MODE_MULTI) { in intel_th_msc_read()
1143 atomic_dec(&msc->user_count); in intel_th_msc_read()
1155 struct msc *msc = iter->msc; in msc_mmap_open() local
1157 atomic_inc(&msc->mmap_count); in msc_mmap_open()
1163 struct msc *msc = iter->msc; in msc_mmap_close() local
1166 if (!atomic_dec_and_mutex_lock(&msc->mmap_count, &msc->buf_mutex)) in msc_mmap_close()
1170 for (pg = 0; pg < msc->nr_pages; pg++) { in msc_mmap_close()
1171 struct page *page = msc_buffer_get_page(msc, pg); in msc_mmap_close()
1181 atomic_dec(&msc->user_count); in msc_mmap_close()
1182 mutex_unlock(&msc->buf_mutex); in msc_mmap_close()
1188 struct msc *msc = iter->msc; in msc_mmap_fault() local
1190 vmf->page = msc_buffer_get_page(msc, vmf->pgoff); in msc_mmap_fault()
1211 struct msc *msc = iter->msc; in intel_th_msc_mmap() local
1221 if (!atomic_inc_unless_negative(&msc->user_count)) in intel_th_msc_mmap()
1224 if (msc->mode != MSC_MODE_SINGLE && in intel_th_msc_mmap()
1225 msc->mode != MSC_MODE_MULTI) in intel_th_msc_mmap()
1228 if (size >> PAGE_SHIFT != msc->nr_pages) in intel_th_msc_mmap()
1231 atomic_set(&msc->mmap_count, 1); in intel_th_msc_mmap()
1236 atomic_dec(&msc->user_count); in intel_th_msc_mmap()
1253 static int intel_th_msc_init(struct msc *msc) in intel_th_msc_init() argument
1255 atomic_set(&msc->user_count, -1); in intel_th_msc_init()
1257 msc->mode = MSC_MODE_MULTI; in intel_th_msc_init()
1258 mutex_init(&msc->buf_mutex); in intel_th_msc_init()
1259 INIT_LIST_HEAD(&msc->win_list); 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()
1408 if (nr_wins && msc->mode == MSC_MODE_SINGLE) { in nr_pages_store()
1430 mutex_lock(&msc->buf_mutex); in nr_pages_store()
1431 ret = msc_buffer_alloc(msc, win, nr_wins); in nr_pages_store()
1432 mutex_unlock(&msc->buf_mutex); in nr_pages_store()
1457 struct msc *msc; in intel_th_msc_probe() local
1469 msc = devm_kzalloc(dev, sizeof(*msc), GFP_KERNEL); in intel_th_msc_probe()
1470 if (!msc) in intel_th_msc_probe()
1473 msc->index = thdev->id; in intel_th_msc_probe()
1475 msc->thdev = thdev; in intel_th_msc_probe()
1476 msc->reg_base = base + msc->index * 0x100; in intel_th_msc_probe()
1478 err = intel_th_msc_init(msc); in intel_th_msc_probe()
1482 dev_set_drvdata(dev, msc); in intel_th_msc_probe()
1489 struct msc *msc = dev_get_drvdata(&thdev->dev); in intel_th_msc_remove() local
1499 ret = msc_buffer_free_unless_used(msc); in intel_th_msc_remove()