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