blob: f231f5ec74b633555decc0827a8d14d3ceba3d6d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * File...........: arch/s390/mm/extmem.c
3 * Author(s)......: Carsten Otte <cotte@de.ibm.com>
4 * Rob M van der Heij <rvdheij@nl.ibm.com>
5 * Steven Shultz <shultzss@us.ibm.com>
6 * Bugreports.to..: <Linux390@de.ibm.com>
7 * (C) IBM Corporation 2002-2004
8 */
9
10#include <linux/kernel.h>
11#include <linux/string.h>
12#include <linux/spinlock.h>
13#include <linux/list.h>
14#include <linux/slab.h>
15#include <linux/module.h>
16#include <linux/bootmem.h>
Heiko Carstens36a2bd42006-12-04 15:40:38 +010017#include <linux/ctype.h>
Gerald Schaefer444f0e52007-02-05 21:17:11 +010018#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/page.h>
Heiko Carstensf4eb07c2006-12-08 15:56:07 +010020#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/ebcdic.h>
22#include <asm/errno.h>
23#include <asm/extmem.h>
24#include <asm/cpcmd.h>
Heiko Carstens36a2bd42006-12-04 15:40:38 +010025#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#define DCSS_DEBUG /* Debug messages on/off */
28
29#define DCSS_NAME "extmem"
30#ifdef DCSS_DEBUG
31#define PRINT_DEBUG(x...) printk(KERN_DEBUG DCSS_NAME " debug:" x)
32#else
33#define PRINT_DEBUG(x...) do {} while (0)
34#endif
35#define PRINT_INFO(x...) printk(KERN_INFO DCSS_NAME " info:" x)
36#define PRINT_WARN(x...) printk(KERN_WARNING DCSS_NAME " warning:" x)
37#define PRINT_ERR(x...) printk(KERN_ERR DCSS_NAME " error:" x)
38
39
40#define DCSS_LOADSHR 0x00
41#define DCSS_LOADNSR 0x04
42#define DCSS_PURGESEG 0x08
43#define DCSS_FINDSEG 0x0c
44#define DCSS_LOADNOLY 0x10
45#define DCSS_SEGEXT 0x18
46#define DCSS_FINDSEGA 0x0c
47
48struct qrange {
49 unsigned int start; // 3byte start address, 1 byte type
50 unsigned int end; // 3byte end address, 1 byte reserved
51};
52
53struct qout64 {
54 int segstart;
55 int segend;
56 int segcnt;
57 int segrcnt;
58 struct qrange range[6];
59};
60
61struct qin64 {
62 char qopcode;
63 char rsrv1[3];
64 char qrcode;
65 char rsrv2[3];
66 char qname[8];
67 unsigned int qoutptr;
68 short int qoutlen;
69};
70
71struct dcss_segment {
72 struct list_head list;
73 char dcss_name[8];
Gerald Schaefer444f0e52007-02-05 21:17:11 +010074 char res_name[15];
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 unsigned long start_addr;
76 unsigned long end;
77 atomic_t ref_count;
78 int do_nonshared;
79 unsigned int vm_segtype;
80 struct qrange range[6];
81 int segcnt;
Gerald Schaefer444f0e52007-02-05 21:17:11 +010082 struct resource *res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083};
84
Heiko Carstens09252e72006-12-04 15:40:51 +010085static DEFINE_MUTEX(dcss_lock);
Denis Chengc11ca972008-01-26 14:11:13 +010086static LIST_HEAD(dcss_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static char *segtype_string[] = { "SW", "EW", "SR", "ER", "SN", "EN", "SC",
88 "EW/EN-MIXED" };
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090/*
91 * Create the 8 bytes, ebcdic VM segment name from
92 * an ascii name.
93 */
Heiko Carstens4d284ca2007-02-05 21:18:53 +010094static void
Linus Torvalds1da177e2005-04-16 15:20:36 -070095dcss_mkname(char *name, char *dcss_name)
96{
97 int i;
98
99 for (i = 0; i < 8; i++) {
100 if (name[i] == '\0')
101 break;
102 dcss_name[i] = toupper(name[i]);
103 };
104 for (; i < 8; i++)
105 dcss_name[i] = ' ';
106 ASCEBC(dcss_name, 8);
107}
108
109
110/*
111 * search all segments in dcss_list, and return the one
112 * namend *name. If not found, return NULL.
113 */
114static struct dcss_segment *
115segment_by_name (char *name)
116{
117 char dcss_name[9];
118 struct list_head *l;
119 struct dcss_segment *tmp, *retval = NULL;
120
Heiko Carstens09252e72006-12-04 15:40:51 +0100121 BUG_ON(!mutex_is_locked(&dcss_lock));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 dcss_mkname (name, dcss_name);
123 list_for_each (l, &dcss_list) {
124 tmp = list_entry (l, struct dcss_segment, list);
125 if (memcmp(tmp->dcss_name, dcss_name, 8) == 0) {
126 retval = tmp;
127 break;
128 }
129 }
130 return retval;
131}
132
133
134/*
135 * Perform a function on a dcss segment.
136 */
137static inline int
138dcss_diag (__u8 func, void *parameter,
139 unsigned long *ret1, unsigned long *ret2)
140{
141 unsigned long rx, ry;
142 int rc;
143
144 rx = (unsigned long) parameter;
145 ry = (unsigned long) func;
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200146 asm volatile(
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800147#ifdef CONFIG_64BIT
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200148 " sam31\n"
149 " diag %0,%1,0x64\n"
150 " sam64\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#else
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200152 " diag %0,%1,0x64\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#endif
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200154 " ipm %2\n"
155 " srl %2,28\n"
156 : "+d" (rx), "+d" (ry), "=d" (rc) : : "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 *ret1 = rx;
158 *ret2 = ry;
159 return rc;
160}
161
162static inline int
163dcss_diag_translate_rc (int vm_rc) {
164 if (vm_rc == 44)
165 return -ENOENT;
166 return -EIO;
167}
168
169
170/* do a diag to get info about a segment.
171 * fills start_address, end and vm_segtype fields
172 */
173static int
174query_segment_type (struct dcss_segment *seg)
175{
176 struct qin64 *qin = kmalloc (sizeof(struct qin64), GFP_DMA);
177 struct qout64 *qout = kmalloc (sizeof(struct qout64), GFP_DMA);
178
179 int diag_cc, rc, i;
180 unsigned long dummy, vmrc;
181
182 if ((qin == NULL) || (qout == NULL)) {
183 rc = -ENOMEM;
184 goto out_free;
185 }
186
187 /* initialize diag input parameters */
188 qin->qopcode = DCSS_FINDSEGA;
189 qin->qoutptr = (unsigned long) qout;
190 qin->qoutlen = sizeof(struct qout64);
191 memcpy (qin->qname, seg->dcss_name, 8);
192
193 diag_cc = dcss_diag (DCSS_SEGEXT, qin, &dummy, &vmrc);
194
195 if (diag_cc > 1) {
Gerald Schaefer9b5dec12006-04-27 18:40:22 -0700196 PRINT_WARN ("segment_type: diag returned error %ld\n", vmrc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 rc = dcss_diag_translate_rc (vmrc);
198 goto out_free;
199 }
200
201 if (qout->segcnt > 6) {
202 rc = -ENOTSUPP;
203 goto out_free;
204 }
205
206 if (qout->segcnt == 1) {
207 seg->vm_segtype = qout->range[0].start & 0xff;
208 } else {
209 /* multi-part segment. only one type supported here:
210 - all parts are contiguous
211 - all parts are either EW or EN type
212 - maximum 6 parts allowed */
213 unsigned long start = qout->segstart >> PAGE_SHIFT;
214 for (i=0; i<qout->segcnt; i++) {
215 if (((qout->range[i].start & 0xff) != SEG_TYPE_EW) &&
216 ((qout->range[i].start & 0xff) != SEG_TYPE_EN)) {
217 rc = -ENOTSUPP;
218 goto out_free;
219 }
220 if (start != qout->range[i].start >> PAGE_SHIFT) {
221 rc = -ENOTSUPP;
222 goto out_free;
223 }
224 start = (qout->range[i].end >> PAGE_SHIFT) + 1;
225 }
226 seg->vm_segtype = SEG_TYPE_EWEN;
227 }
228
229 /* analyze diag output and update seg */
230 seg->start_addr = qout->segstart;
231 seg->end = qout->segend;
232
233 memcpy (seg->range, qout->range, 6*sizeof(struct qrange));
234 seg->segcnt = qout->segcnt;
235
236 rc = 0;
237
238 out_free:
Jesper Juhlb2325fe2005-11-07 01:01:35 -0800239 kfree(qin);
240 kfree(qout);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return rc;
242}
243
244/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 * get info about a segment
246 * possible return values:
247 * -ENOSYS : we are not running on VM
248 * -EIO : could not perform query diagnose
249 * -ENOENT : no such segment
250 * -ENOTSUPP: multi-part segment cannot be used with linux
251 * -ENOSPC : segment cannot be used (overlaps with storage)
252 * -ENOMEM : out of memory
253 * 0 .. 6 : type of segment as defined in include/asm-s390/extmem.h
254 */
255int
256segment_type (char* name)
257{
258 int rc;
259 struct dcss_segment seg;
260
261 if (!MACHINE_IS_VM)
262 return -ENOSYS;
263
264 dcss_mkname(name, seg.dcss_name);
265 rc = query_segment_type (&seg);
266 if (rc < 0)
267 return rc;
268 return seg.vm_segtype;
269}
270
271/*
272 * real segment loading function, called from segment_load
273 */
274static int
275__segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long *end)
276{
277 struct dcss_segment *seg = kmalloc(sizeof(struct dcss_segment),
278 GFP_DMA);
279 int dcss_command, rc, diag_cc;
280
281 if (seg == NULL) {
282 rc = -ENOMEM;
283 goto out;
284 }
285 dcss_mkname (name, seg->dcss_name);
286 rc = query_segment_type (seg);
287 if (rc < 0)
288 goto out_free;
Heiko Carstensf4eb07c2006-12-08 15:56:07 +0100289
Heiko Carstens17f34582008-04-30 13:38:47 +0200290 rc = vmem_add_mapping(seg->start_addr, seg->end - seg->start_addr + 1);
Heiko Carstensf4eb07c2006-12-08 15:56:07 +0100291
Martin Schwidefskyca683052008-04-17 07:46:31 +0200292 if (rc)
Heiko Carstensf4eb07c2006-12-08 15:56:07 +0100293 goto out_free;
Heiko Carstensf4eb07c2006-12-08 15:56:07 +0100294
Gerald Schaefer444f0e52007-02-05 21:17:11 +0100295 seg->res = kzalloc(sizeof(struct resource), GFP_KERNEL);
296 if (seg->res == NULL) {
297 rc = -ENOMEM;
298 goto out_shared;
299 }
300 seg->res->flags = IORESOURCE_BUSY | IORESOURCE_MEM;
301 seg->res->start = seg->start_addr;
302 seg->res->end = seg->end;
303 memcpy(&seg->res_name, seg->dcss_name, 8);
304 EBCASC(seg->res_name, 8);
305 seg->res_name[8] = '\0';
306 strncat(seg->res_name, " (DCSS)", 7);
307 seg->res->name = seg->res_name;
308 rc = seg->vm_segtype;
309 if (rc == SEG_TYPE_SC ||
310 ((rc == SEG_TYPE_SR || rc == SEG_TYPE_ER) && !do_nonshared))
311 seg->res->flags |= IORESOURCE_READONLY;
312 if (request_resource(&iomem_resource, seg->res)) {
313 rc = -EBUSY;
314 kfree(seg->res);
315 goto out_shared;
316 }
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 if (do_nonshared)
319 dcss_command = DCSS_LOADNSR;
320 else
321 dcss_command = DCSS_LOADNOLY;
322
323 diag_cc = dcss_diag(dcss_command, seg->dcss_name,
324 &seg->start_addr, &seg->end);
325 if (diag_cc > 1) {
326 PRINT_WARN ("segment_load: could not load segment %s - "
327 "diag returned error (%ld)\n",name,seg->end);
328 rc = dcss_diag_translate_rc (seg->end);
329 dcss_diag(DCSS_PURGESEG, seg->dcss_name,
330 &seg->start_addr, &seg->end);
Gerald Schaefer444f0e52007-02-05 21:17:11 +0100331 goto out_resource;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 }
333 seg->do_nonshared = do_nonshared;
334 atomic_set(&seg->ref_count, 1);
335 list_add(&seg->list, &dcss_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 *addr = seg->start_addr;
337 *end = seg->end;
338 if (do_nonshared)
339 PRINT_INFO ("segment_load: loaded segment %s range %p .. %p "
340 "type %s in non-shared mode\n", name,
341 (void*)seg->start_addr, (void*)seg->end,
342 segtype_string[seg->vm_segtype]);
Gerald Schaefer444f0e52007-02-05 21:17:11 +0100343 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 PRINT_INFO ("segment_load: loaded segment %s range %p .. %p "
345 "type %s in shared mode\n", name,
346 (void*)seg->start_addr, (void*)seg->end,
347 segtype_string[seg->vm_segtype]);
Gerald Schaefer444f0e52007-02-05 21:17:11 +0100348 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 goto out;
Gerald Schaefer444f0e52007-02-05 21:17:11 +0100350 out_resource:
351 release_resource(seg->res);
352 kfree(seg->res);
Heiko Carstensf4eb07c2006-12-08 15:56:07 +0100353 out_shared:
Heiko Carstens17f34582008-04-30 13:38:47 +0200354 vmem_remove_mapping(seg->start_addr, seg->end - seg->start_addr + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 out_free:
Jesper Juhlb2325fe2005-11-07 01:01:35 -0800356 kfree(seg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 out:
358 return rc;
359}
360
361/*
362 * this function loads a DCSS segment
363 * name : name of the DCSS
364 * do_nonshared : 0 indicates that the dcss should be shared with other linux images
365 * 1 indicates that the dcss should be exclusive for this linux image
366 * addr : will be filled with start address of the segment
367 * end : will be filled with end address of the segment
368 * return values:
369 * -ENOSYS : we are not running on VM
370 * -EIO : could not perform query or load diagnose
371 * -ENOENT : no such segment
372 * -ENOTSUPP: multi-part segment cannot be used with linux
373 * -ENOSPC : segment cannot be used (overlaps with storage)
374 * -EBUSY : segment can temporarily not be used (overlaps with dcss)
375 * -ERANGE : segment cannot be used (exceeds kernel mapping range)
376 * -EPERM : segment is currently loaded with incompatible permissions
377 * -ENOMEM : out of memory
378 * 0 .. 6 : type of segment as defined in include/asm-s390/extmem.h
379 */
380int
381segment_load (char *name, int do_nonshared, unsigned long *addr,
382 unsigned long *end)
383{
384 struct dcss_segment *seg;
385 int rc;
386
387 if (!MACHINE_IS_VM)
388 return -ENOSYS;
389
Heiko Carstens09252e72006-12-04 15:40:51 +0100390 mutex_lock(&dcss_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 seg = segment_by_name (name);
392 if (seg == NULL)
393 rc = __segment_load (name, do_nonshared, addr, end);
394 else {
395 if (do_nonshared == seg->do_nonshared) {
396 atomic_inc(&seg->ref_count);
397 *addr = seg->start_addr;
398 *end = seg->end;
399 rc = seg->vm_segtype;
400 } else {
401 *addr = *end = 0;
402 rc = -EPERM;
403 }
404 }
Heiko Carstens09252e72006-12-04 15:40:51 +0100405 mutex_unlock(&dcss_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 return rc;
407}
408
409/*
410 * this function modifies the shared state of a DCSS segment. note that
411 * name : name of the DCSS
412 * do_nonshared : 0 indicates that the dcss should be shared with other linux images
413 * 1 indicates that the dcss should be exclusive for this linux image
414 * return values:
415 * -EIO : could not perform load diagnose (segment gone!)
416 * -ENOENT : no such segment (segment gone!)
417 * -EAGAIN : segment is in use by other exploiters, try later
418 * -EINVAL : no segment with the given name is currently loaded - name invalid
Gerald Schaefer444f0e52007-02-05 21:17:11 +0100419 * -EBUSY : segment can temporarily not be used (overlaps with dcss)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 * 0 : operation succeeded
421 */
422int
423segment_modify_shared (char *name, int do_nonshared)
424{
425 struct dcss_segment *seg;
426 unsigned long dummy;
427 int dcss_command, rc, diag_cc;
428
Heiko Carstens09252e72006-12-04 15:40:51 +0100429 mutex_lock(&dcss_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 seg = segment_by_name (name);
431 if (seg == NULL) {
432 rc = -EINVAL;
433 goto out_unlock;
434 }
435 if (do_nonshared == seg->do_nonshared) {
436 PRINT_INFO ("segment_modify_shared: not reloading segment %s"
437 " - already in requested mode\n",name);
438 rc = 0;
439 goto out_unlock;
440 }
441 if (atomic_read (&seg->ref_count) != 1) {
442 PRINT_WARN ("segment_modify_shared: not reloading segment %s - "
443 "segment is in use by other driver(s)\n",name);
444 rc = -EAGAIN;
445 goto out_unlock;
446 }
Gerald Schaefer444f0e52007-02-05 21:17:11 +0100447 release_resource(seg->res);
448 if (do_nonshared) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 dcss_command = DCSS_LOADNSR;
Gerald Schaefer444f0e52007-02-05 21:17:11 +0100450 seg->res->flags &= ~IORESOURCE_READONLY;
451 } else {
452 dcss_command = DCSS_LOADNOLY;
453 if (seg->vm_segtype == SEG_TYPE_SR ||
454 seg->vm_segtype == SEG_TYPE_ER)
455 seg->res->flags |= IORESOURCE_READONLY;
456 }
457 if (request_resource(&iomem_resource, seg->res)) {
458 PRINT_WARN("segment_modify_shared: could not reload segment %s"
459 " - overlapping resources\n", name);
460 rc = -EBUSY;
461 kfree(seg->res);
462 goto out_del;
463 }
464 dcss_diag(DCSS_PURGESEG, seg->dcss_name, &dummy, &dummy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 diag_cc = dcss_diag(dcss_command, seg->dcss_name,
466 &seg->start_addr, &seg->end);
467 if (diag_cc > 1) {
468 PRINT_WARN ("segment_modify_shared: could not reload segment %s"
469 " - diag returned error (%ld)\n",name,seg->end);
470 rc = dcss_diag_translate_rc (seg->end);
471 goto out_del;
472 }
473 seg->do_nonshared = do_nonshared;
474 rc = 0;
475 goto out_unlock;
476 out_del:
Heiko Carstens17f34582008-04-30 13:38:47 +0200477 vmem_remove_mapping(seg->start_addr, seg->end - seg->start_addr + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 list_del(&seg->list);
Gerald Schaefer444f0e52007-02-05 21:17:11 +0100479 dcss_diag(DCSS_PURGESEG, seg->dcss_name, &dummy, &dummy);
Jesper Juhlb2325fe2005-11-07 01:01:35 -0800480 kfree(seg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 out_unlock:
Heiko Carstens09252e72006-12-04 15:40:51 +0100482 mutex_unlock(&dcss_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 return rc;
484}
485
486/*
487 * Decrease the use count of a DCSS segment and remove
488 * it from the address space if nobody is using it
489 * any longer.
490 */
491void
492segment_unload(char *name)
493{
494 unsigned long dummy;
495 struct dcss_segment *seg;
496
497 if (!MACHINE_IS_VM)
498 return;
499
Heiko Carstens09252e72006-12-04 15:40:51 +0100500 mutex_lock(&dcss_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 seg = segment_by_name (name);
502 if (seg == NULL) {
503 PRINT_ERR ("could not find segment %s in segment_unload, "
504 "please report to linux390@de.ibm.com\n",name);
505 goto out_unlock;
506 }
Heiko Carstensf4eb07c2006-12-08 15:56:07 +0100507 if (atomic_dec_return(&seg->ref_count) != 0)
508 goto out_unlock;
Gerald Schaefer444f0e52007-02-05 21:17:11 +0100509 release_resource(seg->res);
510 kfree(seg->res);
Heiko Carstens17f34582008-04-30 13:38:47 +0200511 vmem_remove_mapping(seg->start_addr, seg->end - seg->start_addr + 1);
Heiko Carstensf4eb07c2006-12-08 15:56:07 +0100512 list_del(&seg->list);
513 dcss_diag(DCSS_PURGESEG, seg->dcss_name, &dummy, &dummy);
514 kfree(seg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515out_unlock:
Heiko Carstens09252e72006-12-04 15:40:51 +0100516 mutex_unlock(&dcss_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517}
518
519/*
520 * save segment content permanently
521 */
522void
523segment_save(char *name)
524{
525 struct dcss_segment *seg;
526 int startpfn = 0;
527 int endpfn = 0;
528 char cmd1[160];
529 char cmd2[80];
Gerald Schaefer9b5dec12006-04-27 18:40:22 -0700530 int i, response;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532 if (!MACHINE_IS_VM)
533 return;
534
Heiko Carstens09252e72006-12-04 15:40:51 +0100535 mutex_lock(&dcss_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 seg = segment_by_name (name);
537
538 if (seg == NULL) {
Heiko Carstens6b4044b2006-12-04 15:40:20 +0100539 PRINT_ERR("could not find segment %s in segment_save, please "
540 "report to linux390@de.ibm.com\n", name);
541 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 }
543
544 startpfn = seg->start_addr >> PAGE_SHIFT;
545 endpfn = (seg->end) >> PAGE_SHIFT;
546 sprintf(cmd1, "DEFSEG %s", name);
547 for (i=0; i<seg->segcnt; i++) {
548 sprintf(cmd1+strlen(cmd1), " %X-%X %s",
549 seg->range[i].start >> PAGE_SHIFT,
550 seg->range[i].end >> PAGE_SHIFT,
551 segtype_string[seg->range[i].start & 0xff]);
552 }
553 sprintf(cmd2, "SAVESEG %s", name);
Gerald Schaefer9b5dec12006-04-27 18:40:22 -0700554 response = 0;
555 cpcmd(cmd1, NULL, 0, &response);
556 if (response) {
557 PRINT_ERR("segment_save: DEFSEG failed with response code %i\n",
558 response);
559 goto out;
560 }
561 cpcmd(cmd2, NULL, 0, &response);
562 if (response) {
563 PRINT_ERR("segment_save: SAVESEG failed with response code %i\n",
564 response);
565 goto out;
566 }
567out:
Heiko Carstens09252e72006-12-04 15:40:51 +0100568 mutex_unlock(&dcss_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569}
570
Martin Schwidefskyca683052008-04-17 07:46:31 +0200571/*
572 * print appropriate error message for segment_load()/segment_type()
573 * return code
574 */
575void segment_warning(int rc, char *seg_name)
576{
577 switch (rc) {
578 case -ENOENT:
579 PRINT_WARN("cannot load/query segment %s, "
580 "does not exist\n", seg_name);
581 break;
582 case -ENOSYS:
583 PRINT_WARN("cannot load/query segment %s, "
584 "not running on VM\n", seg_name);
585 break;
586 case -EIO:
587 PRINT_WARN("cannot load/query segment %s, "
588 "hardware error\n", seg_name);
589 break;
590 case -ENOTSUPP:
591 PRINT_WARN("cannot load/query segment %s, "
592 "is a multi-part segment\n", seg_name);
593 break;
594 case -ENOSPC:
595 PRINT_WARN("cannot load/query segment %s, "
596 "overlaps with storage\n", seg_name);
597 break;
598 case -EBUSY:
599 PRINT_WARN("cannot load/query segment %s, "
600 "overlaps with already loaded dcss\n", seg_name);
601 break;
602 case -EPERM:
603 PRINT_WARN("cannot load/query segment %s, "
604 "already loaded in incompatible mode\n", seg_name);
605 break;
606 case -ENOMEM:
607 PRINT_WARN("cannot load/query segment %s, "
608 "out of memory\n", seg_name);
609 break;
610 case -ERANGE:
611 PRINT_WARN("cannot load/query segment %s, "
612 "exceeds kernel mapping range\n", seg_name);
613 break;
614 default:
615 PRINT_WARN("cannot load/query segment %s, "
616 "return value %i\n", seg_name, rc);
617 break;
618 }
619}
620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621EXPORT_SYMBOL(segment_load);
622EXPORT_SYMBOL(segment_unload);
623EXPORT_SYMBOL(segment_save);
624EXPORT_SYMBOL(segment_type);
625EXPORT_SYMBOL(segment_modify_shared);
Martin Schwidefskyca683052008-04-17 07:46:31 +0200626EXPORT_SYMBOL(segment_warning);