Debugfs i915_gem_object is extended to enable the IGTs to
detect the LMEM's availability and the total size of LMEM.
v2: READ_ONCE is used [Chris]
v3: %pa is used for printing the resource [Chris]
v4: All regions' details added to debugfs [Chris]
v5: Macro for_each_mem_region added
    name is initialized at region init [Chris]
Signed-off-by: Lukasz Fiedorowicz <lukasz.fiedorowicz@intel.com>
Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Stuart Summers <stuart.summers@intel.com>
Signed-off-by: Ramalingam C <ramalingam.c@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20191227133748.4330-1-ramalingam.c@intel.com
 
                         err);
        }
 
+       intel_memory_region_set_name(mem, "system");
+
        return 0; /* Don't error, we can simply fallback to the kernel mnt */
 }
 
 
 
 static int init_stolen(struct intel_memory_region *mem)
 {
+       intel_memory_region_set_name(mem, "stolen");
+
        /*
         * Initialise stolen early so that we may reserve preallocated
         * objects for the BIOS to KMS transition.
 
 static int i915_gem_object_info(struct seq_file *m, void *data)
 {
        struct drm_i915_private *i915 = node_to_i915(m->private);
+       struct intel_memory_region *mr;
+       enum intel_region_id id;
 
        seq_printf(m, "%u shrinkable [%u free] objects, %llu bytes\n",
                   i915->mm.shrink_count,
                   atomic_read(&i915->mm.free_count),
                   i915->mm.shrink_memory);
-
+       for_each_memory_region(mr, i915, id)
+               seq_printf(m, "%s: total:%pa, available:%pa bytes\n",
+                          mr->name, &mr->total, &mr->avail);
        seq_putc(m, '\n');
 
        print_context_stats(m, i915);
 
                                      struct list_head *blocks)
 {
        mutex_lock(&mem->mm_lock);
-       intel_memory_region_free_pages(mem, blocks);
+       mem->avail += intel_memory_region_free_pages(mem, blocks);
        mutex_unlock(&mem->mm_lock);
 }
 
                        break;
        } while (1);
 
+       mem->avail -= size;
        mutex_unlock(&mem->mm_lock);
        return 0;
 
        mem->io_start = io_start;
        mem->min_page_size = min_page_size;
        mem->ops = ops;
+       mem->total = size;
+       mem->avail = mem->total;
 
        mutex_init(&mem->objects.lock);
        INIT_LIST_HEAD(&mem->objects.list);
        return ERR_PTR(err);
 }
 
+void intel_memory_region_set_name(struct intel_memory_region *mem,
+                                 const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       vsnprintf(mem->name, sizeof(mem->name), fmt, ap);
+       va_end(ap);
+}
+
 static void __intel_memory_region_destroy(struct kref *kref)
 {
        struct intel_memory_region *mem =
 
 #define I915_ALLOC_MIN_PAGE_SIZE  BIT(0)
 #define I915_ALLOC_CONTIGUOUS     BIT(1)
 
+#define for_each_memory_region(mr, i915, id) \
+       for (id = 0; id < ARRAY_SIZE((i915)->mm.regions); id++) \
+               for_each_if((mr) = (i915)->mm.regions[id])
+
 /**
  * Memory regions encoded as type | instance
  */
 
        resource_size_t io_start;
        resource_size_t min_page_size;
+       resource_size_t total;
+       resource_size_t avail;
 
        unsigned int type;
        unsigned int instance;
        unsigned int id;
+       char name[8];
 
        dma_addr_t remap_addr;
 
 int intel_memory_regions_hw_probe(struct drm_i915_private *i915);
 void intel_memory_regions_driver_release(struct drm_i915_private *i915);
 
+__printf(2, 3) void
+intel_memory_region_set_name(struct intel_memory_region *mem,
+                            const char *fmt, ...);
+
 #endif
 
        if (ret)
                io_mapping_fini(&mem->iomap);
 
+       intel_memory_region_set_name(mem, "local");
+
        return ret;
 }