Commit 0ce81788 authored by Chris Wilson's avatar Chris Wilson

drm/i915: Redefine ptr_pack_bits() and friends

Rebrand the current (pointer | bits) pack/unpack utility macros as
explicit bit twiddling for PAGE_SIZE so that we can use the more
flexible underlying macros for different bits.
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20170517121007.27224-4-chris@chris-wilson.co.uk
parent 991bfc64
...@@ -1284,7 +1284,7 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine, ...@@ -1284,7 +1284,7 @@ int intel_engine_cmd_parser(struct intel_engine_cs *engine,
if (*cmd == MI_BATCH_BUFFER_END) { if (*cmd == MI_BATCH_BUFFER_END) {
if (needs_clflush_after) { if (needs_clflush_after) {
void *ptr = ptr_mask_bits(shadow_batch_obj->mm.mapping); void *ptr = page_mask_bits(shadow_batch_obj->mm.mapping);
drm_clflush_virt_range(ptr, drm_clflush_virt_range(ptr,
(void *)(cmd + 1) - ptr); (void *)(cmd + 1) - ptr);
} }
......
...@@ -2280,7 +2280,7 @@ void __i915_gem_object_put_pages(struct drm_i915_gem_object *obj, ...@@ -2280,7 +2280,7 @@ void __i915_gem_object_put_pages(struct drm_i915_gem_object *obj,
if (obj->mm.mapping) { if (obj->mm.mapping) {
void *ptr; void *ptr;
ptr = ptr_mask_bits(obj->mm.mapping); ptr = page_mask_bits(obj->mm.mapping);
if (is_vmalloc_addr(ptr)) if (is_vmalloc_addr(ptr))
vunmap(ptr); vunmap(ptr);
else else
...@@ -2612,7 +2612,7 @@ void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj, ...@@ -2612,7 +2612,7 @@ void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj,
} }
GEM_BUG_ON(!obj->mm.pages); GEM_BUG_ON(!obj->mm.pages);
ptr = ptr_unpack_bits(obj->mm.mapping, &has_type); ptr = page_unpack_bits(obj->mm.mapping, &has_type);
if (ptr && has_type != type) { if (ptr && has_type != type) {
if (pinned) { if (pinned) {
ret = -EBUSY; ret = -EBUSY;
...@@ -2634,7 +2634,7 @@ void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj, ...@@ -2634,7 +2634,7 @@ void *i915_gem_object_pin_map(struct drm_i915_gem_object *obj,
goto err_unpin; goto err_unpin;
} }
obj->mm.mapping = ptr_pack_bits(ptr, type); obj->mm.mapping = page_pack_bits(ptr, type);
} }
out_unlock: out_unlock:
......
...@@ -70,20 +70,27 @@ ...@@ -70,20 +70,27 @@
#define overflows_type(x, T) \ #define overflows_type(x, T) \
(sizeof(x) > sizeof(T) && (x) >> (sizeof(T) * BITS_PER_BYTE)) (sizeof(x) > sizeof(T) && (x) >> (sizeof(T) * BITS_PER_BYTE))
#define ptr_mask_bits(ptr) ({ \ #define ptr_mask_bits(ptr, n) ({ \
unsigned long __v = (unsigned long)(ptr); \ unsigned long __v = (unsigned long)(ptr); \
(typeof(ptr))(__v & PAGE_MASK); \ (typeof(ptr))(__v & -BIT(n)); \
}) })
#define ptr_unpack_bits(ptr, bits) ({ \ #define ptr_unmask_bits(ptr, n) ((unsigned long)(ptr) & (BIT(n) - 1))
#define ptr_unpack_bits(ptr, bits, n) ({ \
unsigned long __v = (unsigned long)(ptr); \ unsigned long __v = (unsigned long)(ptr); \
*(bits) = __v & ~PAGE_MASK; \ *(bits) = __v & (BIT(n) - 1); \
(typeof(ptr))(__v & PAGE_MASK); \ (typeof(ptr))(__v & -BIT(n)); \
}) })
#define ptr_pack_bits(ptr, bits) \ #define ptr_pack_bits(ptr, bits, n) \
((typeof(ptr))((unsigned long)(ptr) | (bits))) ((typeof(ptr))((unsigned long)(ptr) | (bits)))
#define page_mask_bits(ptr) ptr_mask_bits(ptr, PAGE_SHIFT)
#define page_unmask_bits(ptr) ptr_unmask_bits(ptr, PAGE_SHIFT)
#define page_pack_bits(ptr, bits) ptr_pack_bits(ptr, bits, PAGE_SHIFT)
#define page_unpack_bits(ptr, bits) ptr_unpack_bits(ptr, bits, PAGE_SHIFT)
#define ptr_offset(ptr, member) offsetof(typeof(*(ptr)), member) #define ptr_offset(ptr, member) offsetof(typeof(*(ptr)), member)
#define fetch_and_zero(ptr) ({ \ #define fetch_and_zero(ptr) ({ \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment