nfit.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591
  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
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. */
  13. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  14. #include <linux/platform_device.h>
  15. #include <linux/dma-mapping.h>
  16. #include <linux/workqueue.h>
  17. #include <linux/libnvdimm.h>
  18. #include <linux/vmalloc.h>
  19. #include <linux/device.h>
  20. #include <linux/module.h>
  21. #include <linux/mutex.h>
  22. #include <linux/ndctl.h>
  23. #include <linux/sizes.h>
  24. #include <linux/list.h>
  25. #include <linux/slab.h>
  26. #include <nfit.h>
  27. #include <nd.h>
  28. #include "nfit_test.h"
  29. /*
  30. * Generate an NFIT table to describe the following topology:
  31. *
  32. * BUS0: Interleaved PMEM regions, and aliasing with BLK regions
  33. *
  34. * (a) (b) DIMM BLK-REGION
  35. * +----------+--------------+----------+---------+
  36. * +------+ | blk2.0 | pm0.0 | blk2.1 | pm1.0 | 0 region2
  37. * | imc0 +--+- - - - - region0 - - - -+----------+ +
  38. * +--+---+ | blk3.0 | pm0.0 | blk3.1 | pm1.0 | 1 region3
  39. * | +----------+--------------v----------v v
  40. * +--+---+ | |
  41. * | cpu0 | region1
  42. * +--+---+ | |
  43. * | +-------------------------^----------^ ^
  44. * +--+---+ | blk4.0 | pm1.0 | 2 region4
  45. * | imc1 +--+-------------------------+----------+ +
  46. * +------+ | blk5.0 | pm1.0 | 3 region5
  47. * +-------------------------+----------+-+-------+
  48. *
  49. * +--+---+
  50. * | cpu1 |
  51. * +--+---+ (Hotplug DIMM)
  52. * | +----------------------------------------------+
  53. * +--+---+ | blk6.0/pm7.0 | 4 region6/7
  54. * | imc0 +--+----------------------------------------------+
  55. * +------+
  56. *
  57. *
  58. * *) In this layout we have four dimms and two memory controllers in one
  59. * socket. Each unique interface (BLK or PMEM) to DPA space
  60. * is identified by a region device with a dynamically assigned id.
  61. *
  62. * *) The first portion of dimm0 and dimm1 are interleaved as REGION0.
  63. * A single PMEM namespace "pm0.0" is created using half of the
  64. * REGION0 SPA-range. REGION0 spans dimm0 and dimm1. PMEM namespace
  65. * allocate from from the bottom of a region. The unallocated
  66. * portion of REGION0 aliases with REGION2 and REGION3. That
  67. * unallacted capacity is reclaimed as BLK namespaces ("blk2.0" and
  68. * "blk3.0") starting at the base of each DIMM to offset (a) in those
  69. * DIMMs. "pm0.0", "blk2.0" and "blk3.0" are free-form readable
  70. * names that can be assigned to a namespace.
  71. *
  72. * *) In the last portion of dimm0 and dimm1 we have an interleaved
  73. * SPA range, REGION1, that spans those two dimms as well as dimm2
  74. * and dimm3. Some of REGION1 allocated to a PMEM namespace named
  75. * "pm1.0" the rest is reclaimed in 4 BLK namespaces (for each
  76. * dimm in the interleave set), "blk2.1", "blk3.1", "blk4.0", and
  77. * "blk5.0".
  78. *
  79. * *) The portion of dimm2 and dimm3 that do not participate in the
  80. * REGION1 interleaved SPA range (i.e. the DPA address below offset
  81. * (b) are also included in the "blk4.0" and "blk5.0" namespaces.
  82. * Note, that BLK namespaces need not be contiguous in DPA-space, and
  83. * can consume aliased capacity from multiple interleave sets.
  84. *
  85. * BUS1: Legacy NVDIMM (single contiguous range)
  86. *
  87. * region2
  88. * +---------------------+
  89. * |---------------------|
  90. * || pm2.0 ||
  91. * |---------------------|
  92. * +---------------------+
  93. *
  94. * *) A NFIT-table may describe a simple system-physical-address range
  95. * with no BLK aliasing. This type of region may optionally
  96. * reference an NVDIMM.
  97. */
  98. enum {
  99. NUM_PM = 3,
  100. NUM_DCR = 5,
  101. NUM_HINTS = 8,
  102. NUM_BDW = NUM_DCR,
  103. NUM_SPA = NUM_PM + NUM_DCR + NUM_BDW,
  104. NUM_MEM = NUM_DCR + NUM_BDW + 2 /* spa0 iset */ + 4 /* spa1 iset */,
  105. DIMM_SIZE = SZ_32M,
  106. LABEL_SIZE = SZ_128K,
  107. SPA_VCD_SIZE = SZ_4M,
  108. SPA0_SIZE = DIMM_SIZE,
  109. SPA1_SIZE = DIMM_SIZE*2,
  110. SPA2_SIZE = DIMM_SIZE,
  111. BDW_SIZE = 64 << 8,
  112. DCR_SIZE = 12,
  113. NUM_NFITS = 2, /* permit testing multiple NFITs per system */
  114. };
  115. struct nfit_test_dcr {
  116. __le64 bdw_addr;
  117. __le32 bdw_status;
  118. __u8 aperature[BDW_SIZE];
  119. };
  120. #define NFIT_DIMM_HANDLE(node, socket, imc, chan, dimm) \
  121. (((node & 0xfff) << 16) | ((socket & 0xf) << 12) \
  122. | ((imc & 0xf) << 8) | ((chan & 0xf) << 4) | (dimm & 0xf))
  123. static u32 handle[NUM_DCR] = {
  124. [0] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 0),
  125. [1] = NFIT_DIMM_HANDLE(0, 0, 0, 0, 1),
  126. [2] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 0),
  127. [3] = NFIT_DIMM_HANDLE(0, 0, 1, 0, 1),
  128. [4] = NFIT_DIMM_HANDLE(0, 1, 0, 0, 0),
  129. };
  130. struct nfit_test {
  131. struct acpi_nfit_desc acpi_desc;
  132. struct platform_device pdev;
  133. struct list_head resources;
  134. void *nfit_buf;
  135. dma_addr_t nfit_dma;
  136. size_t nfit_size;
  137. int num_dcr;
  138. int num_pm;
  139. void **dimm;
  140. dma_addr_t *dimm_dma;
  141. void **flush;
  142. dma_addr_t *flush_dma;
  143. void **label;
  144. dma_addr_t *label_dma;
  145. void **spa_set;
  146. dma_addr_t *spa_set_dma;
  147. struct nfit_test_dcr **dcr;
  148. dma_addr_t *dcr_dma;
  149. int (*alloc)(struct nfit_test *t);
  150. void (*setup)(struct nfit_test *t);
  151. int setup_hotplug;
  152. struct ars_state {
  153. struct nd_cmd_ars_status *ars_status;
  154. unsigned long deadline;
  155. spinlock_t lock;
  156. } ars_state;
  157. };
  158. static struct nfit_test *to_nfit_test(struct device *dev)
  159. {
  160. struct platform_device *pdev = to_platform_device(dev);
  161. return container_of(pdev, struct nfit_test, pdev);
  162. }
  163. static int nfit_test_cmd_get_config_size(struct nd_cmd_get_config_size *nd_cmd,
  164. unsigned int buf_len)
  165. {
  166. if (buf_len < sizeof(*nd_cmd))
  167. return -EINVAL;
  168. nd_cmd->status = 0;
  169. nd_cmd->config_size = LABEL_SIZE;
  170. nd_cmd->max_xfer = SZ_4K;
  171. return 0;
  172. }
  173. static int nfit_test_cmd_get_config_data(struct nd_cmd_get_config_data_hdr
  174. *nd_cmd, unsigned int buf_len, void *label)
  175. {
  176. unsigned int len, offset = nd_cmd->in_offset;
  177. int rc;
  178. if (buf_len < sizeof(*nd_cmd))
  179. return -EINVAL;
  180. if (offset >= LABEL_SIZE)
  181. return -EINVAL;
  182. if (nd_cmd->in_length + sizeof(*nd_cmd) > buf_len)
  183. return -EINVAL;
  184. nd_cmd->status = 0;
  185. len = min(nd_cmd->in_length, LABEL_SIZE - offset);
  186. memcpy(nd_cmd->out_buf, label + offset, len);
  187. rc = buf_len - sizeof(*nd_cmd) - len;
  188. return rc;
  189. }
  190. static int nfit_test_cmd_set_config_data(struct nd_cmd_set_config_hdr *nd_cmd,
  191. unsigned int buf_len, void *label)
  192. {
  193. unsigned int len, offset = nd_cmd->in_offset;
  194. u32 *status;
  195. int rc;
  196. if (buf_len < sizeof(*nd_cmd))
  197. return -EINVAL;
  198. if (offset >= LABEL_SIZE)
  199. return -EINVAL;
  200. if (nd_cmd->in_length + sizeof(*nd_cmd) + 4 > buf_len)
  201. return -EINVAL;
  202. status = (void *)nd_cmd + nd_cmd->in_length + sizeof(*nd_cmd);
  203. *status = 0;
  204. len = min(nd_cmd->in_length, LABEL_SIZE - offset);
  205. memcpy(label + offset, nd_cmd->in_buf, len);
  206. rc = buf_len - sizeof(*nd_cmd) - (len + 4);
  207. return rc;
  208. }
  209. #define NFIT_TEST_ARS_RECORDS 4
  210. #define NFIT_TEST_CLEAR_ERR_UNIT 256
  211. static int nfit_test_cmd_ars_cap(struct nd_cmd_ars_cap *nd_cmd,
  212. unsigned int buf_len)
  213. {
  214. if (buf_len < sizeof(*nd_cmd))
  215. return -EINVAL;
  216. nd_cmd->max_ars_out = sizeof(struct nd_cmd_ars_status)
  217. + NFIT_TEST_ARS_RECORDS * sizeof(struct nd_ars_record);
  218. nd_cmd->status = (ND_ARS_PERSISTENT | ND_ARS_VOLATILE) << 16;
  219. nd_cmd->clear_err_unit = NFIT_TEST_CLEAR_ERR_UNIT;
  220. return 0;
  221. }
  222. /*
  223. * Initialize the ars_state to return an ars_result 1 second in the future with
  224. * a 4K error range in the middle of the requested address range.
  225. */
  226. static void post_ars_status(struct ars_state *ars_state, u64 addr, u64 len)
  227. {
  228. struct nd_cmd_ars_status *ars_status;
  229. struct nd_ars_record *ars_record;
  230. ars_state->deadline = jiffies + 1*HZ;
  231. ars_status = ars_state->ars_status;
  232. ars_status->status = 0;
  233. ars_status->out_length = sizeof(struct nd_cmd_ars_status)
  234. + sizeof(struct nd_ars_record);
  235. ars_status->address = addr;
  236. ars_status->length = len;
  237. ars_status->type = ND_ARS_PERSISTENT;
  238. ars_status->num_records = 1;
  239. ars_record = &ars_status->records[0];
  240. ars_record->handle = 0;
  241. ars_record->err_address = addr + len / 2;
  242. ars_record->length = SZ_4K;
  243. }
  244. static int nfit_test_cmd_ars_start(struct ars_state *ars_state,
  245. struct nd_cmd_ars_start *ars_start, unsigned int buf_len,
  246. int *cmd_rc)
  247. {
  248. if (buf_len < sizeof(*ars_start))
  249. return -EINVAL;
  250. spin_lock(&ars_state->lock);
  251. if (time_before(jiffies, ars_state->deadline)) {
  252. ars_start->status = NFIT_ARS_START_BUSY;
  253. *cmd_rc = -EBUSY;
  254. } else {
  255. ars_start->status = 0;
  256. ars_start->scrub_time = 1;
  257. post_ars_status(ars_state, ars_start->address,
  258. ars_start->length);
  259. *cmd_rc = 0;
  260. }
  261. spin_unlock(&ars_state->lock);
  262. return 0;
  263. }
  264. static int nfit_test_cmd_ars_status(struct ars_state *ars_state,
  265. struct nd_cmd_ars_status *ars_status, unsigned int buf_len,
  266. int *cmd_rc)
  267. {
  268. if (buf_len < ars_state->ars_status->out_length)
  269. return -EINVAL;
  270. spin_lock(&ars_state->lock);
  271. if (time_before(jiffies, ars_state->deadline)) {
  272. memset(ars_status, 0, buf_len);
  273. ars_status->status = NFIT_ARS_STATUS_BUSY;
  274. ars_status->out_length = sizeof(*ars_status);
  275. *cmd_rc = -EBUSY;
  276. } else {
  277. memcpy(ars_status, ars_state->ars_status,
  278. ars_state->ars_status->out_length);
  279. *cmd_rc = 0;
  280. }
  281. spin_unlock(&ars_state->lock);
  282. return 0;
  283. }
  284. static int nfit_test_cmd_clear_error(struct nd_cmd_clear_error *clear_err,
  285. unsigned int buf_len, int *cmd_rc)
  286. {
  287. const u64 mask = NFIT_TEST_CLEAR_ERR_UNIT - 1;
  288. if (buf_len < sizeof(*clear_err))
  289. return -EINVAL;
  290. if ((clear_err->address & mask) || (clear_err->length & mask))
  291. return -EINVAL;
  292. /*
  293. * Report 'all clear' success for all commands even though a new
  294. * scrub will find errors again. This is enough to have the
  295. * error removed from the 'badblocks' tracking in the pmem
  296. * driver.
  297. */
  298. clear_err->status = 0;
  299. clear_err->cleared = clear_err->length;
  300. *cmd_rc = 0;
  301. return 0;
  302. }
  303. static int nfit_test_cmd_smart(struct nd_cmd_smart *smart, unsigned int buf_len)
  304. {
  305. static const struct nd_smart_payload smart_data = {
  306. .flags = ND_SMART_HEALTH_VALID | ND_SMART_TEMP_VALID
  307. | ND_SMART_SPARES_VALID | ND_SMART_ALARM_VALID
  308. | ND_SMART_USED_VALID | ND_SMART_SHUTDOWN_VALID,
  309. .health = ND_SMART_NON_CRITICAL_HEALTH,
  310. .temperature = 23 * 16,
  311. .spares = 75,
  312. .alarm_flags = ND_SMART_SPARE_TRIP | ND_SMART_TEMP_TRIP,
  313. .life_used = 5,
  314. .shutdown_state = 0,
  315. .vendor_size = 0,
  316. };
  317. if (buf_len < sizeof(*smart))
  318. return -EINVAL;
  319. memcpy(smart->data, &smart_data, sizeof(smart_data));
  320. return 0;
  321. }
  322. static int nfit_test_cmd_smart_threshold(struct nd_cmd_smart_threshold *smart_t,
  323. unsigned int buf_len)
  324. {
  325. static const struct nd_smart_threshold_payload smart_t_data = {
  326. .alarm_control = ND_SMART_SPARE_TRIP | ND_SMART_TEMP_TRIP,
  327. .temperature = 40 * 16,
  328. .spares = 5,
  329. };
  330. if (buf_len < sizeof(*smart_t))
  331. return -EINVAL;
  332. memcpy(smart_t->data, &smart_t_data, sizeof(smart_t_data));
  333. return 0;
  334. }
  335. static int nfit_test_ctl(struct nvdimm_bus_descriptor *nd_desc,
  336. struct nvdimm *nvdimm, unsigned int cmd, void *buf,
  337. unsigned int buf_len, int *cmd_rc)
  338. {
  339. struct acpi_nfit_desc *acpi_desc = to_acpi_desc(nd_desc);
  340. struct nfit_test *t = container_of(acpi_desc, typeof(*t), acpi_desc);
  341. unsigned int func = cmd;
  342. int i, rc = 0, __cmd_rc;
  343. if (!cmd_rc)
  344. cmd_rc = &__cmd_rc;
  345. *cmd_rc = 0;
  346. if (nvdimm) {
  347. struct nfit_mem *nfit_mem = nvdimm_provider_data(nvdimm);
  348. unsigned long cmd_mask = nvdimm_cmd_mask(nvdimm);
  349. if (!nfit_mem)
  350. return -ENOTTY;
  351. if (cmd == ND_CMD_CALL) {
  352. struct nd_cmd_pkg *call_pkg = buf;
  353. buf_len = call_pkg->nd_size_in + call_pkg->nd_size_out;
  354. buf = (void *) call_pkg->nd_payload;
  355. func = call_pkg->nd_command;
  356. if (call_pkg->nd_family != nfit_mem->family)
  357. return -ENOTTY;
  358. }
  359. if (!test_bit(cmd, &cmd_mask)
  360. || !test_bit(func, &nfit_mem->dsm_mask))
  361. return -ENOTTY;
  362. /* lookup label space for the given dimm */
  363. for (i = 0; i < ARRAY_SIZE(handle); i++)
  364. if (__to_nfit_memdev(nfit_mem)->device_handle ==
  365. handle[i])
  366. break;
  367. if (i >= ARRAY_SIZE(handle))
  368. return -ENXIO;
  369. switch (func) {
  370. case ND_CMD_GET_CONFIG_SIZE:
  371. rc = nfit_test_cmd_get_config_size(buf, buf_len);
  372. break;
  373. case ND_CMD_GET_CONFIG_DATA:
  374. rc = nfit_test_cmd_get_config_data(buf, buf_len,
  375. t->label[i]);
  376. break;
  377. case ND_CMD_SET_CONFIG_DATA:
  378. rc = nfit_test_cmd_set_config_data(buf, buf_len,
  379. t->label[i]);
  380. break;
  381. case ND_CMD_SMART:
  382. rc = nfit_test_cmd_smart(buf, buf_len);
  383. break;
  384. case ND_CMD_SMART_THRESHOLD:
  385. rc = nfit_test_cmd_smart_threshold(buf, buf_len);
  386. break;
  387. default:
  388. return -ENOTTY;
  389. }
  390. } else {
  391. struct ars_state *ars_state = &t->ars_state;
  392. if (!nd_desc || !test_bit(cmd, &nd_desc->cmd_mask))
  393. return -ENOTTY;
  394. switch (func) {
  395. case ND_CMD_ARS_CAP:
  396. rc = nfit_test_cmd_ars_cap(buf, buf_len);
  397. break;
  398. case ND_CMD_ARS_START:
  399. rc = nfit_test_cmd_ars_start(ars_state, buf, buf_len,
  400. cmd_rc);
  401. break;
  402. case ND_CMD_ARS_STATUS:
  403. rc = nfit_test_cmd_ars_status(ars_state, buf, buf_len,
  404. cmd_rc);
  405. break;
  406. case ND_CMD_CLEAR_ERROR:
  407. rc = nfit_test_cmd_clear_error(buf, buf_len, cmd_rc);
  408. break;
  409. default:
  410. return -ENOTTY;
  411. }
  412. }
  413. return rc;
  414. }
  415. static DEFINE_SPINLOCK(nfit_test_lock);
  416. static struct nfit_test *instances[NUM_NFITS];
  417. static void release_nfit_res(void *data)
  418. {
  419. struct nfit_test_resource *nfit_res = data;
  420. struct resource *res = nfit_res->res;
  421. spin_lock(&nfit_test_lock);
  422. list_del(&nfit_res->list);
  423. spin_unlock(&nfit_test_lock);
  424. vfree(nfit_res->buf);
  425. kfree(res);
  426. kfree(nfit_res);
  427. }
  428. static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma,
  429. void *buf)
  430. {
  431. struct device *dev = &t->pdev.dev;
  432. struct resource *res = kzalloc(sizeof(*res) * 2, GFP_KERNEL);
  433. struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res),
  434. GFP_KERNEL);
  435. int rc;
  436. if (!res || !buf || !nfit_res)
  437. goto err;
  438. rc = devm_add_action(dev, release_nfit_res, nfit_res);
  439. if (rc)
  440. goto err;
  441. INIT_LIST_HEAD(&nfit_res->list);
  442. memset(buf, 0, size);
  443. nfit_res->dev = dev;
  444. nfit_res->buf = buf;
  445. nfit_res->res = res;
  446. res->start = *dma;
  447. res->end = *dma + size - 1;
  448. res->name = "NFIT";
  449. spin_lock(&nfit_test_lock);
  450. list_add(&nfit_res->list, &t->resources);
  451. spin_unlock(&nfit_test_lock);
  452. return nfit_res->buf;
  453. err:
  454. if (buf)
  455. vfree(buf);
  456. kfree(res);
  457. kfree(nfit_res);
  458. return NULL;
  459. }
  460. static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma)
  461. {
  462. void *buf = vmalloc(size);
  463. *dma = (unsigned long) buf;
  464. return __test_alloc(t, size, dma, buf);
  465. }
  466. static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr)
  467. {
  468. int i;
  469. for (i = 0; i < ARRAY_SIZE(instances); i++) {
  470. struct nfit_test_resource *n, *nfit_res = NULL;
  471. struct nfit_test *t = instances[i];
  472. if (!t)
  473. continue;
  474. spin_lock(&nfit_test_lock);
  475. list_for_each_entry(n, &t->resources, list) {
  476. if (addr >= n->res->start && (addr < n->res->start
  477. + resource_size(n->res))) {
  478. nfit_res = n;
  479. break;
  480. } else if (addr >= (unsigned long) n->buf
  481. && (addr < (unsigned long) n->buf
  482. + resource_size(n->res))) {
  483. nfit_res = n;
  484. break;
  485. }
  486. }
  487. spin_unlock(&nfit_test_lock);
  488. if (nfit_res)
  489. return nfit_res;
  490. }
  491. return NULL;
  492. }
  493. static int ars_state_init(struct device *dev, struct ars_state *ars_state)
  494. {
  495. ars_state->ars_status = devm_kzalloc(dev,
  496. sizeof(struct nd_cmd_ars_status)
  497. + sizeof(struct nd_ars_record) * NFIT_TEST_ARS_RECORDS,
  498. GFP_KERNEL);
  499. if (!ars_state->ars_status)
  500. return -ENOMEM;
  501. spin_lock_init(&ars_state->lock);
  502. return 0;
  503. }
  504. static int nfit_test0_alloc(struct nfit_test *t)
  505. {
  506. size_t nfit_size = sizeof(struct acpi_nfit_system_address) * NUM_SPA
  507. + sizeof(struct acpi_nfit_memory_map) * NUM_MEM
  508. + sizeof(struct acpi_nfit_control_region) * NUM_DCR
  509. + offsetof(struct acpi_nfit_control_region,
  510. window_size) * NUM_DCR
  511. + sizeof(struct acpi_nfit_data_region) * NUM_BDW
  512. + (sizeof(struct acpi_nfit_flush_address)
  513. + sizeof(u64) * NUM_HINTS) * NUM_DCR;
  514. int i;
  515. t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma);
  516. if (!t->nfit_buf)
  517. return -ENOMEM;
  518. t->nfit_size = nfit_size;
  519. t->spa_set[0] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[0]);
  520. if (!t->spa_set[0])
  521. return -ENOMEM;
  522. t->spa_set[1] = test_alloc(t, SPA1_SIZE, &t->spa_set_dma[1]);
  523. if (!t->spa_set[1])
  524. return -ENOMEM;
  525. t->spa_set[2] = test_alloc(t, SPA0_SIZE, &t->spa_set_dma[2]);
  526. if (!t->spa_set[2])
  527. return -ENOMEM;
  528. for (i = 0; i < NUM_DCR; i++) {
  529. t->dimm[i] = test_alloc(t, DIMM_SIZE, &t->dimm_dma[i]);
  530. if (!t->dimm[i])
  531. return -ENOMEM;
  532. t->label[i] = test_alloc(t, LABEL_SIZE, &t->label_dma[i]);
  533. if (!t->label[i])
  534. return -ENOMEM;
  535. sprintf(t->label[i], "label%d", i);
  536. t->flush[i] = test_alloc(t, sizeof(u64) * NUM_HINTS,
  537. &t->flush_dma[i]);
  538. if (!t->flush[i])
  539. return -ENOMEM;
  540. }
  541. for (i = 0; i < NUM_DCR; i++) {
  542. t->dcr[i] = test_alloc(t, LABEL_SIZE, &t->dcr_dma[i]);
  543. if (!t->dcr[i])
  544. return -ENOMEM;
  545. }
  546. return ars_state_init(&t->pdev.dev, &t->ars_state);
  547. }
  548. static int nfit_test1_alloc(struct nfit_test *t)
  549. {
  550. size_t nfit_size = sizeof(struct acpi_nfit_system_address) * 2
  551. + sizeof(struct acpi_nfit_memory_map)
  552. + offsetof(struct acpi_nfit_control_region, window_size);
  553. t->nfit_buf = test_alloc(t, nfit_size, &t->nfit_dma);
  554. if (!t->nfit_buf)
  555. return -ENOMEM;
  556. t->nfit_size = nfit_size;
  557. t->spa_set[0] = test_alloc(t, SPA2_SIZE, &t->spa_set_dma[0]);
  558. if (!t->spa_set[0])
  559. return -ENOMEM;
  560. t->spa_set[1] = test_alloc(t, SPA_VCD_SIZE, &t->spa_set_dma[1]);
  561. if (!t->spa_set[1])
  562. return -ENOMEM;
  563. return ars_state_init(&t->pdev.dev, &t->ars_state);
  564. }
  565. static void dcr_common_init(struct acpi_nfit_control_region *dcr)
  566. {
  567. dcr->vendor_id = 0xabcd;
  568. dcr->device_id = 0;
  569. dcr->revision_id = 1;
  570. dcr->valid_fields = 1;
  571. dcr->manufacturing_location = 0xa;
  572. dcr->manufacturing_date = cpu_to_be16(2016);
  573. }
  574. static void nfit_test0_setup(struct nfit_test *t)
  575. {
  576. const int flush_hint_size = sizeof(struct acpi_nfit_flush_address)
  577. + (sizeof(u64) * NUM_HINTS);
  578. struct acpi_nfit_desc *acpi_desc;
  579. struct acpi_nfit_memory_map *memdev;
  580. void *nfit_buf = t->nfit_buf;
  581. struct acpi_nfit_system_address *spa;
  582. struct acpi_nfit_control_region *dcr;
  583. struct acpi_nfit_data_region *bdw;
  584. struct acpi_nfit_flush_address *flush;
  585. unsigned int offset, i;
  586. /*
  587. * spa0 (interleave first half of dimm0 and dimm1, note storage
  588. * does not actually alias the related block-data-window
  589. * regions)
  590. */
  591. spa = nfit_buf;
  592. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  593. spa->header.length = sizeof(*spa);
  594. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16);
  595. spa->range_index = 0+1;
  596. spa->address = t->spa_set_dma[0];
  597. spa->length = SPA0_SIZE;
  598. /*
  599. * spa1 (interleave last half of the 4 DIMMS, note storage
  600. * does not actually alias the related block-data-window
  601. * regions)
  602. */
  603. spa = nfit_buf + sizeof(*spa);
  604. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  605. spa->header.length = sizeof(*spa);
  606. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16);
  607. spa->range_index = 1+1;
  608. spa->address = t->spa_set_dma[1];
  609. spa->length = SPA1_SIZE;
  610. /* spa2 (dcr0) dimm0 */
  611. spa = nfit_buf + sizeof(*spa) * 2;
  612. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  613. spa->header.length = sizeof(*spa);
  614. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
  615. spa->range_index = 2+1;
  616. spa->address = t->dcr_dma[0];
  617. spa->length = DCR_SIZE;
  618. /* spa3 (dcr1) dimm1 */
  619. spa = nfit_buf + sizeof(*spa) * 3;
  620. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  621. spa->header.length = sizeof(*spa);
  622. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
  623. spa->range_index = 3+1;
  624. spa->address = t->dcr_dma[1];
  625. spa->length = DCR_SIZE;
  626. /* spa4 (dcr2) dimm2 */
  627. spa = nfit_buf + sizeof(*spa) * 4;
  628. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  629. spa->header.length = sizeof(*spa);
  630. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
  631. spa->range_index = 4+1;
  632. spa->address = t->dcr_dma[2];
  633. spa->length = DCR_SIZE;
  634. /* spa5 (dcr3) dimm3 */
  635. spa = nfit_buf + sizeof(*spa) * 5;
  636. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  637. spa->header.length = sizeof(*spa);
  638. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
  639. spa->range_index = 5+1;
  640. spa->address = t->dcr_dma[3];
  641. spa->length = DCR_SIZE;
  642. /* spa6 (bdw for dcr0) dimm0 */
  643. spa = nfit_buf + sizeof(*spa) * 6;
  644. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  645. spa->header.length = sizeof(*spa);
  646. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
  647. spa->range_index = 6+1;
  648. spa->address = t->dimm_dma[0];
  649. spa->length = DIMM_SIZE;
  650. /* spa7 (bdw for dcr1) dimm1 */
  651. spa = nfit_buf + sizeof(*spa) * 7;
  652. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  653. spa->header.length = sizeof(*spa);
  654. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
  655. spa->range_index = 7+1;
  656. spa->address = t->dimm_dma[1];
  657. spa->length = DIMM_SIZE;
  658. /* spa8 (bdw for dcr2) dimm2 */
  659. spa = nfit_buf + sizeof(*spa) * 8;
  660. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  661. spa->header.length = sizeof(*spa);
  662. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
  663. spa->range_index = 8+1;
  664. spa->address = t->dimm_dma[2];
  665. spa->length = DIMM_SIZE;
  666. /* spa9 (bdw for dcr3) dimm3 */
  667. spa = nfit_buf + sizeof(*spa) * 9;
  668. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  669. spa->header.length = sizeof(*spa);
  670. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
  671. spa->range_index = 9+1;
  672. spa->address = t->dimm_dma[3];
  673. spa->length = DIMM_SIZE;
  674. offset = sizeof(*spa) * 10;
  675. /* mem-region0 (spa0, dimm0) */
  676. memdev = nfit_buf + offset;
  677. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  678. memdev->header.length = sizeof(*memdev);
  679. memdev->device_handle = handle[0];
  680. memdev->physical_id = 0;
  681. memdev->region_id = 0;
  682. memdev->range_index = 0+1;
  683. memdev->region_index = 4+1;
  684. memdev->region_size = SPA0_SIZE/2;
  685. memdev->region_offset = t->spa_set_dma[0];
  686. memdev->address = 0;
  687. memdev->interleave_index = 0;
  688. memdev->interleave_ways = 2;
  689. /* mem-region1 (spa0, dimm1) */
  690. memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map);
  691. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  692. memdev->header.length = sizeof(*memdev);
  693. memdev->device_handle = handle[1];
  694. memdev->physical_id = 1;
  695. memdev->region_id = 0;
  696. memdev->range_index = 0+1;
  697. memdev->region_index = 5+1;
  698. memdev->region_size = SPA0_SIZE/2;
  699. memdev->region_offset = t->spa_set_dma[0] + SPA0_SIZE/2;
  700. memdev->address = 0;
  701. memdev->interleave_index = 0;
  702. memdev->interleave_ways = 2;
  703. /* mem-region2 (spa1, dimm0) */
  704. memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 2;
  705. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  706. memdev->header.length = sizeof(*memdev);
  707. memdev->device_handle = handle[0];
  708. memdev->physical_id = 0;
  709. memdev->region_id = 1;
  710. memdev->range_index = 1+1;
  711. memdev->region_index = 4+1;
  712. memdev->region_size = SPA1_SIZE/4;
  713. memdev->region_offset = t->spa_set_dma[1];
  714. memdev->address = SPA0_SIZE/2;
  715. memdev->interleave_index = 0;
  716. memdev->interleave_ways = 4;
  717. /* mem-region3 (spa1, dimm1) */
  718. memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 3;
  719. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  720. memdev->header.length = sizeof(*memdev);
  721. memdev->device_handle = handle[1];
  722. memdev->physical_id = 1;
  723. memdev->region_id = 1;
  724. memdev->range_index = 1+1;
  725. memdev->region_index = 5+1;
  726. memdev->region_size = SPA1_SIZE/4;
  727. memdev->region_offset = t->spa_set_dma[1] + SPA1_SIZE/4;
  728. memdev->address = SPA0_SIZE/2;
  729. memdev->interleave_index = 0;
  730. memdev->interleave_ways = 4;
  731. /* mem-region4 (spa1, dimm2) */
  732. memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 4;
  733. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  734. memdev->header.length = sizeof(*memdev);
  735. memdev->device_handle = handle[2];
  736. memdev->physical_id = 2;
  737. memdev->region_id = 0;
  738. memdev->range_index = 1+1;
  739. memdev->region_index = 6+1;
  740. memdev->region_size = SPA1_SIZE/4;
  741. memdev->region_offset = t->spa_set_dma[1] + 2*SPA1_SIZE/4;
  742. memdev->address = SPA0_SIZE/2;
  743. memdev->interleave_index = 0;
  744. memdev->interleave_ways = 4;
  745. /* mem-region5 (spa1, dimm3) */
  746. memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 5;
  747. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  748. memdev->header.length = sizeof(*memdev);
  749. memdev->device_handle = handle[3];
  750. memdev->physical_id = 3;
  751. memdev->region_id = 0;
  752. memdev->range_index = 1+1;
  753. memdev->region_index = 7+1;
  754. memdev->region_size = SPA1_SIZE/4;
  755. memdev->region_offset = t->spa_set_dma[1] + 3*SPA1_SIZE/4;
  756. memdev->address = SPA0_SIZE/2;
  757. memdev->interleave_index = 0;
  758. memdev->interleave_ways = 4;
  759. /* mem-region6 (spa/dcr0, dimm0) */
  760. memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 6;
  761. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  762. memdev->header.length = sizeof(*memdev);
  763. memdev->device_handle = handle[0];
  764. memdev->physical_id = 0;
  765. memdev->region_id = 0;
  766. memdev->range_index = 2+1;
  767. memdev->region_index = 0+1;
  768. memdev->region_size = 0;
  769. memdev->region_offset = 0;
  770. memdev->address = 0;
  771. memdev->interleave_index = 0;
  772. memdev->interleave_ways = 1;
  773. /* mem-region7 (spa/dcr1, dimm1) */
  774. memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 7;
  775. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  776. memdev->header.length = sizeof(*memdev);
  777. memdev->device_handle = handle[1];
  778. memdev->physical_id = 1;
  779. memdev->region_id = 0;
  780. memdev->range_index = 3+1;
  781. memdev->region_index = 1+1;
  782. memdev->region_size = 0;
  783. memdev->region_offset = 0;
  784. memdev->address = 0;
  785. memdev->interleave_index = 0;
  786. memdev->interleave_ways = 1;
  787. /* mem-region8 (spa/dcr2, dimm2) */
  788. memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 8;
  789. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  790. memdev->header.length = sizeof(*memdev);
  791. memdev->device_handle = handle[2];
  792. memdev->physical_id = 2;
  793. memdev->region_id = 0;
  794. memdev->range_index = 4+1;
  795. memdev->region_index = 2+1;
  796. memdev->region_size = 0;
  797. memdev->region_offset = 0;
  798. memdev->address = 0;
  799. memdev->interleave_index = 0;
  800. memdev->interleave_ways = 1;
  801. /* mem-region9 (spa/dcr3, dimm3) */
  802. memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 9;
  803. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  804. memdev->header.length = sizeof(*memdev);
  805. memdev->device_handle = handle[3];
  806. memdev->physical_id = 3;
  807. memdev->region_id = 0;
  808. memdev->range_index = 5+1;
  809. memdev->region_index = 3+1;
  810. memdev->region_size = 0;
  811. memdev->region_offset = 0;
  812. memdev->address = 0;
  813. memdev->interleave_index = 0;
  814. memdev->interleave_ways = 1;
  815. /* mem-region10 (spa/bdw0, dimm0) */
  816. memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 10;
  817. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  818. memdev->header.length = sizeof(*memdev);
  819. memdev->device_handle = handle[0];
  820. memdev->physical_id = 0;
  821. memdev->region_id = 0;
  822. memdev->range_index = 6+1;
  823. memdev->region_index = 0+1;
  824. memdev->region_size = 0;
  825. memdev->region_offset = 0;
  826. memdev->address = 0;
  827. memdev->interleave_index = 0;
  828. memdev->interleave_ways = 1;
  829. /* mem-region11 (spa/bdw1, dimm1) */
  830. memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 11;
  831. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  832. memdev->header.length = sizeof(*memdev);
  833. memdev->device_handle = handle[1];
  834. memdev->physical_id = 1;
  835. memdev->region_id = 0;
  836. memdev->range_index = 7+1;
  837. memdev->region_index = 1+1;
  838. memdev->region_size = 0;
  839. memdev->region_offset = 0;
  840. memdev->address = 0;
  841. memdev->interleave_index = 0;
  842. memdev->interleave_ways = 1;
  843. /* mem-region12 (spa/bdw2, dimm2) */
  844. memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 12;
  845. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  846. memdev->header.length = sizeof(*memdev);
  847. memdev->device_handle = handle[2];
  848. memdev->physical_id = 2;
  849. memdev->region_id = 0;
  850. memdev->range_index = 8+1;
  851. memdev->region_index = 2+1;
  852. memdev->region_size = 0;
  853. memdev->region_offset = 0;
  854. memdev->address = 0;
  855. memdev->interleave_index = 0;
  856. memdev->interleave_ways = 1;
  857. /* mem-region13 (spa/dcr3, dimm3) */
  858. memdev = nfit_buf + offset + sizeof(struct acpi_nfit_memory_map) * 13;
  859. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  860. memdev->header.length = sizeof(*memdev);
  861. memdev->device_handle = handle[3];
  862. memdev->physical_id = 3;
  863. memdev->region_id = 0;
  864. memdev->range_index = 9+1;
  865. memdev->region_index = 3+1;
  866. memdev->region_size = 0;
  867. memdev->region_offset = 0;
  868. memdev->address = 0;
  869. memdev->interleave_index = 0;
  870. memdev->interleave_ways = 1;
  871. offset = offset + sizeof(struct acpi_nfit_memory_map) * 14;
  872. /* dcr-descriptor0: blk */
  873. dcr = nfit_buf + offset;
  874. dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
  875. dcr->header.length = sizeof(struct acpi_nfit_control_region);
  876. dcr->region_index = 0+1;
  877. dcr_common_init(dcr);
  878. dcr->serial_number = ~handle[0];
  879. dcr->code = NFIT_FIC_BLK;
  880. dcr->windows = 1;
  881. dcr->window_size = DCR_SIZE;
  882. dcr->command_offset = 0;
  883. dcr->command_size = 8;
  884. dcr->status_offset = 8;
  885. dcr->status_size = 4;
  886. /* dcr-descriptor1: blk */
  887. dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region);
  888. dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
  889. dcr->header.length = sizeof(struct acpi_nfit_control_region);
  890. dcr->region_index = 1+1;
  891. dcr_common_init(dcr);
  892. dcr->serial_number = ~handle[1];
  893. dcr->code = NFIT_FIC_BLK;
  894. dcr->windows = 1;
  895. dcr->window_size = DCR_SIZE;
  896. dcr->command_offset = 0;
  897. dcr->command_size = 8;
  898. dcr->status_offset = 8;
  899. dcr->status_size = 4;
  900. /* dcr-descriptor2: blk */
  901. dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 2;
  902. dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
  903. dcr->header.length = sizeof(struct acpi_nfit_control_region);
  904. dcr->region_index = 2+1;
  905. dcr_common_init(dcr);
  906. dcr->serial_number = ~handle[2];
  907. dcr->code = NFIT_FIC_BLK;
  908. dcr->windows = 1;
  909. dcr->window_size = DCR_SIZE;
  910. dcr->command_offset = 0;
  911. dcr->command_size = 8;
  912. dcr->status_offset = 8;
  913. dcr->status_size = 4;
  914. /* dcr-descriptor3: blk */
  915. dcr = nfit_buf + offset + sizeof(struct acpi_nfit_control_region) * 3;
  916. dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
  917. dcr->header.length = sizeof(struct acpi_nfit_control_region);
  918. dcr->region_index = 3+1;
  919. dcr_common_init(dcr);
  920. dcr->serial_number = ~handle[3];
  921. dcr->code = NFIT_FIC_BLK;
  922. dcr->windows = 1;
  923. dcr->window_size = DCR_SIZE;
  924. dcr->command_offset = 0;
  925. dcr->command_size = 8;
  926. dcr->status_offset = 8;
  927. dcr->status_size = 4;
  928. offset = offset + sizeof(struct acpi_nfit_control_region) * 4;
  929. /* dcr-descriptor0: pmem */
  930. dcr = nfit_buf + offset;
  931. dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
  932. dcr->header.length = offsetof(struct acpi_nfit_control_region,
  933. window_size);
  934. dcr->region_index = 4+1;
  935. dcr_common_init(dcr);
  936. dcr->serial_number = ~handle[0];
  937. dcr->code = NFIT_FIC_BYTEN;
  938. dcr->windows = 0;
  939. /* dcr-descriptor1: pmem */
  940. dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region,
  941. window_size);
  942. dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
  943. dcr->header.length = offsetof(struct acpi_nfit_control_region,
  944. window_size);
  945. dcr->region_index = 5+1;
  946. dcr_common_init(dcr);
  947. dcr->serial_number = ~handle[1];
  948. dcr->code = NFIT_FIC_BYTEN;
  949. dcr->windows = 0;
  950. /* dcr-descriptor2: pmem */
  951. dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region,
  952. window_size) * 2;
  953. dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
  954. dcr->header.length = offsetof(struct acpi_nfit_control_region,
  955. window_size);
  956. dcr->region_index = 6+1;
  957. dcr_common_init(dcr);
  958. dcr->serial_number = ~handle[2];
  959. dcr->code = NFIT_FIC_BYTEN;
  960. dcr->windows = 0;
  961. /* dcr-descriptor3: pmem */
  962. dcr = nfit_buf + offset + offsetof(struct acpi_nfit_control_region,
  963. window_size) * 3;
  964. dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
  965. dcr->header.length = offsetof(struct acpi_nfit_control_region,
  966. window_size);
  967. dcr->region_index = 7+1;
  968. dcr_common_init(dcr);
  969. dcr->serial_number = ~handle[3];
  970. dcr->code = NFIT_FIC_BYTEN;
  971. dcr->windows = 0;
  972. offset = offset + offsetof(struct acpi_nfit_control_region,
  973. window_size) * 4;
  974. /* bdw0 (spa/dcr0, dimm0) */
  975. bdw = nfit_buf + offset;
  976. bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
  977. bdw->header.length = sizeof(struct acpi_nfit_data_region);
  978. bdw->region_index = 0+1;
  979. bdw->windows = 1;
  980. bdw->offset = 0;
  981. bdw->size = BDW_SIZE;
  982. bdw->capacity = DIMM_SIZE;
  983. bdw->start_address = 0;
  984. /* bdw1 (spa/dcr1, dimm1) */
  985. bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region);
  986. bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
  987. bdw->header.length = sizeof(struct acpi_nfit_data_region);
  988. bdw->region_index = 1+1;
  989. bdw->windows = 1;
  990. bdw->offset = 0;
  991. bdw->size = BDW_SIZE;
  992. bdw->capacity = DIMM_SIZE;
  993. bdw->start_address = 0;
  994. /* bdw2 (spa/dcr2, dimm2) */
  995. bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 2;
  996. bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
  997. bdw->header.length = sizeof(struct acpi_nfit_data_region);
  998. bdw->region_index = 2+1;
  999. bdw->windows = 1;
  1000. bdw->offset = 0;
  1001. bdw->size = BDW_SIZE;
  1002. bdw->capacity = DIMM_SIZE;
  1003. bdw->start_address = 0;
  1004. /* bdw3 (spa/dcr3, dimm3) */
  1005. bdw = nfit_buf + offset + sizeof(struct acpi_nfit_data_region) * 3;
  1006. bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
  1007. bdw->header.length = sizeof(struct acpi_nfit_data_region);
  1008. bdw->region_index = 3+1;
  1009. bdw->windows = 1;
  1010. bdw->offset = 0;
  1011. bdw->size = BDW_SIZE;
  1012. bdw->capacity = DIMM_SIZE;
  1013. bdw->start_address = 0;
  1014. offset = offset + sizeof(struct acpi_nfit_data_region) * 4;
  1015. /* flush0 (dimm0) */
  1016. flush = nfit_buf + offset;
  1017. flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
  1018. flush->header.length = flush_hint_size;
  1019. flush->device_handle = handle[0];
  1020. flush->hint_count = NUM_HINTS;
  1021. for (i = 0; i < NUM_HINTS; i++)
  1022. flush->hint_address[i] = t->flush_dma[0] + i * sizeof(u64);
  1023. /* flush1 (dimm1) */
  1024. flush = nfit_buf + offset + flush_hint_size * 1;
  1025. flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
  1026. flush->header.length = flush_hint_size;
  1027. flush->device_handle = handle[1];
  1028. flush->hint_count = NUM_HINTS;
  1029. for (i = 0; i < NUM_HINTS; i++)
  1030. flush->hint_address[i] = t->flush_dma[1] + i * sizeof(u64);
  1031. /* flush2 (dimm2) */
  1032. flush = nfit_buf + offset + flush_hint_size * 2;
  1033. flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
  1034. flush->header.length = flush_hint_size;
  1035. flush->device_handle = handle[2];
  1036. flush->hint_count = NUM_HINTS;
  1037. for (i = 0; i < NUM_HINTS; i++)
  1038. flush->hint_address[i] = t->flush_dma[2] + i * sizeof(u64);
  1039. /* flush3 (dimm3) */
  1040. flush = nfit_buf + offset + flush_hint_size * 3;
  1041. flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
  1042. flush->header.length = flush_hint_size;
  1043. flush->device_handle = handle[3];
  1044. flush->hint_count = NUM_HINTS;
  1045. for (i = 0; i < NUM_HINTS; i++)
  1046. flush->hint_address[i] = t->flush_dma[3] + i * sizeof(u64);
  1047. if (t->setup_hotplug) {
  1048. offset = offset + flush_hint_size * 4;
  1049. /* dcr-descriptor4: blk */
  1050. dcr = nfit_buf + offset;
  1051. dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
  1052. dcr->header.length = sizeof(struct acpi_nfit_control_region);
  1053. dcr->region_index = 8+1;
  1054. dcr_common_init(dcr);
  1055. dcr->serial_number = ~handle[4];
  1056. dcr->code = NFIT_FIC_BLK;
  1057. dcr->windows = 1;
  1058. dcr->window_size = DCR_SIZE;
  1059. dcr->command_offset = 0;
  1060. dcr->command_size = 8;
  1061. dcr->status_offset = 8;
  1062. dcr->status_size = 4;
  1063. offset = offset + sizeof(struct acpi_nfit_control_region);
  1064. /* dcr-descriptor4: pmem */
  1065. dcr = nfit_buf + offset;
  1066. dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
  1067. dcr->header.length = offsetof(struct acpi_nfit_control_region,
  1068. window_size);
  1069. dcr->region_index = 9+1;
  1070. dcr_common_init(dcr);
  1071. dcr->serial_number = ~handle[4];
  1072. dcr->code = NFIT_FIC_BYTEN;
  1073. dcr->windows = 0;
  1074. offset = offset + offsetof(struct acpi_nfit_control_region,
  1075. window_size);
  1076. /* bdw4 (spa/dcr4, dimm4) */
  1077. bdw = nfit_buf + offset;
  1078. bdw->header.type = ACPI_NFIT_TYPE_DATA_REGION;
  1079. bdw->header.length = sizeof(struct acpi_nfit_data_region);
  1080. bdw->region_index = 8+1;
  1081. bdw->windows = 1;
  1082. bdw->offset = 0;
  1083. bdw->size = BDW_SIZE;
  1084. bdw->capacity = DIMM_SIZE;
  1085. bdw->start_address = 0;
  1086. offset = offset + sizeof(struct acpi_nfit_data_region);
  1087. /* spa10 (dcr4) dimm4 */
  1088. spa = nfit_buf + offset;
  1089. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  1090. spa->header.length = sizeof(*spa);
  1091. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_DCR), 16);
  1092. spa->range_index = 10+1;
  1093. spa->address = t->dcr_dma[4];
  1094. spa->length = DCR_SIZE;
  1095. /*
  1096. * spa11 (single-dimm interleave for hotplug, note storage
  1097. * does not actually alias the related block-data-window
  1098. * regions)
  1099. */
  1100. spa = nfit_buf + offset + sizeof(*spa);
  1101. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  1102. spa->header.length = sizeof(*spa);
  1103. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16);
  1104. spa->range_index = 11+1;
  1105. spa->address = t->spa_set_dma[2];
  1106. spa->length = SPA0_SIZE;
  1107. /* spa12 (bdw for dcr4) dimm4 */
  1108. spa = nfit_buf + offset + sizeof(*spa) * 2;
  1109. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  1110. spa->header.length = sizeof(*spa);
  1111. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_BDW), 16);
  1112. spa->range_index = 12+1;
  1113. spa->address = t->dimm_dma[4];
  1114. spa->length = DIMM_SIZE;
  1115. offset = offset + sizeof(*spa) * 3;
  1116. /* mem-region14 (spa/dcr4, dimm4) */
  1117. memdev = nfit_buf + offset;
  1118. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  1119. memdev->header.length = sizeof(*memdev);
  1120. memdev->device_handle = handle[4];
  1121. memdev->physical_id = 4;
  1122. memdev->region_id = 0;
  1123. memdev->range_index = 10+1;
  1124. memdev->region_index = 8+1;
  1125. memdev->region_size = 0;
  1126. memdev->region_offset = 0;
  1127. memdev->address = 0;
  1128. memdev->interleave_index = 0;
  1129. memdev->interleave_ways = 1;
  1130. /* mem-region15 (spa0, dimm4) */
  1131. memdev = nfit_buf + offset +
  1132. sizeof(struct acpi_nfit_memory_map);
  1133. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  1134. memdev->header.length = sizeof(*memdev);
  1135. memdev->device_handle = handle[4];
  1136. memdev->physical_id = 4;
  1137. memdev->region_id = 0;
  1138. memdev->range_index = 11+1;
  1139. memdev->region_index = 9+1;
  1140. memdev->region_size = SPA0_SIZE;
  1141. memdev->region_offset = t->spa_set_dma[2];
  1142. memdev->address = 0;
  1143. memdev->interleave_index = 0;
  1144. memdev->interleave_ways = 1;
  1145. /* mem-region16 (spa/bdw4, dimm4) */
  1146. memdev = nfit_buf + offset +
  1147. sizeof(struct acpi_nfit_memory_map) * 2;
  1148. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  1149. memdev->header.length = sizeof(*memdev);
  1150. memdev->device_handle = handle[4];
  1151. memdev->physical_id = 4;
  1152. memdev->region_id = 0;
  1153. memdev->range_index = 12+1;
  1154. memdev->region_index = 8+1;
  1155. memdev->region_size = 0;
  1156. memdev->region_offset = 0;
  1157. memdev->address = 0;
  1158. memdev->interleave_index = 0;
  1159. memdev->interleave_ways = 1;
  1160. offset = offset + sizeof(struct acpi_nfit_memory_map) * 3;
  1161. /* flush3 (dimm4) */
  1162. flush = nfit_buf + offset;
  1163. flush->header.type = ACPI_NFIT_TYPE_FLUSH_ADDRESS;
  1164. flush->header.length = flush_hint_size;
  1165. flush->device_handle = handle[4];
  1166. flush->hint_count = NUM_HINTS;
  1167. for (i = 0; i < NUM_HINTS; i++)
  1168. flush->hint_address[i] = t->flush_dma[4]
  1169. + i * sizeof(u64);
  1170. }
  1171. post_ars_status(&t->ars_state, t->spa_set_dma[0], SPA0_SIZE);
  1172. acpi_desc = &t->acpi_desc;
  1173. set_bit(ND_CMD_GET_CONFIG_SIZE, &acpi_desc->dimm_cmd_force_en);
  1174. set_bit(ND_CMD_GET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en);
  1175. set_bit(ND_CMD_SET_CONFIG_DATA, &acpi_desc->dimm_cmd_force_en);
  1176. set_bit(ND_CMD_SMART, &acpi_desc->dimm_cmd_force_en);
  1177. set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en);
  1178. set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en);
  1179. set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en);
  1180. set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en);
  1181. set_bit(ND_CMD_SMART_THRESHOLD, &acpi_desc->dimm_cmd_force_en);
  1182. }
  1183. static void nfit_test1_setup(struct nfit_test *t)
  1184. {
  1185. size_t offset;
  1186. void *nfit_buf = t->nfit_buf;
  1187. struct acpi_nfit_memory_map *memdev;
  1188. struct acpi_nfit_control_region *dcr;
  1189. struct acpi_nfit_system_address *spa;
  1190. struct acpi_nfit_desc *acpi_desc;
  1191. offset = 0;
  1192. /* spa0 (flat range with no bdw aliasing) */
  1193. spa = nfit_buf + offset;
  1194. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  1195. spa->header.length = sizeof(*spa);
  1196. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_PM), 16);
  1197. spa->range_index = 0+1;
  1198. spa->address = t->spa_set_dma[0];
  1199. spa->length = SPA2_SIZE;
  1200. /* virtual cd region */
  1201. spa = nfit_buf + sizeof(*spa);
  1202. spa->header.type = ACPI_NFIT_TYPE_SYSTEM_ADDRESS;
  1203. spa->header.length = sizeof(*spa);
  1204. memcpy(spa->range_guid, to_nfit_uuid(NFIT_SPA_VCD), 16);
  1205. spa->range_index = 0;
  1206. spa->address = t->spa_set_dma[1];
  1207. spa->length = SPA_VCD_SIZE;
  1208. offset += sizeof(*spa) * 2;
  1209. /* mem-region0 (spa0, dimm0) */
  1210. memdev = nfit_buf + offset;
  1211. memdev->header.type = ACPI_NFIT_TYPE_MEMORY_MAP;
  1212. memdev->header.length = sizeof(*memdev);
  1213. memdev->device_handle = 0;
  1214. memdev->physical_id = 0;
  1215. memdev->region_id = 0;
  1216. memdev->range_index = 0+1;
  1217. memdev->region_index = 0+1;
  1218. memdev->region_size = SPA2_SIZE;
  1219. memdev->region_offset = 0;
  1220. memdev->address = 0;
  1221. memdev->interleave_index = 0;
  1222. memdev->interleave_ways = 1;
  1223. memdev->flags = ACPI_NFIT_MEM_SAVE_FAILED | ACPI_NFIT_MEM_RESTORE_FAILED
  1224. | ACPI_NFIT_MEM_FLUSH_FAILED | ACPI_NFIT_MEM_HEALTH_OBSERVED
  1225. | ACPI_NFIT_MEM_NOT_ARMED;
  1226. offset += sizeof(*memdev);
  1227. /* dcr-descriptor0 */
  1228. dcr = nfit_buf + offset;
  1229. dcr->header.type = ACPI_NFIT_TYPE_CONTROL_REGION;
  1230. dcr->header.length = offsetof(struct acpi_nfit_control_region,
  1231. window_size);
  1232. dcr->region_index = 0+1;
  1233. dcr_common_init(dcr);
  1234. dcr->serial_number = ~0;
  1235. dcr->code = NFIT_FIC_BYTE;
  1236. dcr->windows = 0;
  1237. post_ars_status(&t->ars_state, t->spa_set_dma[0], SPA2_SIZE);
  1238. acpi_desc = &t->acpi_desc;
  1239. set_bit(ND_CMD_ARS_CAP, &acpi_desc->bus_cmd_force_en);
  1240. set_bit(ND_CMD_ARS_START, &acpi_desc->bus_cmd_force_en);
  1241. set_bit(ND_CMD_ARS_STATUS, &acpi_desc->bus_cmd_force_en);
  1242. set_bit(ND_CMD_CLEAR_ERROR, &acpi_desc->bus_cmd_force_en);
  1243. }
  1244. static int nfit_test_blk_do_io(struct nd_blk_region *ndbr, resource_size_t dpa,
  1245. void *iobuf, u64 len, int rw)
  1246. {
  1247. struct nfit_blk *nfit_blk = ndbr->blk_provider_data;
  1248. struct nfit_blk_mmio *mmio = &nfit_blk->mmio[BDW];
  1249. struct nd_region *nd_region = &ndbr->nd_region;
  1250. unsigned int lane;
  1251. lane = nd_region_acquire_lane(nd_region);
  1252. if (rw)
  1253. memcpy(mmio->addr.base + dpa, iobuf, len);
  1254. else {
  1255. memcpy(iobuf, mmio->addr.base + dpa, len);
  1256. /* give us some some coverage of the mmio_flush_range() API */
  1257. mmio_flush_range(mmio->addr.base + dpa, len);
  1258. }
  1259. nd_region_release_lane(nd_region, lane);
  1260. return 0;
  1261. }
  1262. static int nfit_test_probe(struct platform_device *pdev)
  1263. {
  1264. struct nvdimm_bus_descriptor *nd_desc;
  1265. struct acpi_nfit_desc *acpi_desc;
  1266. struct device *dev = &pdev->dev;
  1267. struct nfit_test *nfit_test;
  1268. int rc;
  1269. nfit_test = to_nfit_test(&pdev->dev);
  1270. /* common alloc */
  1271. if (nfit_test->num_dcr) {
  1272. int num = nfit_test->num_dcr;
  1273. nfit_test->dimm = devm_kcalloc(dev, num, sizeof(void *),
  1274. GFP_KERNEL);
  1275. nfit_test->dimm_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t),
  1276. GFP_KERNEL);
  1277. nfit_test->flush = devm_kcalloc(dev, num, sizeof(void *),
  1278. GFP_KERNEL);
  1279. nfit_test->flush_dma = devm_kcalloc(dev, num, sizeof(dma_addr_t),
  1280. GFP_KERNEL);
  1281. nfit_test->label = devm_kcalloc(dev, num, sizeof(void *),
  1282. GFP_KERNEL);
  1283. nfit_test->label_dma = devm_kcalloc(dev, num,
  1284. sizeof(dma_addr_t), GFP_KERNEL);
  1285. nfit_test->dcr = devm_kcalloc(dev, num,
  1286. sizeof(struct nfit_test_dcr *), GFP_KERNEL);
  1287. nfit_test->dcr_dma = devm_kcalloc(dev, num,
  1288. sizeof(dma_addr_t), GFP_KERNEL);
  1289. if (nfit_test->dimm && nfit_test->dimm_dma && nfit_test->label
  1290. && nfit_test->label_dma && nfit_test->dcr
  1291. && nfit_test->dcr_dma && nfit_test->flush
  1292. && nfit_test->flush_dma)
  1293. /* pass */;
  1294. else
  1295. return -ENOMEM;
  1296. }
  1297. if (nfit_test->num_pm) {
  1298. int num = nfit_test->num_pm;
  1299. nfit_test->spa_set = devm_kcalloc(dev, num, sizeof(void *),
  1300. GFP_KERNEL);
  1301. nfit_test->spa_set_dma = devm_kcalloc(dev, num,
  1302. sizeof(dma_addr_t), GFP_KERNEL);
  1303. if (nfit_test->spa_set && nfit_test->spa_set_dma)
  1304. /* pass */;
  1305. else
  1306. return -ENOMEM;
  1307. }
  1308. /* per-nfit specific alloc */
  1309. if (nfit_test->alloc(nfit_test))
  1310. return -ENOMEM;
  1311. nfit_test->setup(nfit_test);
  1312. acpi_desc = &nfit_test->acpi_desc;
  1313. acpi_nfit_desc_init(acpi_desc, &pdev->dev);
  1314. acpi_desc->blk_do_io = nfit_test_blk_do_io;
  1315. nd_desc = &acpi_desc->nd_desc;
  1316. nd_desc->provider_name = NULL;
  1317. nd_desc->module = THIS_MODULE;
  1318. nd_desc->ndctl = nfit_test_ctl;
  1319. rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf,
  1320. nfit_test->nfit_size);
  1321. if (rc)
  1322. return rc;
  1323. if (nfit_test->setup != nfit_test0_setup)
  1324. return 0;
  1325. flush_work(&acpi_desc->work);
  1326. nfit_test->setup_hotplug = 1;
  1327. nfit_test->setup(nfit_test);
  1328. rc = acpi_nfit_init(acpi_desc, nfit_test->nfit_buf,
  1329. nfit_test->nfit_size);
  1330. if (rc)
  1331. return rc;
  1332. return 0;
  1333. }
  1334. static int nfit_test_remove(struct platform_device *pdev)
  1335. {
  1336. return 0;
  1337. }
  1338. static void nfit_test_release(struct device *dev)
  1339. {
  1340. struct nfit_test *nfit_test = to_nfit_test(dev);
  1341. kfree(nfit_test);
  1342. }
  1343. static const struct platform_device_id nfit_test_id[] = {
  1344. { KBUILD_MODNAME },
  1345. { },
  1346. };
  1347. static struct platform_driver nfit_test_driver = {
  1348. .probe = nfit_test_probe,
  1349. .remove = nfit_test_remove,
  1350. .driver = {
  1351. .name = KBUILD_MODNAME,
  1352. },
  1353. .id_table = nfit_test_id,
  1354. };
  1355. static __init int nfit_test_init(void)
  1356. {
  1357. int rc, i;
  1358. nfit_test_setup(nfit_test_lookup);
  1359. for (i = 0; i < NUM_NFITS; i++) {
  1360. struct nfit_test *nfit_test;
  1361. struct platform_device *pdev;
  1362. nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL);
  1363. if (!nfit_test) {
  1364. rc = -ENOMEM;
  1365. goto err_register;
  1366. }
  1367. INIT_LIST_HEAD(&nfit_test->resources);
  1368. switch (i) {
  1369. case 0:
  1370. nfit_test->num_pm = NUM_PM;
  1371. nfit_test->num_dcr = NUM_DCR;
  1372. nfit_test->alloc = nfit_test0_alloc;
  1373. nfit_test->setup = nfit_test0_setup;
  1374. break;
  1375. case 1:
  1376. nfit_test->num_pm = 1;
  1377. nfit_test->alloc = nfit_test1_alloc;
  1378. nfit_test->setup = nfit_test1_setup;
  1379. break;
  1380. default:
  1381. rc = -EINVAL;
  1382. goto err_register;
  1383. }
  1384. pdev = &nfit_test->pdev;
  1385. pdev->name = KBUILD_MODNAME;
  1386. pdev->id = i;
  1387. pdev->dev.release = nfit_test_release;
  1388. rc = platform_device_register(pdev);
  1389. if (rc) {
  1390. put_device(&pdev->dev);
  1391. goto err_register;
  1392. }
  1393. rc = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  1394. if (rc)
  1395. goto err_register;
  1396. instances[i] = nfit_test;
  1397. }
  1398. rc = platform_driver_register(&nfit_test_driver);
  1399. if (rc)
  1400. goto err_register;
  1401. return 0;
  1402. err_register:
  1403. for (i = 0; i < NUM_NFITS; i++)
  1404. if (instances[i])
  1405. platform_device_unregister(&instances[i]->pdev);
  1406. nfit_test_teardown();
  1407. return rc;
  1408. }
  1409. static __exit void nfit_test_exit(void)
  1410. {
  1411. int i;
  1412. platform_driver_unregister(&nfit_test_driver);
  1413. for (i = 0; i < NUM_NFITS; i++)
  1414. platform_device_unregister(&instances[i]->pdev);
  1415. nfit_test_teardown();
  1416. }
  1417. module_init(nfit_test_init);
  1418. module_exit(nfit_test_exit);
  1419. MODULE_LICENSE("GPL v2");
  1420. MODULE_AUTHOR("Intel Corporation");