nfit.c (2002e90412df17ef7f714be62ed96a3c80b2f907) | nfit.c (67a3e8fe90156d41cd480d3dfbb40f3bc007c262) |
---|---|
1/* 2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of version 2 of the GNU General Public License as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, but --- 133 unchanged lines hidden (view full) --- 142 143static struct nfit_test *to_nfit_test(struct device *dev) 144{ 145 struct platform_device *pdev = to_platform_device(dev); 146 147 return container_of(pdev, struct nfit_test, pdev); 148} 149 | 1/* 2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of version 2 of the GNU General Public License as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, but --- 133 unchanged lines hidden (view full) --- 142 143static struct nfit_test *to_nfit_test(struct device *dev) 144{ 145 struct platform_device *pdev = to_platform_device(dev); 146 147 return container_of(pdev, struct nfit_test, pdev); 148} 149 |
150static int nfit_test_cmd_get_config_size(struct nd_cmd_get_config_size *nd_cmd, 151 unsigned int buf_len) 152{ 153 if (buf_len < sizeof(*nd_cmd)) 154 return -EINVAL; 155 156 nd_cmd->status = 0; 157 nd_cmd->config_size = LABEL_SIZE; 158 nd_cmd->max_xfer = SZ_4K; 159 160 return 0; 161} 162 163static int nfit_test_cmd_get_config_data(struct nd_cmd_get_config_data_hdr 164 *nd_cmd, unsigned int buf_len, void *label) 165{ 166 unsigned int len, offset = nd_cmd->in_offset; 167 int rc; 168 169 if (buf_len < sizeof(*nd_cmd)) 170 return -EINVAL; 171 if (offset >= LABEL_SIZE) 172 return -EINVAL; 173 if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len) 174 return -EINVAL; 175 176 nd_cmd->status = 0; 177 len = min(nd_cmd->in_length, LABEL_SIZE - offset); 178 memcpy(nd_cmd->out_buf, label + offset, len); 179 rc = buf_len - sizeof(*nd_cmd) - len; 180 181 return rc; 182} 183 184static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd, 185 unsigned int buf_len, void *label) 186{ 187 unsigned int len, offset = nd_cmd->in_offset; 188 u32 *status; 189 int rc; 190 191 if (buf_len < sizeof(*nd_cmd)) 192 return -EINVAL; 193 if (offset >= LABEL_SIZE) 194 return -EINVAL; 195 if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len) 196 return -EINVAL; 197 198 status = (void *)nd_cmd + nd_cmd->in_length + sizeof(*nd_cmd); 199 *status = 0; 200 len = min(nd_cmd->in_length, LABEL_SIZE - offset); 201 memcpy(label + offset, nd_cmd->in_buf, len); 202 rc = buf_len - sizeof(*nd_cmd) - (len + 4); 203 204 return rc; 205} 206 207static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd, 208 unsigned int buf_len) 209{ 210 if (buf_len < sizeof(*nd_cmd)) 211 return -EINVAL; 212 213 nd_cmd->max_ars_out = 256; 214 nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16; 215 216 return 0; 217} 218 219static int nfit_test_cmd_ars_start(struct nd_cmd_ars_start *nd_cmd, 220 unsigned int buf_len) 221{ 222 if (buf_len < sizeof(*nd_cmd)) 223 return -EINVAL; 224 225 nd_cmd->status = 0; 226 227 return 0; 228} 229 230static int nfit_test_cmd_ars_status(struct nd_cmd_ars_status *nd_cmd, 231 unsigned int buf_len) 232{ 233 if (buf_len < sizeof(*nd_cmd)) 234 return -EINVAL; 235 236 nd_cmd->out_length = 256; 237 nd_cmd->num_records = 0; 238 nd_cmd->status = 0; 239 240 return 0; 241} 242 |
|
150static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, 151 struct nvdimm *nvdimm, unsigned int cmd, void *buf, 152 unsigned int buf_len) 153{ 154 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); 155 struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc); | 243static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc, 244 struct nvdimm *nvdimm, unsigned int cmd, void *buf, 245 unsigned int buf_len) 246{ 247 struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc); 248 struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc); |
156 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); 157 int i, rc; | 249 int i, rc = 0; |
158 | 250 |
159 if (!nfit_mem || !test_bit(cmd, &nfit_mem->dsm_mask)) 160 return -ENOTTY; | 251 if (nvdimm) { 252 struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm); |
161 | 253 |
162 /* lookup label space for the given dimm */ 163 for (i = 0; i < ARRAY_SIZE(handle); i++) 164 if (__to_nfit_memdev(nfit_mem)->device_handle == handle[i]) 165 break; 166 if (i >= ARRAY_SIZE(handle)) 167 return -ENXIO; | 254 if (!nfit_mem || !test_bit(cmd, &nfit_mem->dsm_mask)) 255 return -ENOTTY; |
168 | 256 |
169 switch (cmd) { 170 case ND_CMD_GET_CONFIG_SIZE: { 171 struct nd_cmd_get_config_size *nd_cmd = buf; | 257 /* lookup label space for the given dimm */ 258 for (i = 0; i < ARRAY_SIZE(handle); i++) 259 if (__to_nfit_memdev(nfit_mem)->device_handle == 260 handle[i]) 261 break; 262 if (i >= ARRAY_SIZE(handle)) 263 return -ENXIO; |
172 | 264 |
173 if (buf_len < sizeof(*nd_cmd)) 174 return -EINVAL; 175 nd_cmd->status = 0; 176 nd_cmd->config_size = LABEL_SIZE; 177 nd_cmd->max_xfer = SZ_4K; 178 rc = 0; 179 break; 180 } 181 case ND_CMD_GET_CONFIG_DATA: { 182 struct nd_cmd_get_config_data_hdr *nd_cmd = buf; 183 unsigned int len, offset = nd_cmd->in_offset; | 265 switch (cmd) { 266 case ND_CMD_GET_CONFIG_SIZE: 267 rc = nfit_test_cmd_get_config_size(buf, buf_len); 268 break; 269 case ND_CMD_GET_CONFIG_DATA: 270 rc = nfit_test_cmd_get_config_data(buf, buf_len, 271 t->label[i]); 272 break; 273 case ND_CMD_SET_CONFIG_DATA: 274 rc = nfit_test_cmd_set_config_data(buf, buf_len, 275 t->label[i]); 276 break; 277 default: 278 return -ENOTTY; 279 } 280 } else { 281 if (!nd_desc || !test_bit(cmd, &nd_desc->dsm_mask)) 282 return -ENOTTY; |
184 | 283 |
185 if (buf_len < sizeof(*nd_cmd)) 186 return -EINVAL; 187 if (offset >= LABEL_SIZE) 188 return -EINVAL; 189 if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len) 190 return -EINVAL; 191 192 nd_cmd->status = 0; 193 len = min(nd_cmd->in_length, LABEL_SIZE - offset); 194 memcpy(nd_cmd->out_buf, t->label[i] + offset, len); 195 rc = buf_len - sizeof(*nd_cmd) - len; 196 break; | 284 switch (cmd) { 285 case ND_CMD_ARS_CAP: 286 rc = nfit_test_cmd_ars_cap(buf, buf_len); 287 break; 288 case ND_CMD_ARS_START: 289 rc = nfit_test_cmd_ars_start(buf, buf_len); 290 break; 291 case ND_CMD_ARS_STATUS: 292 rc = nfit_test_cmd_ars_status(buf, buf_len); 293 break; 294 default: 295 return -ENOTTY; 296 } |
197 } | 297 } |
198 case ND_CMD_SET_CONFIG_DATA: { 199 struct nd_cmd_set_config_hdr *nd_cmd = buf; 200 unsigned int len, offset = nd_cmd->in_offset; 201 u32 *status; | |
202 | 298 |
203 if (buf_len < sizeof(*nd_cmd)) 204 return -EINVAL; 205 if (offset >= LABEL_SIZE) 206 return -EINVAL; 207 if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len) 208 return -EINVAL; 209 210 status = buf + nd_cmd->in_length + sizeof(*nd_cmd); 211 *status = 0; 212 len = min(nd_cmd->in_length, LABEL_SIZE - offset); 213 memcpy(t->label[i] + offset, nd_cmd->in_buf, len); 214 rc = buf_len - sizeof(*nd_cmd) - (len + 4); 215 break; 216 } 217 default: 218 return -ENOTTY; 219 } 220 | |
221 return rc; 222} 223 224static DEFINE_SPINLOCK(nfit_test_lock); 225static struct nfit_test *instances[NUM_NFITS]; 226 227static void release_nfit_res(void *data) 228{ --- 642 unchanged lines hidden (view full) --- 871 flush->device_handle = handle[3]; 872 flush->hint_count = 1; 873 flush->hint_address[0] = t->flush_dma[3]; 874 875 acpi_desc = &t->acpi_desc; 876 set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_dsm_force_en); 877 set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_dsm_force_en); 878 set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_dsm_force_en); | 299 return rc; 300} 301 302static DEFINE_SPINLOCK(nfit_test_lock); 303static struct nfit_test *instances[NUM_NFITS]; 304 305static void release_nfit_res(void *data) 306{ --- 642 unchanged lines hidden (view full) --- 949 flush->device_handle = handle[3]; 950 flush->hint_count = 1; 951 flush->hint_address[0] = t->flush_dma[3]; 952 953 acpi_desc = &t->acpi_desc; 954 set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_dsm_force_en); 955 set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_dsm_force_en); 956 set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_dsm_force_en); |
957 set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_dsm_force_en); 958 set_bit(ND_CMD_ARS_START, &acpi_desc->bus_dsm_force_en); 959 set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_dsm_force_en); |
|
879 nd_desc = &acpi_desc->nd_desc; 880 nd_desc->ndctl = nfit_test_ctl; 881} 882 883static void nfit_test1_setup(struct nfit_test *t) 884{ 885 size_t size = t->nfit_size, offset; 886 void *nfit_buf = t->nfit_buf; --- 56 unchanged lines hidden (view full) --- 943{ 944 struct nfit_blk *nfit_blk = ndbr->blk_provider_data; 945 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; 946 struct nd_region *nd_region = &ndbr->nd_region; 947 unsigned int lane; 948 949 lane = nd_region_acquire_lane(nd_region); 950 if (rw) | 960 nd_desc = &acpi_desc->nd_desc; 961 nd_desc->ndctl = nfit_test_ctl; 962} 963 964static void nfit_test1_setup(struct nfit_test *t) 965{ 966 size_t size = t->nfit_size, offset; 967 void *nfit_buf = t->nfit_buf; --- 56 unchanged lines hidden (view full) --- 1024{ 1025 struct nfit_blk *nfit_blk = ndbr->blk_provider_data; 1026 struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW]; 1027 struct nd_region *nd_region = &ndbr->nd_region; 1028 unsigned int lane; 1029 1030 lane = nd_region_acquire_lane(nd_region); 1031 if (rw) |
951 memcpy(mmio->base + dpa, iobuf, len); 952 else 953 memcpy(iobuf, mmio->base + dpa, len); | 1032 memcpy(mmio->addr.base + dpa, iobuf, len); 1033 else { 1034 memcpy(iobuf, mmio->addr.base + dpa, len); 1035 1036 /* give us some some coverage of the mmio_flush_range() API */ 1037 mmio_flush_range(mmio->addr.base + dpa, len); 1038 } |
954 nd_region_release_lane(nd_region, lane); 955 956 return 0; 957} 958 959static int nfit_test_probe(struct platform_device *pdev) 960{ 961 struct nvdimm_bus_descriptor *nd_desc; --- 201 unchanged lines hidden --- | 1039 nd_region_release_lane(nd_region, lane); 1040 1041 return 0; 1042} 1043 1044static int nfit_test_probe(struct platform_device *pdev) 1045{ 1046 struct nvdimm_bus_descriptor *nd_desc; --- 201 unchanged lines hidden --- |