-/* $OpenBSD: i915_drv.c,v 1.80 2015/04/18 11:05:32 jsg Exp $ */
+/* $OpenBSD: i915_drv.c,v 1.81 2015/04/18 11:21:12 jsg Exp $ */
/*
* Copyright (c) 2008-2009 Owain G. Ainsworth <oga@openbsd.org>
*
return 0;
}
-/*
- * Debug code from here.
- */
-
-#if (INTELDRM_DEBUG > 1)
-
-int i915_gem_object_list_info(int, uint);
-
-static const char *get_pin_flag(struct drm_i915_gem_object *obj)
-{
- if (obj->user_pin_count > 0)
- return "P";
- if (obj->pin_count > 0)
- return "p";
- else
- return " ";
-}
-
-static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
-{
- switch (obj->tiling_mode) {
- default:
- case I915_TILING_NONE: return " ";
- case I915_TILING_X: return "X";
- case I915_TILING_Y: return "Y";
- }
-}
-
-static const char *
-cache_level_str(int type)
-{
- switch (type) {
- case I915_CACHE_NONE: return " uncached";
- case I915_CACHE_LLC: return " snooped (LLC)";
- case I915_CACHE_LLC_MLC: return " snooped (LLC+MLC)";
- default: return "";
- }
-}
-
-static void
-describe_obj(struct drm_i915_gem_object *obj)
-{
- printf("%p: %s%s %8zdKiB %04x %04x %d %d %d%s%s%s",
- &obj->base,
- get_pin_flag(obj),
- get_tiling_flag(obj),
- obj->base.size / 1024,
- obj->base.read_domains,
- obj->base.write_domain,
- obj->last_read_seqno,
- obj->last_write_seqno,
- obj->last_fenced_seqno,
- cache_level_str(obj->cache_level),
- obj->dirty ? " dirty" : "",
- obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
- if (obj->base.name)
- printf(" (name: %d)", obj->base.name);
- if (obj->pin_count)
- printf(" (pinned x %d)", obj->pin_count);
- if (obj->fence_reg != I915_FENCE_REG_NONE)
- printf(" (fence: %d)", obj->fence_reg);
-#if 0
- if (obj->gtt_space != NULL)
- printf(" (gtt offset: %08x, size: %08x)",
- obj->gtt_offset, (unsigned int)obj->gtt_space->size);
- if (obj->pin_mappable || obj->fault_mappable) {
- char s[3], *t = s;
- if (obj->pin_mappable)
- *t++ = 'p';
- if (obj->fault_mappable)
- *t++ = 'f';
- *t = '\0';
- printf(" (%s mappable)", s);
- }
-#endif
- if (obj->ring != NULL)
- printf(" (%s)", obj->ring->name);
-}
-
-#define ACTIVE_LIST 0
-#define INACTIVE_LIST 1
-
-int
-i915_gem_object_list_info(int kdev, uint list)
-{
- struct drm_device *dev = drm_get_device_from_kdev(kdev);
- struct list_head *head;
- drm_i915_private_t *dev_priv = dev->dev_private;
- struct drm_i915_gem_object *obj;
- size_t total_obj_size, total_gtt_size;
- int count;
-#if 0
- int ret;
-
- ret = mutex_lock_interruptible(&dev->struct_mutex);
- if (ret)
- return ret;
-#endif
-
- switch (list) {
- case ACTIVE_LIST:
- printf("Active:\n");
- head = &dev_priv->mm.active_list;
- break;
- case INACTIVE_LIST:
- printf("Inactive:\n");
- head = &dev_priv->mm.inactive_list;
- break;
- default:
-// mutex_unlock(&dev->struct_mutex);
- return -EINVAL;
- }
-
- total_obj_size = total_gtt_size = count = 0;
- list_for_each_entry(obj, head, mm_list) {
- printf(" ");
- describe_obj(obj);
- printf("\n");
- total_obj_size += obj->base.size;
- count++;
- }
-// mutex_unlock(&dev->struct_mutex);
-
- printf("Total %d objects, %zu bytes, %zu GTT size\n",
- count, total_obj_size);
- return 0;
-}
-
-
-static void i915_ring_seqno_info(struct intel_ring_buffer *ring)
-{
- if (ring->get_seqno) {
- printf("Current sequence (%s): %d\n",
- ring->name, ring->get_seqno(ring, false));
- }
-}
-
-void
-i915_gem_seqno_info(int kdev)
-{
- struct drm_device *dev = drm_get_device_from_kdev(kdev);
- struct inteldrm_softc *dev_priv = dev->dev_private;
- struct intel_ring_buffer *ring;
- int i;
-
- for_each_ring(ring, dev_priv, i)
- i915_ring_seqno_info(ring);
-}
-
-void
-i915_interrupt_info(int kdev)
-{
- struct drm_device *dev = drm_get_device_from_kdev(kdev);
- struct inteldrm_softc *dev_priv = dev->dev_private;
- struct intel_ring_buffer *ring;
- int i, pipe;
-
- if (IS_VALLEYVIEW(dev)) {
- printf("Display IER:\t%08x\n",
- I915_READ(VLV_IER));
- printf("Display IIR:\t%08x\n",
- I915_READ(VLV_IIR));
- printf("Display IIR_RW:\t%08x\n",
- I915_READ(VLV_IIR_RW));
- printf("Display IMR:\t%08x\n",
- I915_READ(VLV_IMR));
- for_each_pipe(pipe)
- printf("Pipe %c stat:\t%08x\n",
- pipe_name(pipe),
- I915_READ(PIPESTAT(pipe)));
-
- printf("Master IER:\t%08x\n",
- I915_READ(VLV_MASTER_IER));
-
- printf("Render IER:\t%08x\n",
- I915_READ(GTIER));
- printf("Render IIR:\t%08x\n",
- I915_READ(GTIIR));
- printf("Render IMR:\t%08x\n",
- I915_READ(GTIMR));
-
- printf("PM IER:\t\t%08x\n",
- I915_READ(GEN6_PMIER));
- printf("PM IIR:\t\t%08x\n",
- I915_READ(GEN6_PMIIR));
- printf("PM IMR:\t\t%08x\n",
- I915_READ(GEN6_PMIMR));
-
- printf("Port hotplug:\t%08x\n",
- I915_READ(PORT_HOTPLUG_EN));
- printf("DPFLIPSTAT:\t%08x\n",
- I915_READ(VLV_DPFLIPSTAT));
- printf("DPINVGTT:\t%08x\n",
- I915_READ(DPINVGTT));
-
- } else if (!HAS_PCH_SPLIT(dev)) {
- printf("Interrupt enable: %08x\n",
- I915_READ(IER));
- printf("Interrupt identity: %08x\n",
- I915_READ(IIR));
- printf("Interrupt mask: %08x\n",
- I915_READ(IMR));
- for_each_pipe(pipe)
- printf("Pipe %c stat: %08x\n",
- pipe_name(pipe),
- I915_READ(PIPESTAT(pipe)));
- } else {
- printf("North Display Interrupt enable: %08x\n",
- I915_READ(DEIER));
- printf("North Display Interrupt identity: %08x\n",
- I915_READ(DEIIR));
- printf("North Display Interrupt mask: %08x\n",
- I915_READ(DEIMR));
- printf("South Display Interrupt enable: %08x\n",
- I915_READ(SDEIER));
- printf("South Display Interrupt identity: %08x\n",
- I915_READ(SDEIIR));
- printf("South Display Interrupt mask: %08x\n",
- I915_READ(SDEIMR));
- printf("Graphics Interrupt enable: %08x\n",
- I915_READ(GTIER));
- printf("Graphics Interrupt identity: %08x\n",
- I915_READ(GTIIR));
- printf("Graphics Interrupt mask: %08x\n",
- I915_READ(GTIMR));
- }
-#if 0
- printf("Interrupts received: %d\n",
- atomic_read(&dev_priv->irq_received));
-#endif
- for_each_ring(ring, dev_priv, i) {
- if (IS_GEN6(dev) || IS_GEN7(dev)) {
- printf(
- "Graphics Interrupt mask (%s): %08x\n",
- ring->name, I915_READ_IMR(ring));
- }
- i915_ring_seqno_info(ring);
- }
-}
-
-void
-i915_gem_fence_regs_info(int kdev)
-{
- struct drm_device *dev = drm_get_device_from_kdev(kdev);
- struct inteldrm_softc *dev_priv = dev->dev_private;
- int i;
-
- printf("Reserved fences = %d\n", dev_priv->fence_reg_start);
- printf("Total fences = %d\n", dev_priv->num_fence_regs);
- for (i = 0; i < dev_priv->num_fence_regs; i++) {
- struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
-
- printf("Fence %d, pin count = %d, object = ",
- i, dev_priv->fence_regs[i].pin_count);
- if (obj == NULL)
- printf("unused");
- else
- describe_obj(obj);
- printf("\n");
- }
-}
-
-void
-i915_hws_info(int kdev)
-{
- struct drm_device *dev = drm_get_device_from_kdev(kdev);
- struct inteldrm_softc *dev_priv = dev->dev_private;
- struct intel_ring_buffer *ring = &dev_priv->rings[RCS];
- int i;
- volatile u32 *hws;
-
- hws = (volatile u32 *)ring->status_page.page_addr;
- if (hws == NULL)
- return;
-
- for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
- printf("0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
- i * 4,
- hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
- }
-}
-
-static void
-i915_dump_pages(bus_space_tag_t bst, bus_space_handle_t bsh,
- bus_size_t size)
-{
- bus_addr_t offset = 0;
- int i = 0;
-
- /*
- * this is a bit odd so i don't have to play with the intel
- * tools too much.
- */
- for (offset = 0; offset < size; offset += 4, i += 4) {
- if (i == PAGE_SIZE)
- i = 0;
- printf("%08x : %08x\n", i, bus_space_read_4(bst, bsh,
- offset));
- }
-}
-
-void
-i915_batchbuffer_info(int kdev)
-{
- struct drm_device *dev = drm_get_device_from_kdev(kdev);
- struct inteldrm_softc *dev_priv = dev->dev_private;
- struct drm_obj *obj;
- struct drm_i915_gem_object *obj_priv;
- bus_space_handle_t bsh;
- int ret;
-
- list_for_each_entry(obj_priv, &dev_priv->mm.active_list, mm_list) {
- obj = &obj_priv->base;
- if (obj->read_domains & I915_GEM_DOMAIN_COMMAND) {
- if ((ret = agp_map_subregion(dev_priv->agph,
- obj_priv->gtt_offset, obj->size, &bsh)) != 0) {
- DRM_ERROR("Failed to map pages: %d\n", ret);
- return;
- }
- printf("--- gtt_offset = 0x%08x\n",
- obj_priv->gtt_offset);
- i915_dump_pages(dev_priv->bst, bsh, obj->size);
- agp_unmap_subregion(dev_priv->agph,
- dev_priv->rings[RCS].bsh, obj->size);
- }
- }
-}
-
-void
-i915_ringbuffer_data(int kdev)
-{
- struct drm_device *dev = drm_get_device_from_kdev(kdev);
- struct inteldrm_softc *dev_priv = dev->dev_private;
- bus_size_t off;
-
- if (!dev_priv->rings[RCS].obj) {
- printf("No ringbuffer setup\n");
- return;
- }
-
- for (off = 0; off < dev_priv->rings[RCS].size; off += 4)
- printf("%08x : %08x\n", off, bus_space_read_4(dev_priv->bst,
- dev_priv->rings[RCS].bsh, off));
-}
-
-void
-i915_ringbuffer_info(int kdev)
-{
- struct drm_device *dev = drm_get_device_from_kdev(kdev);
- struct inteldrm_softc *dev_priv = dev->dev_private;
- u_int32_t head, tail;
-
- head = I915_READ(PRB0_HEAD) & HEAD_ADDR;
- tail = I915_READ(PRB0_TAIL) & TAIL_ADDR;
-
- printf("RingHead : %08x\n", head);
- printf("RingTail : %08x\n", tail);
- printf("RingMask : %08x\n", dev_priv->rings[RCS].size - 1);
- printf("RingSize : %08lx\n", dev_priv->rings[RCS].size);
- printf("Acthd : %08x\n", I915_READ(INTEL_INFO(dev)->gen >= 4 ?
- ACTHD_I965 : ACTHD));
-}
-
-#endif
-
static int
intel_pch_match(struct pci_attach_args *pa)
{