aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/sysdev/msi_bitmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/sysdev/msi_bitmap.c')
-rw-r--r--arch/powerpc/sysdev/msi_bitmap.c66
1 files changed, 35 insertions, 31 deletions
diff --git a/arch/powerpc/sysdev/msi_bitmap.c b/arch/powerpc/sysdev/msi_bitmap.c
index 0c75214b6f92..73b64c73505b 100644
--- a/arch/powerpc/sysdev/msi_bitmap.c
+++ b/arch/powerpc/sysdev/msi_bitmap.c
@@ -145,59 +145,64 @@ void msi_bitmap_free(struct msi_bitmap *bmp)
145 145
146#ifdef CONFIG_MSI_BITMAP_SELFTEST 146#ifdef CONFIG_MSI_BITMAP_SELFTEST
147 147
148#define check(x) \
149 if (!(x)) printk("msi_bitmap: test failed at line %d\n", __LINE__);
150
151static void __init test_basics(void) 148static void __init test_basics(void)
152{ 149{
153 struct msi_bitmap bmp; 150 struct msi_bitmap bmp;
154 int i, size = 512; 151 int rc, i, size = 512;
155 152
156 /* Can't allocate a bitmap of 0 irqs */ 153 /* Can't allocate a bitmap of 0 irqs */
157 check(msi_bitmap_alloc(&bmp, 0, NULL) != 0); 154 WARN_ON(msi_bitmap_alloc(&bmp, 0, NULL) == 0);
158 155
159 /* of_node may be NULL */ 156 /* of_node may be NULL */
160 check(0 == msi_bitmap_alloc(&bmp, size, NULL)); 157 WARN_ON(msi_bitmap_alloc(&bmp, size, NULL));
161 158
162 /* Should all be free by default */ 159 /* Should all be free by default */
163 check(0 == bitmap_find_free_region(bmp.bitmap, size, 160 WARN_ON(bitmap_find_free_region(bmp.bitmap, size, get_count_order(size)));
164 get_count_order(size)));
165 bitmap_release_region(bmp.bitmap, 0, get_count_order(size)); 161 bitmap_release_region(bmp.bitmap, 0, get_count_order(size));
166 162
167 /* With no node, there's no msi-available-ranges, so expect > 0 */ 163 /* With no node, there's no msi-available-ranges, so expect > 0 */
168 check(msi_bitmap_reserve_dt_hwirqs(&bmp) > 0); 164 WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp) <= 0);
169 165
170 /* Should all still be free */ 166 /* Should all still be free */
171 check(0 == bitmap_find_free_region(bmp.bitmap, size, 167 WARN_ON(bitmap_find_free_region(bmp.bitmap, size, get_count_order(size)));
172 get_count_order(size)));
173 bitmap_release_region(bmp.bitmap, 0, get_count_order(size)); 168 bitmap_release_region(bmp.bitmap, 0, get_count_order(size));
174 169
175 /* Check we can fill it up and then no more */ 170 /* Check we can fill it up and then no more */
176 for (i = 0; i < size; i++) 171 for (i = 0; i < size; i++)
177 check(msi_bitmap_alloc_hwirqs(&bmp, 1) >= 0); 172 WARN_ON(msi_bitmap_alloc_hwirqs(&bmp, 1) < 0);
178 173
179 check(msi_bitmap_alloc_hwirqs(&bmp, 1) < 0); 174 WARN_ON(msi_bitmap_alloc_hwirqs(&bmp, 1) >= 0);
180 175
181 /* Should all be allocated */ 176 /* Should all be allocated */
182 check(bitmap_find_free_region(bmp.bitmap, size, 0) < 0); 177 WARN_ON(bitmap_find_free_region(bmp.bitmap, size, 0) >= 0);
183 178
184 /* And if we free one we can then allocate another */ 179 /* And if we free one we can then allocate another */
185 msi_bitmap_free_hwirqs(&bmp, size / 2, 1); 180 msi_bitmap_free_hwirqs(&bmp, size / 2, 1);
186 check(msi_bitmap_alloc_hwirqs(&bmp, 1) == size / 2); 181 WARN_ON(msi_bitmap_alloc_hwirqs(&bmp, 1) != size / 2);
182
183 /* Free most of them for the alignment tests */
184 msi_bitmap_free_hwirqs(&bmp, 3, size - 3);
187 185
188 /* Check we get a naturally aligned offset */ 186 /* Check we get a naturally aligned offset */
189 check(msi_bitmap_alloc_hwirqs(&bmp, 2) % 2 == 0); 187 rc = msi_bitmap_alloc_hwirqs(&bmp, 2);
190 check(msi_bitmap_alloc_hwirqs(&bmp, 4) % 4 == 0); 188 WARN_ON(rc < 0 && rc % 2 != 0);
191 check(msi_bitmap_alloc_hwirqs(&bmp, 8) % 8 == 0); 189 rc = msi_bitmap_alloc_hwirqs(&bmp, 4);
192 check(msi_bitmap_alloc_hwirqs(&bmp, 9) % 16 == 0); 190 WARN_ON(rc < 0 && rc % 4 != 0);
193 check(msi_bitmap_alloc_hwirqs(&bmp, 3) % 4 == 0); 191 rc = msi_bitmap_alloc_hwirqs(&bmp, 8);
194 check(msi_bitmap_alloc_hwirqs(&bmp, 7) % 8 == 0); 192 WARN_ON(rc < 0 && rc % 8 != 0);
195 check(msi_bitmap_alloc_hwirqs(&bmp, 121) % 128 == 0); 193 rc = msi_bitmap_alloc_hwirqs(&bmp, 9);
194 WARN_ON(rc < 0 && rc % 16 != 0);
195 rc = msi_bitmap_alloc_hwirqs(&bmp, 3);
196 WARN_ON(rc < 0 && rc % 4 != 0);
197 rc = msi_bitmap_alloc_hwirqs(&bmp, 7);
198 WARN_ON(rc < 0 && rc % 8 != 0);
199 rc = msi_bitmap_alloc_hwirqs(&bmp, 121);
200 WARN_ON(rc < 0 && rc % 128 != 0);
196 201
197 msi_bitmap_free(&bmp); 202 msi_bitmap_free(&bmp);
198 203
199 /* Clients may check bitmap == NULL for "not-allocated" */ 204 /* Clients may WARN_ON bitmap == NULL for "not-allocated" */
200 check(bmp.bitmap == NULL); 205 WARN_ON(bmp.bitmap != NULL);
201 206
202 kfree(bmp.bitmap); 207 kfree(bmp.bitmap);
203} 208}
@@ -219,14 +224,13 @@ static void __init test_of_node(void)
219 of_node_init(&of_node); 224 of_node_init(&of_node);
220 of_node.full_name = node_name; 225 of_node.full_name = node_name;
221 226
222 check(0 == msi_bitmap_alloc(&bmp, size, &of_node)); 227 WARN_ON(msi_bitmap_alloc(&bmp, size, &of_node));
223 228
224 /* No msi-available-ranges, so expect > 0 */ 229 /* No msi-available-ranges, so expect > 0 */
225 check(msi_bitmap_reserve_dt_hwirqs(&bmp) > 0); 230 WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp) <= 0);
226 231
227 /* Should all still be free */ 232 /* Should all still be free */
228 check(0 == bitmap_find_free_region(bmp.bitmap, size, 233 WARN_ON(bitmap_find_free_region(bmp.bitmap, size, get_count_order(size)));
229 get_count_order(size)));
230 bitmap_release_region(bmp.bitmap, 0, get_count_order(size)); 234 bitmap_release_region(bmp.bitmap, 0, get_count_order(size));
231 235
232 /* Now create a fake msi-available-ranges property */ 236 /* Now create a fake msi-available-ranges property */
@@ -240,11 +244,11 @@ static void __init test_of_node(void)
240 of_node.properties = &prop; 244 of_node.properties = &prop;
241 245
242 /* msi-available-ranges, so expect == 0 */ 246 /* msi-available-ranges, so expect == 0 */
243 check(msi_bitmap_reserve_dt_hwirqs(&bmp) == 0); 247 WARN_ON(msi_bitmap_reserve_dt_hwirqs(&bmp));
244 248
245 /* Check we got the expected result */ 249 /* Check we got the expected result */
246 check(0 == bitmap_parselist(expected_str, expected, size)); 250 WARN_ON(bitmap_parselist(expected_str, expected, size));
247 check(bitmap_equal(expected, bmp.bitmap, size)); 251 WARN_ON(!bitmap_equal(expected, bmp.bitmap, size));
248 252
249 msi_bitmap_free(&bmp); 253 msi_bitmap_free(&bmp);
250 kfree(bmp.bitmap); 254 kfree(bmp.bitmap);