nfit.c (14a4467a0a5eacb2ebbe3aab1b4e25af3519c76a) | nfit.c (e3f5df762d4a6ef6326c3c09bc9f89ea8a2eab2c) |
---|---|
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> | 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/genalloc.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> --- 184 unchanged lines hidden (view full) --- 210 struct nd_intel_smart_threshold *smart_threshold; 211 struct badrange badrange; 212 struct work_struct work; 213 struct nfit_test_fw *fw; 214}; 215 216static struct workqueue_struct *nfit_wq; 217 | 19#include <linux/vmalloc.h> 20#include <linux/device.h> 21#include <linux/module.h> 22#include <linux/mutex.h> 23#include <linux/ndctl.h> 24#include <linux/sizes.h> 25#include <linux/list.h> 26#include <linux/slab.h> --- 184 unchanged lines hidden (view full) --- 211 struct nd_intel_smart_threshold *smart_threshold; 212 struct badrange badrange; 213 struct work_struct work; 214 struct nfit_test_fw *fw; 215}; 216 217static struct workqueue_struct *nfit_wq; 218 |
219static struct gen_pool *nfit_pool; 220 |
|
218static struct nfit_test *to_nfit_test(struct device *dev) 219{ 220 struct platform_device *pdev = to_platform_device(dev); 221 222 return container_of(pdev, struct nfit_test, pdev); 223} 224 225static int nd_intel_test_get_fw_info(struct nfit_test *t, --- 901 unchanged lines hidden (view full) --- 1127static void release_nfit_res(void *data) 1128{ 1129 struct nfit_test_resource *nfit_res = data; 1130 1131 spin_lock(&nfit_test_lock); 1132 list_del(&nfit_res->list); 1133 spin_unlock(&nfit_test_lock); 1134 | 221static struct nfit_test *to_nfit_test(struct device *dev) 222{ 223 struct platform_device *pdev = to_platform_device(dev); 224 225 return container_of(pdev, struct nfit_test, pdev); 226} 227 228static int nd_intel_test_get_fw_info(struct nfit_test *t, --- 901 unchanged lines hidden (view full) --- 1130static void release_nfit_res(void *data) 1131{ 1132 struct nfit_test_resource *nfit_res = data; 1133 1134 spin_lock(&nfit_test_lock); 1135 list_del(&nfit_res->list); 1136 spin_unlock(&nfit_test_lock); 1137 |
1138 if (resource_size(&nfit_res->res) >= DIMM_SIZE) 1139 gen_pool_free(nfit_pool, nfit_res->res.start, 1140 resource_size(&nfit_res->res)); |
|
1135 vfree(nfit_res->buf); 1136 kfree(nfit_res); 1137} 1138 1139static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, 1140 void *buf) 1141{ 1142 struct device *dev = &t->pdev.dev; 1143 struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res), 1144 GFP_KERNEL); 1145 int rc; 1146 | 1141 vfree(nfit_res->buf); 1142 kfree(nfit_res); 1143} 1144 1145static void *__test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma, 1146 void *buf) 1147{ 1148 struct device *dev = &t->pdev.dev; 1149 struct nfit_test_resource *nfit_res = kzalloc(sizeof(*nfit_res), 1150 GFP_KERNEL); 1151 int rc; 1152 |
1147 if (!buf || !nfit_res) | 1153 if (!buf || !nfit_res || !*dma) |
1148 goto err; 1149 rc = devm_add_action(dev, release_nfit_res, nfit_res); 1150 if (rc) 1151 goto err; 1152 INIT_LIST_HEAD(&nfit_res->list); 1153 memset(buf, 0, size); 1154 nfit_res->dev = dev; 1155 nfit_res->buf = buf; 1156 nfit_res->res.start = *dma; 1157 nfit_res->res.end = *dma + size - 1; 1158 nfit_res->res.name = "NFIT"; 1159 spin_lock_init(&nfit_res->lock); 1160 INIT_LIST_HEAD(&nfit_res->requests); 1161 spin_lock(&nfit_test_lock); 1162 list_add(&nfit_res->list, &t->resources); 1163 spin_unlock(&nfit_test_lock); 1164 1165 return nfit_res->buf; 1166 err: | 1154 goto err; 1155 rc = devm_add_action(dev, release_nfit_res, nfit_res); 1156 if (rc) 1157 goto err; 1158 INIT_LIST_HEAD(&nfit_res->list); 1159 memset(buf, 0, size); 1160 nfit_res->dev = dev; 1161 nfit_res->buf = buf; 1162 nfit_res->res.start = *dma; 1163 nfit_res->res.end = *dma + size - 1; 1164 nfit_res->res.name = "NFIT"; 1165 spin_lock_init(&nfit_res->lock); 1166 INIT_LIST_HEAD(&nfit_res->requests); 1167 spin_lock(&nfit_test_lock); 1168 list_add(&nfit_res->list, &t->resources); 1169 spin_unlock(&nfit_test_lock); 1170 1171 return nfit_res->buf; 1172 err: |
1173 if (*dma && size >= DIMM_SIZE) 1174 gen_pool_free(nfit_pool, *dma, size); |
|
1167 if (buf) 1168 vfree(buf); 1169 kfree(nfit_res); 1170 return NULL; 1171} 1172 1173static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma) 1174{ | 1175 if (buf) 1176 vfree(buf); 1177 kfree(nfit_res); 1178 return NULL; 1179} 1180 1181static void *test_alloc(struct nfit_test *t, size_t size, dma_addr_t *dma) 1182{ |
1183 struct genpool_data_align data = { 1184 .align = SZ_128M, 1185 }; |
|
1175 void *buf = vmalloc(size); 1176 | 1186 void *buf = vmalloc(size); 1187 |
1177 *dma = (unsigned long) buf; | 1188 if (size >= DIMM_SIZE) 1189 *dma = gen_pool_alloc_algo(nfit_pool, size, 1190 gen_pool_first_fit_align, &data); 1191 else 1192 *dma = (unsigned long) buf; |
1178 return __test_alloc(t, size, dma, buf); 1179} 1180 1181static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr) 1182{ 1183 int i; 1184 1185 for (i = 0; i < ARRAY_SIZE(instances); i++) { --- 1648 unchanged lines hidden (view full) --- 2834 return -ENOMEM; 2835 2836 nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm"); 2837 if (IS_ERR(nfit_test_dimm)) { 2838 rc = PTR_ERR(nfit_test_dimm); 2839 goto err_register; 2840 } 2841 | 1193 return __test_alloc(t, size, dma, buf); 1194} 1195 1196static struct nfit_test_resource *nfit_test_lookup(resource_size_t addr) 1197{ 1198 int i; 1199 1200 for (i = 0; i < ARRAY_SIZE(instances); i++) { --- 1648 unchanged lines hidden (view full) --- 2849 return -ENOMEM; 2850 2851 nfit_test_dimm = class_create(THIS_MODULE, "nfit_test_dimm"); 2852 if (IS_ERR(nfit_test_dimm)) { 2853 rc = PTR_ERR(nfit_test_dimm); 2854 goto err_register; 2855 } 2856 |
2857 nfit_pool = gen_pool_create(ilog2(SZ_4M), NUMA_NO_NODE); 2858 if (!nfit_pool) { 2859 rc = -ENOMEM; 2860 goto err_register; 2861 } 2862 2863 if (gen_pool_add(nfit_pool, SZ_4G, SZ_4G, NUMA_NO_NODE)) { 2864 rc = -ENOMEM; 2865 goto err_register; 2866 } 2867 |
|
2842 for (i = 0; i < NUM_NFITS; i++) { 2843 struct nfit_test *nfit_test; 2844 struct platform_device *pdev; 2845 2846 nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); 2847 if (!nfit_test) { 2848 rc = -ENOMEM; 2849 goto err_register; --- 39 unchanged lines hidden (view full) --- 2889 } 2890 2891 rc = platform_driver_register(&nfit_test_driver); 2892 if (rc) 2893 goto err_register; 2894 return 0; 2895 2896 err_register: | 2868 for (i = 0; i < NUM_NFITS; i++) { 2869 struct nfit_test *nfit_test; 2870 struct platform_device *pdev; 2871 2872 nfit_test = kzalloc(sizeof(*nfit_test), GFP_KERNEL); 2873 if (!nfit_test) { 2874 rc = -ENOMEM; 2875 goto err_register; --- 39 unchanged lines hidden (view full) --- 2915 } 2916 2917 rc = platform_driver_register(&nfit_test_driver); 2918 if (rc) 2919 goto err_register; 2920 return 0; 2921 2922 err_register: |
2923 if (nfit_pool) 2924 gen_pool_destroy(nfit_pool); 2925 |
|
2897 destroy_workqueue(nfit_wq); 2898 for (i = 0; i < NUM_NFITS; i++) 2899 if (instances[i]) 2900 platform_device_unregister(&instances[i]->pdev); 2901 nfit_test_teardown(); 2902 for (i = 0; i < NUM_NFITS; i++) 2903 if (instances[i]) 2904 put_device(&instances[i]->pdev.dev); --- 7 unchanged lines hidden (view full) --- 2912 2913 flush_workqueue(nfit_wq); 2914 destroy_workqueue(nfit_wq); 2915 for (i = 0; i < NUM_NFITS; i++) 2916 platform_device_unregister(&instances[i]->pdev); 2917 platform_driver_unregister(&nfit_test_driver); 2918 nfit_test_teardown(); 2919 | 2926 destroy_workqueue(nfit_wq); 2927 for (i = 0; i < NUM_NFITS; i++) 2928 if (instances[i]) 2929 platform_device_unregister(&instances[i]->pdev); 2930 nfit_test_teardown(); 2931 for (i = 0; i < NUM_NFITS; i++) 2932 if (instances[i]) 2933 put_device(&instances[i]->pdev.dev); --- 7 unchanged lines hidden (view full) --- 2941 2942 flush_workqueue(nfit_wq); 2943 destroy_workqueue(nfit_wq); 2944 for (i = 0; i < NUM_NFITS; i++) 2945 platform_device_unregister(&instances[i]->pdev); 2946 platform_driver_unregister(&nfit_test_driver); 2947 nfit_test_teardown(); 2948 |
2949 gen_pool_destroy(nfit_pool); 2950 |
|
2920 for (i = 0; i < NUM_NFITS; i++) 2921 put_device(&instances[i]->pdev.dev); 2922 class_destroy(nfit_test_dimm); 2923} 2924 2925module_init(nfit_test_init); 2926module_exit(nfit_test_exit); 2927MODULE_LICENSE("GPL v2"); 2928MODULE_AUTHOR("Intel Corporation"); | 2951 for (i = 0; i < NUM_NFITS; i++) 2952 put_device(&instances[i]->pdev.dev); 2953 class_destroy(nfit_test_dimm); 2954} 2955 2956module_init(nfit_test_init); 2957module_exit(nfit_test_exit); 2958MODULE_LICENSE("GPL v2"); 2959MODULE_AUTHOR("Intel Corporation"); |