Files
android_kernel_samsung_msm8226/include/linux/kref.h
T
Jordan Crouse 2371c9bae6 msm: kgsl: Add dispatcher and server-side-sync support
Add dispatcher and server-side-sync support from the msm-3.10 branch
featuring these commits:

	msm: kgsl: Add a command dispatcher to manage the ringbuffer
	msm: kgsl: Implement KGSL fault tolerance policy in the dispatcher
	msm: kgsl: Don't process events if the timestamp hasn't changed
	msm: kgsl: Add a new command submission API
	msm: kgsl: add kgsl_sync_fence_waiter for server side sync
	msm: kgsl: Add support for KGSL_CMD_SYNCPOINT_TYPE_FENCE
	msm: kgsl: Add the event callback symbol to GPU event tracepoints
	msm: kgsl: Add a ftrace event for adreno context switches
	msm: kgsl: Try to run soft reset on all targets that support it
	msm: kgsl: Check for idle in the fault detection timer
	msm: kgsl: Improve the dispatcher issuecmds loop
	kref: Implement kref_get_unless_zero v3
	msm: kgsl: fix a race condition when calling kref_put
	msm: kgsl: Check the return value of _kgsl_context_get()
	msm: kgsl: Hold the plist spinlock to protect nodes
	msm: kgsl: Hold a reference to process private when creating context
	msm: kgsl: Do not delete command batch unless it's retired
	msm: kgsl: Check whether context is detached before updating timestamp
	msm: kgsl: Free the cmdbatch when it fails to be requeued
	msm: kgsl: Clear dispatcher fault bit if inflight commands are 0
	msm: kgsl: Do not register additional IOMMU faults
	msm: kgsl: Do not overwrite dispatcher fault
	msm: kgsl: Define new fault type for IOMMU fault
	msm: kgsl: On IOMMU fault force a hard reset
	msm: kgsl: Max the expired timestamp of invalidated context
	msm: kgsl: Do not allow events with bogus timestamp
	msm: kgsl: Immediately set the fault bit on a pagefault
	msm: kgsl: Set FSR to 0 on IOMMU pagefault
	msm: kgsl: Do not call dispatcher fault handler if already called
	msm: kgsl: Only skip IB for faulting context
	msm: kgsl: Retry hard reset more than once on failure
	msm: kgsl: Wake up threads after context detach
	msm: kgsl: Don't pause the dispatcher in adreno_dispatcher_stop
	msm: kgsl: Fix draw context fair scheduling in the dispatcher
	msm: kgsl: Return -EPROTO in certain functions if the GPU has faulted
	msm: kgsl: GPU pagefault policy change to not stall on pagefault
	msm: kgsl: A few quick cleanups to improve stability
	msm: kgsl: Return -ENOTTY for legacy waittimestamp calls
	msm: kgsl Check NULL return from kgsl_get_device_from_dev
	msm: kgsl: use kgsl_context_detached() in adreno_dispatcher_queue_cmd()
	msm: kgsl: remove KGSL_STATE_DUMP_AND_FT
	msm: kgsl: Re-add the irq_last functionality
	msm: kgsl: Allow sync points to be created on the submitter's context
	msm: kgsl: Don't repeatedly call adreno_stop during reset
	msm: kgsl:  Add an helper function to clear the GPU fault after reset

Change-Id: Ic0dedbad5ae48dddad1e5f76875b0a8604017cc3
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
2013-11-05 11:37:11 -07:00

119 lines
3.8 KiB
C

/*
* kref.h - library routines for handling generic reference counted objects
*
* Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
* Copyright (C) 2004 IBM Corp.
*
* based on kobject.h which was:
* Copyright (C) 2002-2003 Patrick Mochel <mochel@osdl.org>
* Copyright (C) 2002-2003 Open Source Development Labs
*
* This file is released under the GPLv2.
*
*/
#ifndef _KREF_H_
#define _KREF_H_
#include <linux/bug.h>
#include <linux/atomic.h>
#include <linux/kernel.h>
struct kref {
atomic_t refcount;
};
/**
* kref_init - initialize object.
* @kref: object in question.
*/
static inline void kref_init(struct kref *kref)
{
atomic_set(&kref->refcount, 1);
}
/**
* kref_get - increment refcount for object.
* @kref: object.
*/
static inline void kref_get(struct kref *kref)
{
WARN_ON(!atomic_read(&kref->refcount));
atomic_inc(&kref->refcount);
}
/**
* kref_sub - subtract a number of refcounts for object.
* @kref: object.
* @count: Number of recounts to subtract.
* @release: pointer to the function that will clean up the object when the
* last reference to the object is released.
* This pointer is required, and it is not acceptable to pass kfree
* in as this function. If the caller does pass kfree to this
* function, you will be publicly mocked mercilessly by the kref
* maintainer, and anyone else who happens to notice it. You have
* been warned.
*
* Subtract @count from the refcount, and if 0, call release().
* Return 1 if the object was removed, otherwise return 0. Beware, if this
* function returns 0, you still can not count on the kref from remaining in
* memory. Only use the return value if you want to see if the kref is now
* gone, not present.
*/
static inline int kref_sub(struct kref *kref, unsigned int count,
void (*release)(struct kref *kref))
{
WARN_ON(release == NULL);
if (atomic_sub_and_test((int) count, &kref->refcount)) {
release(kref);
return 1;
}
return 0;
}
/**
* kref_put - decrement refcount for object.
* @kref: object.
* @release: pointer to the function that will clean up the object when the
* last reference to the object is released.
* This pointer is required, and it is not acceptable to pass kfree
* in as this function. If the caller does pass kfree to this
* function, you will be publicly mocked mercilessly by the kref
* maintainer, and anyone else who happens to notice it. You have
* been warned.
*
* Decrement the refcount, and if 0, call release().
* Return 1 if the object was removed, otherwise return 0. Beware, if this
* function returns 0, you still can not count on the kref from remaining in
* memory. Only use the return value if you want to see if the kref is now
* gone, not present.
*/
static inline int kref_put(struct kref *kref, void (*release)(struct kref *kref))
{
return kref_sub(kref, 1, release);
}
/**
* kref_get_unless_zero - Increment refcount for object unless it is zero.
* @kref: object.
*
* Return non-zero if the increment succeeded. Otherwise return 0.
*
* This function is intended to simplify locking around refcounting for
* objects that can be looked up from a lookup structure, and which are
* removed from that lookup structure in the object destructor.
* Operations on such objects require at least a read lock around
* lookup + kref_get, and a write lock around kref_put + remove from lookup
* structure. Furthermore, RCU implementations become extremely tricky.
* With a lookup followed by a kref_get_unless_zero *with return value check*
* locking in the kref_put path can be deferred to the actual removal from
* the lookup structure and RCU lookups become trivial.
*/
static inline int __must_check kref_get_unless_zero(struct kref *kref)
{
return atomic_add_unless(&kref->refcount, 1, 0);
}
#endif /* _KREF_H_ */