static ssize_t store_mem_state(struct sys_device *dev, struct sysdev_attribute *attr, const char *buf, size_t count) { struct memory_block *mem; int ret = -EINVAL; mem = container_of(dev, struct memory_block, sysdev); if (!strncmp(buf, "online", min((int)count, 6))) ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE); else if(!strncmp(buf, "offline", min((int)count, 7))) ret = memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); if (ret) return ret; return count; }
static int memory_subsys_offline(struct device *dev) { struct memory_block *mem = to_memory_block(dev); if (mem->state == MEM_OFFLINE) return 0; return memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); }
static int memory_subsys_offline(struct device *dev) { struct memory_block *mem = to_memory_block(dev); if (mem->state == MEM_OFFLINE) return 0; /* Can't offline block with non-present sections */ if (mem->section_count != sections_per_block) return -EINVAL; return memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); }
static ssize_t store_mem_state(struct sys_device *dev, const char *buf, size_t count) { struct memory_block *mem; unsigned int phys_section_nr; int ret = -EINVAL; mem = container_of(dev, struct memory_block, sysdev); phys_section_nr = mem->phys_index; if (!valid_section_nr(phys_section_nr)) goto out; if (!strncmp(buf, "online", min((int)count, 6))) ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE); else if(!strncmp(buf, "offline", min((int)count, 7))) ret = memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); out: if (ret) return ret; return count; }
/* The device lock serializes operations on memory_subsys_[online|offline] */ static int memory_subsys_online(struct device *dev) { struct memory_block *mem = to_memory_block(dev); int ret; if (mem->state == MEM_ONLINE) return 0; /* * If we are called from store_mem_state(), online_type will be * set >= 0 Otherwise we were called from the device online * attribute and need to set the online_type. */ if (mem->online_type < 0) mem->online_type = MMOP_ONLINE_KEEP; ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE); /* clear online_type */ mem->online_type = -1; return ret; }