]> Pileus Git - ~andy/linux/blobdiff - drivers/base/memory.c
OMAPDSS: DISPC: Add IRQ enable/status helpers
[~andy/linux] / drivers / base / memory.c
index 44e7de6ce69455999ef0c843ee91f9641b1173cd..86c88216a503197a84ef22004bf4949adec98d92 100644 (file)
@@ -275,13 +275,11 @@ memory_block_action(unsigned long phys_index, unsigned long action)
        return ret;
 }
 
-static int memory_block_change_state(struct memory_block *mem,
+static int __memory_block_change_state(struct memory_block *mem,
                unsigned long to_state, unsigned long from_state_req)
 {
        int ret = 0;
 
-       mutex_lock(&mem->state_mutex);
-
        if (mem->state != from_state_req) {
                ret = -EINVAL;
                goto out;
@@ -309,10 +307,20 @@ static int memory_block_change_state(struct memory_block *mem,
                break;
        }
 out:
-       mutex_unlock(&mem->state_mutex);
        return ret;
 }
 
+static int memory_block_change_state(struct memory_block *mem,
+               unsigned long to_state, unsigned long from_state_req)
+{
+       int ret;
+
+       mutex_lock(&mem->state_mutex);
+       ret = __memory_block_change_state(mem, to_state, from_state_req);
+       mutex_unlock(&mem->state_mutex);
+
+       return ret;
+}
 static ssize_t
 store_mem_state(struct device *dev,
                struct device_attribute *attr, const char *buf, size_t count)
@@ -652,6 +660,21 @@ int unregister_memory_section(struct mem_section *section)
        return remove_memory_block(0, section, 0);
 }
 
+/*
+ * offline one memory block. If the memory block has been offlined, do nothing.
+ */
+int offline_memory_block(struct memory_block *mem)
+{
+       int ret = 0;
+
+       mutex_lock(&mem->state_mutex);
+       if (mem->state != MEM_OFFLINE)
+               ret = __memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE);
+       mutex_unlock(&mem->state_mutex);
+
+       return ret;
+}
+
 /*
  * Initialize the sysfs support for memory devices...
  */