| 1 | /* $NetBSD: nouveau_subdev_timer_base.c,v 1.1.1.1 2014/08/06 12:36:32 riastradh Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2012 Red Hat Inc. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | * Authors: Ben Skeggs |
| 25 | */ |
| 26 | |
| 27 | #include <sys/cdefs.h> |
| 28 | __KERNEL_RCSID(0, "$NetBSD: nouveau_subdev_timer_base.c,v 1.1.1.1 2014/08/06 12:36:32 riastradh Exp $" ); |
| 29 | |
| 30 | #include "subdev/timer.h" |
| 31 | |
| 32 | bool |
| 33 | nouveau_timer_wait_eq(void *obj, u64 nsec, u32 addr, u32 mask, u32 data) |
| 34 | { |
| 35 | struct nouveau_timer *ptimer = nouveau_timer(obj); |
| 36 | u64 time0; |
| 37 | |
| 38 | time0 = ptimer->read(ptimer); |
| 39 | do { |
| 40 | if (nv_iclass(obj, NV_SUBDEV_CLASS)) { |
| 41 | if ((nv_rd32(obj, addr) & mask) == data) |
| 42 | return true; |
| 43 | } else { |
| 44 | if ((nv_ro32(obj, addr) & mask) == data) |
| 45 | return true; |
| 46 | } |
| 47 | } while (ptimer->read(ptimer) - time0 < nsec); |
| 48 | |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | bool |
| 53 | nouveau_timer_wait_ne(void *obj, u64 nsec, u32 addr, u32 mask, u32 data) |
| 54 | { |
| 55 | struct nouveau_timer *ptimer = nouveau_timer(obj); |
| 56 | u64 time0; |
| 57 | |
| 58 | time0 = ptimer->read(ptimer); |
| 59 | do { |
| 60 | if (nv_iclass(obj, NV_SUBDEV_CLASS)) { |
| 61 | if ((nv_rd32(obj, addr) & mask) != data) |
| 62 | return true; |
| 63 | } else { |
| 64 | if ((nv_ro32(obj, addr) & mask) != data) |
| 65 | return true; |
| 66 | } |
| 67 | } while (ptimer->read(ptimer) - time0 < nsec); |
| 68 | |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | bool |
| 73 | nouveau_timer_wait_cb(void *obj, u64 nsec, bool (*func)(void *), void *data) |
| 74 | { |
| 75 | struct nouveau_timer *ptimer = nouveau_timer(obj); |
| 76 | u64 time0; |
| 77 | |
| 78 | time0 = ptimer->read(ptimer); |
| 79 | do { |
| 80 | if (func(data) == true) |
| 81 | return true; |
| 82 | } while (ptimer->read(ptimer) - time0 < nsec); |
| 83 | |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | void |
| 88 | nouveau_timer_alarm(void *obj, u32 nsec, struct nouveau_alarm *alarm) |
| 89 | { |
| 90 | struct nouveau_timer *ptimer = nouveau_timer(obj); |
| 91 | ptimer->alarm(ptimer, nsec, alarm); |
| 92 | } |
| 93 | |
| 94 | void |
| 95 | nouveau_timer_alarm_cancel(void *obj, struct nouveau_alarm *alarm) |
| 96 | { |
| 97 | struct nouveau_timer *ptimer = nouveau_timer(obj); |
| 98 | ptimer->alarm_cancel(ptimer, alarm); |
| 99 | } |
| 100 | |