1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50#undef PDCS_DEBUG
51#ifdef PDCS_DEBUG
52#define DPRINTK(fmt, args...) printk(KERN_DEBUG fmt, ## args)
53#else
54#define DPRINTK(fmt, args...)
55#endif
56
57#include <linux/module.h>
58#include <linux/init.h>
59#include <linux/kernel.h>
60#include <linux/string.h>
61#include <linux/capability.h>
62#include <linux/ctype.h>
63#include <linux/sysfs.h>
64#include <linux/kobject.h>
65#include <linux/device.h>
66#include <linux/errno.h>
67#include <linux/spinlock.h>
68
69#include <asm/pdc.h>
70#include <asm/page.h>
71#include <linux/uaccess.h>
72#include <asm/hardware.h>
73
74#define PDCS_VERSION "0.30"
75#define PDCS_PREFIX "PDC Stable Storage"
76
77#define PDCS_ADDR_PPRI 0x00
78#define PDCS_ADDR_OSID 0x40
79#define PDCS_ADDR_OSD1 0x48
80#define PDCS_ADDR_DIAG 0x58
81#define PDCS_ADDR_FSIZ 0x5C
82#define PDCS_ADDR_PCON 0x60
83#define PDCS_ADDR_PALT 0x80
84#define PDCS_ADDR_PKBD 0xA0
85#define PDCS_ADDR_OSD2 0xE0
86
87MODULE_AUTHOR("Thibaut VARENE <varenet@parisc-linux.org>");
88MODULE_DESCRIPTION("sysfs interface to HP PDC Stable Storage data");
89MODULE_LICENSE("GPL");
90MODULE_VERSION(PDCS_VERSION);
91
92
93static unsigned long pdcs_size __read_mostly;
94
95
96static u16 pdcs_osid __read_mostly;
97
98
99struct pdcspath_entry {
100 rwlock_t rw_lock;
101 short ready;
102 unsigned long addr;
103 char *name;
104 struct device_path devpath;
105 struct device *dev;
106 struct kobject kobj;
107};
108
109struct pdcspath_attribute {
110 struct attribute attr;
111 ssize_t (*show)(struct pdcspath_entry *entry, char *buf);
112 ssize_t (*store)(struct pdcspath_entry *entry, const char *buf, size_t count);
113};
114
115#define PDCSPATH_ENTRY(_addr, _name) \
116struct pdcspath_entry pdcspath_entry_##_name = { \
117 .ready = 0, \
118 .addr = _addr, \
119 .name = __stringify(_name), \
120};
121
122#define PDCS_ATTR(_name, _mode, _show, _store) \
123struct kobj_attribute pdcs_attr_##_name = { \
124 .attr = {.name = __stringify(_name), .mode = _mode}, \
125 .show = _show, \
126 .store = _store, \
127};
128
129#define PATHS_ATTR(_name, _mode, _show, _store) \
130struct pdcspath_attribute paths_attr_##_name = { \
131 .attr = {.name = __stringify(_name), .mode = _mode}, \
132 .show = _show, \
133 .store = _store, \
134};
135
136#define to_pdcspath_attribute(_attr) container_of(_attr, struct pdcspath_attribute, attr)
137#define to_pdcspath_entry(obj) container_of(obj, struct pdcspath_entry, kobj)
138
139
140
141
142
143
144
145
146
147
148
149
150
151static int
152pdcspath_fetch(struct pdcspath_entry *entry)
153{
154 struct device_path *devpath;
155
156 if (!entry)
157 return -EINVAL;
158
159 devpath = &entry->devpath;
160
161 DPRINTK("%s: fetch: 0x%p, 0x%p, addr: 0x%lx\n", __func__,
162 entry, devpath, entry->addr);
163
164
165 if (pdc_stable_read(entry->addr, devpath, sizeof(*devpath)) != PDC_OK)
166 return -EIO;
167
168
169
170
171 entry->dev = hwpath_to_device((struct hardware_path *)devpath);
172
173 entry->ready = 1;
174
175 DPRINTK("%s: device: 0x%p\n", __func__, entry->dev);
176
177 return 0;
178}
179
180
181
182
183
184
185
186
187
188
189
190
191
192static void
193pdcspath_store(struct pdcspath_entry *entry)
194{
195 struct device_path *devpath;
196
197 BUG_ON(!entry);
198
199 devpath = &entry->devpath;
200
201
202
203
204 if (!entry->ready) {
205
206 BUG_ON(!entry->dev);
207 device_to_hwpath(entry->dev, (struct hardware_path *)devpath);
208 }
209
210
211 DPRINTK("%s: store: 0x%p, 0x%p, addr: 0x%lx\n", __func__,
212 entry, devpath, entry->addr);
213
214
215 if (pdc_stable_write(entry->addr, devpath, sizeof(*devpath)) != PDC_OK)
216 WARN(1, KERN_ERR "%s: an error occurred when writing to PDC.\n"
217 "It is likely that the Stable Storage data has been corrupted.\n"
218 "Please check it carefully upon next reboot.\n", __func__);
219
220
221 entry->ready = 2;
222
223 DPRINTK("%s: device: 0x%p\n", __func__, entry->dev);
224}
225
226
227
228
229
230
231
232
233static ssize_t
234pdcspath_hwpath_read(struct pdcspath_entry *entry, char *buf)
235{
236 char *out = buf;
237 struct device_path *devpath;
238 short i;
239
240 if (!entry || !buf)
241 return -EINVAL;
242
243 read_lock(&entry->rw_lock);
244 devpath = &entry->devpath;
245 i = entry->ready;
246 read_unlock(&entry->rw_lock);
247
248 if (!i)
249 return -ENODATA;
250
251 for (i = 0; i < 6; i++) {
252 if (devpath->bc[i] >= 128)
253 continue;
254 out += sprintf(out, "%u/", (unsigned char)devpath->bc[i]);
255 }
256 out += sprintf(out, "%u\n", (unsigned char)devpath->mod);
257
258 return out - buf;
259}
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276static ssize_t
277pdcspath_hwpath_write(struct pdcspath_entry *entry, const char *buf, size_t count)
278{
279 struct hardware_path hwpath;
280 unsigned short i;
281 char in[64], *temp;
282 struct device *dev;
283 int ret;
284
285 if (!entry || !buf || !count)
286 return -EINVAL;
287
288
289 count = min_t(size_t, count, sizeof(in)-1);
290 strncpy(in, buf, count);
291 in[count] = '\0';
292
293
294 memset(&hwpath, 0xff, sizeof(hwpath));
295
296
297 if (!(temp = strrchr(in, '/')))
298 return -EINVAL;
299
300 hwpath.mod = simple_strtoul(temp+1, NULL, 10);
301 in[temp-in] = '\0';
302 DPRINTK("%s: mod: %d\n", __func__, hwpath.mod);
303
304
305
306
307
308
309 for (i=5; ((temp = strrchr(in, '/'))) && (temp-in > 0) && (likely(i)); i--) {
310 hwpath.bc[i] = simple_strtoul(temp+1, NULL, 10);
311 in[temp-in] = '\0';
312 DPRINTK("%s: bc[%d]: %d\n", __func__, i, hwpath.bc[i]);
313 }
314
315
316 hwpath.bc[i] = simple_strtoul(in, NULL, 10);
317 DPRINTK("%s: bc[%d]: %d\n", __func__, i, hwpath.bc[i]);
318
319
320 if (!(dev = hwpath_to_device((struct hardware_path *)&hwpath))) {
321 printk(KERN_WARNING "%s: attempt to set invalid \"%s\" "
322 "hardware path: %s\n", __func__, entry->name, buf);
323 return -EINVAL;
324 }
325
326
327 write_lock(&entry->rw_lock);
328 entry->ready = 0;
329 entry->dev = dev;
330
331
332 pdcspath_store(entry);
333
334
335 sysfs_remove_link(&entry->kobj, "device");
336 write_unlock(&entry->rw_lock);
337
338 ret = sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device");
339 WARN_ON(ret);
340
341 printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" path to \"%s\"\n",
342 entry->name, buf);
343
344 return count;
345}
346
347
348
349
350
351
352
353
354static ssize_t
355pdcspath_layer_read(struct pdcspath_entry *entry, char *buf)
356{
357 char *out = buf;
358 struct device_path *devpath;
359 short i;
360
361 if (!entry || !buf)
362 return -EINVAL;
363
364 read_lock(&entry->rw_lock);
365 devpath = &entry->devpath;
366 i = entry->ready;
367 read_unlock(&entry->rw_lock);
368
369 if (!i)
370 return -ENODATA;
371
372 for (i = 0; i < 6 && devpath->layers[i]; i++)
373 out += sprintf(out, "%u ", devpath->layers[i]);
374
375 out += sprintf(out, "\n");
376
377 return out - buf;
378}
379
380
381
382
383
384
385
386
387
388
389
390
391
392static ssize_t
393pdcspath_layer_write(struct pdcspath_entry *entry, const char *buf, size_t count)
394{
395 unsigned int layers[6];
396 unsigned short i;
397 char in[64], *temp;
398
399 if (!entry || !buf || !count)
400 return -EINVAL;
401
402
403 count = min_t(size_t, count, sizeof(in)-1);
404 strncpy(in, buf, count);
405 in[count] = '\0';
406
407
408 memset(&layers, 0, sizeof(layers));
409
410
411 if (unlikely(!isdigit(*in)))
412 return -EINVAL;
413 layers[0] = simple_strtoul(in, NULL, 10);
414 DPRINTK("%s: layer[0]: %d\n", __func__, layers[0]);
415
416 temp = in;
417 for (i=1; ((temp = strchr(temp, '.'))) && (likely(i<6)); i++) {
418 if (unlikely(!isdigit(*(++temp))))
419 return -EINVAL;
420 layers[i] = simple_strtoul(temp, NULL, 10);
421 DPRINTK("%s: layer[%d]: %d\n", __func__, i, layers[i]);
422 }
423
424
425 write_lock(&entry->rw_lock);
426
427
428
429 memcpy(&entry->devpath.layers, &layers, sizeof(layers));
430
431
432 pdcspath_store(entry);
433 write_unlock(&entry->rw_lock);
434
435 printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" layers to \"%s\"\n",
436 entry->name, buf);
437
438 return count;
439}
440
441
442
443
444
445
446
447static ssize_t
448pdcspath_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
449{
450 struct pdcspath_entry *entry = to_pdcspath_entry(kobj);
451 struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr);
452 ssize_t ret = 0;
453
454 if (pdcs_attr->show)
455 ret = pdcs_attr->show(entry, buf);
456
457 return ret;
458}
459
460
461
462
463
464
465
466
467static ssize_t
468pdcspath_attr_store(struct kobject *kobj, struct attribute *attr,
469 const char *buf, size_t count)
470{
471 struct pdcspath_entry *entry = to_pdcspath_entry(kobj);
472 struct pdcspath_attribute *pdcs_attr = to_pdcspath_attribute(attr);
473 ssize_t ret = 0;
474
475 if (!capable(CAP_SYS_ADMIN))
476 return -EACCES;
477
478 if (pdcs_attr->store)
479 ret = pdcs_attr->store(entry, buf, count);
480
481 return ret;
482}
483
484static const struct sysfs_ops pdcspath_attr_ops = {
485 .show = pdcspath_attr_show,
486 .store = pdcspath_attr_store,
487};
488
489
490static PATHS_ATTR(hwpath, 0644, pdcspath_hwpath_read, pdcspath_hwpath_write);
491static PATHS_ATTR(layer, 0644, pdcspath_layer_read, pdcspath_layer_write);
492
493static struct attribute *paths_subsys_attrs[] = {
494 &paths_attr_hwpath.attr,
495 &paths_attr_layer.attr,
496 NULL,
497};
498
499
500static struct kobj_type ktype_pdcspath = {
501 .sysfs_ops = &pdcspath_attr_ops,
502 .default_attrs = paths_subsys_attrs,
503};
504
505
506static PDCSPATH_ENTRY(PDCS_ADDR_PPRI, primary);
507static PDCSPATH_ENTRY(PDCS_ADDR_PCON, console);
508static PDCSPATH_ENTRY(PDCS_ADDR_PALT, alternative);
509static PDCSPATH_ENTRY(PDCS_ADDR_PKBD, keyboard);
510
511
512static struct pdcspath_entry *pdcspath_entries[] = {
513 &pdcspath_entry_primary,
514 &pdcspath_entry_alternative,
515 &pdcspath_entry_console,
516 &pdcspath_entry_keyboard,
517 NULL,
518};
519
520
521
522
523
524
525
526
527
528static ssize_t pdcs_size_read(struct kobject *kobj,
529 struct kobj_attribute *attr,
530 char *buf)
531{
532 char *out = buf;
533
534 if (!buf)
535 return -EINVAL;
536
537
538 out += sprintf(out, "%ld\n", pdcs_size);
539
540 return out - buf;
541}
542
543
544
545
546
547
548static ssize_t pdcs_auto_read(struct kobject *kobj,
549 struct kobj_attribute *attr,
550 char *buf, int knob)
551{
552 char *out = buf;
553 struct pdcspath_entry *pathentry;
554
555 if (!buf)
556 return -EINVAL;
557
558
559 pathentry = &pdcspath_entry_primary;
560
561 read_lock(&pathentry->rw_lock);
562 out += sprintf(out, "%s\n", (pathentry->devpath.flags & knob) ?
563 "On" : "Off");
564 read_unlock(&pathentry->rw_lock);
565
566 return out - buf;
567}
568
569
570
571
572
573static ssize_t pdcs_autoboot_read(struct kobject *kobj,
574 struct kobj_attribute *attr, char *buf)
575{
576 return pdcs_auto_read(kobj, attr, buf, PF_AUTOBOOT);
577}
578
579
580
581
582
583static ssize_t pdcs_autosearch_read(struct kobject *kobj,
584 struct kobj_attribute *attr, char *buf)
585{
586 return pdcs_auto_read(kobj, attr, buf, PF_AUTOSEARCH);
587}
588
589
590
591
592
593
594
595static ssize_t pdcs_timer_read(struct kobject *kobj,
596 struct kobj_attribute *attr, char *buf)
597{
598 char *out = buf;
599 struct pdcspath_entry *pathentry;
600
601 if (!buf)
602 return -EINVAL;
603
604
605 pathentry = &pdcspath_entry_primary;
606
607
608 read_lock(&pathentry->rw_lock);
609 out += sprintf(out, "%u\n", (pathentry->devpath.flags & PF_TIMER) ?
610 (1 << (pathentry->devpath.flags & PF_TIMER)) : 0);
611 read_unlock(&pathentry->rw_lock);
612
613 return out - buf;
614}
615
616
617
618
619
620static ssize_t pdcs_osid_read(struct kobject *kobj,
621 struct kobj_attribute *attr, char *buf)
622{
623 char *out = buf;
624
625 if (!buf)
626 return -EINVAL;
627
628 out += sprintf(out, "%s dependent data (0x%.4x)\n",
629 os_id_to_string(pdcs_osid), pdcs_osid);
630
631 return out - buf;
632}
633
634
635
636
637
638
639
640static ssize_t pdcs_osdep1_read(struct kobject *kobj,
641 struct kobj_attribute *attr, char *buf)
642{
643 char *out = buf;
644 u32 result[4];
645
646 if (!buf)
647 return -EINVAL;
648
649 if (pdc_stable_read(PDCS_ADDR_OSD1, &result, sizeof(result)) != PDC_OK)
650 return -EIO;
651
652 out += sprintf(out, "0x%.8x\n", result[0]);
653 out += sprintf(out, "0x%.8x\n", result[1]);
654 out += sprintf(out, "0x%.8x\n", result[2]);
655 out += sprintf(out, "0x%.8x\n", result[3]);
656
657 return out - buf;
658}
659
660
661
662
663
664
665
666static ssize_t pdcs_diagnostic_read(struct kobject *kobj,
667 struct kobj_attribute *attr, char *buf)
668{
669 char *out = buf;
670 u32 result;
671
672 if (!buf)
673 return -EINVAL;
674
675
676 if (pdc_stable_read(PDCS_ADDR_DIAG, &result, sizeof(result)) != PDC_OK)
677 return -EIO;
678
679 out += sprintf(out, "0x%.4x\n", (result >> 16));
680
681 return out - buf;
682}
683
684
685
686
687
688
689
690static ssize_t pdcs_fastsize_read(struct kobject *kobj,
691 struct kobj_attribute *attr, char *buf)
692{
693 char *out = buf;
694 u32 result;
695
696 if (!buf)
697 return -EINVAL;
698
699
700 if (pdc_stable_read(PDCS_ADDR_FSIZ, &result, sizeof(result)) != PDC_OK)
701 return -EIO;
702
703 if ((result & 0x0F) < 0x0E)
704 out += sprintf(out, "%d kB", (1<<(result & 0x0F))*256);
705 else
706 out += sprintf(out, "All");
707 out += sprintf(out, "\n");
708
709 return out - buf;
710}
711
712
713
714
715
716
717
718static ssize_t pdcs_osdep2_read(struct kobject *kobj,
719 struct kobj_attribute *attr, char *buf)
720{
721 char *out = buf;
722 unsigned long size;
723 unsigned short i;
724 u32 result;
725
726 if (unlikely(pdcs_size <= 224))
727 return -ENODATA;
728
729 size = pdcs_size - 224;
730
731 if (!buf)
732 return -EINVAL;
733
734 for (i=0; i<size; i+=4) {
735 if (unlikely(pdc_stable_read(PDCS_ADDR_OSD2 + i, &result,
736 sizeof(result)) != PDC_OK))
737 return -EIO;
738 out += sprintf(out, "0x%.8x\n", result);
739 }
740
741 return out - buf;
742}
743
744
745
746
747
748
749
750
751
752
753
754static ssize_t pdcs_auto_write(struct kobject *kobj,
755 struct kobj_attribute *attr, const char *buf,
756 size_t count, int knob)
757{
758 struct pdcspath_entry *pathentry;
759 unsigned char flags;
760 char in[8], *temp;
761 char c;
762
763 if (!capable(CAP_SYS_ADMIN))
764 return -EACCES;
765
766 if (!buf || !count)
767 return -EINVAL;
768
769
770 count = min_t(size_t, count, sizeof(in)-1);
771 strncpy(in, buf, count);
772 in[count] = '\0';
773
774
775 pathentry = &pdcspath_entry_primary;
776
777
778 read_lock(&pathentry->rw_lock);
779 flags = pathentry->devpath.flags;
780 read_unlock(&pathentry->rw_lock);
781
782 DPRINTK("%s: flags before: 0x%X\n", __func__, flags);
783
784 temp = skip_spaces(in);
785
786 c = *temp++ - '0';
787 if ((c != 0) && (c != 1))
788 goto parse_error;
789 if (c == 0)
790 flags &= ~knob;
791 else
792 flags |= knob;
793
794 DPRINTK("%s: flags after: 0x%X\n", __func__, flags);
795
796
797 write_lock(&pathentry->rw_lock);
798
799
800 pathentry->devpath.flags = flags;
801
802
803 pdcspath_store(pathentry);
804 write_unlock(&pathentry->rw_lock);
805
806 printk(KERN_INFO PDCS_PREFIX ": changed \"%s\" to \"%s\"\n",
807 (knob & PF_AUTOBOOT) ? "autoboot" : "autosearch",
808 (flags & knob) ? "On" : "Off");
809
810 return count;
811
812parse_error:
813 printk(KERN_WARNING "%s: Parse error: expect \"n\" (n == 0 or 1)\n", __func__);
814 return -EINVAL;
815}
816
817
818
819
820
821
822
823
824
825
826static ssize_t pdcs_autoboot_write(struct kobject *kobj,
827 struct kobj_attribute *attr,
828 const char *buf, size_t count)
829{
830 return pdcs_auto_write(kobj, attr, buf, count, PF_AUTOBOOT);
831}
832
833
834
835
836
837
838
839
840
841
842static ssize_t pdcs_autosearch_write(struct kobject *kobj,
843 struct kobj_attribute *attr,
844 const char *buf, size_t count)
845{
846 return pdcs_auto_write(kobj, attr, buf, count, PF_AUTOSEARCH);
847}
848
849
850
851
852
853
854
855
856
857
858static ssize_t pdcs_osdep1_write(struct kobject *kobj,
859 struct kobj_attribute *attr,
860 const char *buf, size_t count)
861{
862 u8 in[16];
863
864 if (!capable(CAP_SYS_ADMIN))
865 return -EACCES;
866
867 if (!buf || !count)
868 return -EINVAL;
869
870 if (unlikely(pdcs_osid != OS_ID_LINUX))
871 return -EPERM;
872
873 if (count > 16)
874 return -EMSGSIZE;
875
876
877 memset(in, 0, 16);
878 memcpy(in, buf, count);
879
880 if (pdc_stable_write(PDCS_ADDR_OSD1, &in, sizeof(in)) != PDC_OK)
881 return -EIO;
882
883 return count;
884}
885
886
887
888
889
890
891
892
893
894
895static ssize_t pdcs_osdep2_write(struct kobject *kobj,
896 struct kobj_attribute *attr,
897 const char *buf, size_t count)
898{
899 unsigned long size;
900 unsigned short i;
901 u8 in[4];
902
903 if (!capable(CAP_SYS_ADMIN))
904 return -EACCES;
905
906 if (!buf || !count)
907 return -EINVAL;
908
909 if (unlikely(pdcs_size <= 224))
910 return -ENOSYS;
911
912 if (unlikely(pdcs_osid != OS_ID_LINUX))
913 return -EPERM;
914
915 size = pdcs_size - 224;
916
917 if (count > size)
918 return -EMSGSIZE;
919
920
921
922 for (i=0; i<count; i+=4) {
923 memset(in, 0, 4);
924 memcpy(in, buf+i, (count-i < 4) ? count-i : 4);
925 if (unlikely(pdc_stable_write(PDCS_ADDR_OSD2 + i, &in,
926 sizeof(in)) != PDC_OK))
927 return -EIO;
928 }
929
930 return count;
931}
932
933
934static PDCS_ATTR(size, 0444, pdcs_size_read, NULL);
935static PDCS_ATTR(autoboot, 0644, pdcs_autoboot_read, pdcs_autoboot_write);
936static PDCS_ATTR(autosearch, 0644, pdcs_autosearch_read, pdcs_autosearch_write);
937static PDCS_ATTR(timer, 0444, pdcs_timer_read, NULL);
938static PDCS_ATTR(osid, 0444, pdcs_osid_read, NULL);
939static PDCS_ATTR(osdep1, 0600, pdcs_osdep1_read, pdcs_osdep1_write);
940static PDCS_ATTR(diagnostic, 0400, pdcs_diagnostic_read, NULL);
941static PDCS_ATTR(fastsize, 0400, pdcs_fastsize_read, NULL);
942static PDCS_ATTR(osdep2, 0600, pdcs_osdep2_read, pdcs_osdep2_write);
943
944static struct attribute *pdcs_subsys_attrs[] = {
945 &pdcs_attr_size.attr,
946 &pdcs_attr_autoboot.attr,
947 &pdcs_attr_autosearch.attr,
948 &pdcs_attr_timer.attr,
949 &pdcs_attr_osid.attr,
950 &pdcs_attr_osdep1.attr,
951 &pdcs_attr_diagnostic.attr,
952 &pdcs_attr_fastsize.attr,
953 &pdcs_attr_osdep2.attr,
954 NULL,
955};
956
957static const struct attribute_group pdcs_attr_group = {
958 .attrs = pdcs_subsys_attrs,
959};
960
961static struct kobject *stable_kobj;
962static struct kset *paths_kset;
963
964
965
966
967
968
969
970
971
972
973static inline int __init
974pdcs_register_pathentries(void)
975{
976 unsigned short i;
977 struct pdcspath_entry *entry;
978 int err;
979
980
981 for (i = 0; (entry = pdcspath_entries[i]); i++)
982 rwlock_init(&entry->rw_lock);
983
984 for (i = 0; (entry = pdcspath_entries[i]); i++) {
985 write_lock(&entry->rw_lock);
986 err = pdcspath_fetch(entry);
987 write_unlock(&entry->rw_lock);
988
989 if (err < 0)
990 continue;
991
992 entry->kobj.kset = paths_kset;
993 err = kobject_init_and_add(&entry->kobj, &ktype_pdcspath, NULL,
994 "%s", entry->name);
995 if (err)
996 return err;
997
998
999 write_lock(&entry->rw_lock);
1000 entry->ready = 2;
1001 write_unlock(&entry->rw_lock);
1002
1003
1004 if (entry->dev) {
1005 err = sysfs_create_link(&entry->kobj, &entry->dev->kobj, "device");
1006 WARN_ON(err);
1007 }
1008
1009 kobject_uevent(&entry->kobj, KOBJ_ADD);
1010 }
1011
1012 return 0;
1013}
1014
1015
1016
1017
1018static inline void
1019pdcs_unregister_pathentries(void)
1020{
1021 unsigned short i;
1022 struct pdcspath_entry *entry;
1023
1024 for (i = 0; (entry = pdcspath_entries[i]); i++) {
1025 read_lock(&entry->rw_lock);
1026 if (entry->ready >= 2)
1027 kobject_put(&entry->kobj);
1028 read_unlock(&entry->rw_lock);
1029 }
1030}
1031
1032
1033
1034
1035
1036static int __init
1037pdc_stable_init(void)
1038{
1039 int rc = 0, error = 0;
1040 u32 result;
1041
1042
1043 if (pdc_stable_get_size(&pdcs_size) != PDC_OK)
1044 return -ENODEV;
1045
1046
1047 if (pdcs_size < 96)
1048 return -ENODATA;
1049
1050 printk(KERN_INFO PDCS_PREFIX " facility v%s\n", PDCS_VERSION);
1051
1052
1053 if (pdc_stable_read(PDCS_ADDR_OSID, &result, sizeof(result)) != PDC_OK)
1054 return -EIO;
1055
1056
1057 pdcs_osid = (u16)(result >> 16);
1058
1059
1060 stable_kobj = kobject_create_and_add("stable", firmware_kobj);
1061 if (!stable_kobj) {
1062 rc = -ENOMEM;
1063 goto fail_firmreg;
1064 }
1065
1066
1067 error = sysfs_create_group(stable_kobj, &pdcs_attr_group);
1068
1069
1070 paths_kset = kset_create_and_add("paths", NULL, stable_kobj);
1071 if (!paths_kset) {
1072 rc = -ENOMEM;
1073 goto fail_ksetreg;
1074 }
1075
1076
1077 if ((rc = pdcs_register_pathentries()))
1078 goto fail_pdcsreg;
1079
1080 return rc;
1081
1082fail_pdcsreg:
1083 pdcs_unregister_pathentries();
1084 kset_unregister(paths_kset);
1085
1086fail_ksetreg:
1087 kobject_put(stable_kobj);
1088
1089fail_firmreg:
1090 printk(KERN_INFO PDCS_PREFIX " bailing out\n");
1091 return rc;
1092}
1093
1094static void __exit
1095pdc_stable_exit(void)
1096{
1097 pdcs_unregister_pathentries();
1098 kset_unregister(paths_kset);
1099 kobject_put(stable_kobj);
1100}
1101
1102
1103module_init(pdc_stable_init);
1104module_exit(pdc_stable_exit);
1105