aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNguyen Anh Quynh <aquynh@gmail.com>2006-12-29 19:49:54 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-30 13:56:44 -0500
commitc68876fd2846d2aaf9770276db244b46f2bf52c7 (patch)
tree482214c7936ae8d3ec74352a689815f01dcdbe49
parenta8d13ea28bcb63baf69aba84b61cad4c3ff7adb9 (diff)
[PATCH] KVM: Rename some msrs
No need to append _MSR to msr names, a prefix should suffice. Signed-off-by: Nguyen Anh Quynh <aquynh@gmail.com> Signed-off-by: Avi Kivity <avi@qumranet.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/kvm/vmx.c13
-rw-r--r--drivers/kvm/vmx.h10
2 files changed, 11 insertions, 12 deletions
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 5561c5936c3d..d0a2c2d5342a 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -26,7 +26,6 @@
26 26
27#include "segment_descriptor.h" 27#include "segment_descriptor.h"
28 28
29#define MSR_IA32_FEATURE_CONTROL 0x03a
30 29
31MODULE_AUTHOR("Qumranet"); 30MODULE_AUTHOR("Qumranet");
32MODULE_LICENSE("GPL"); 31MODULE_LICENSE("GPL");
@@ -519,11 +518,11 @@ static __init void setup_vmcs_descriptor(void)
519{ 518{
520 u32 vmx_msr_low, vmx_msr_high; 519 u32 vmx_msr_low, vmx_msr_high;
521 520
522 rdmsr(MSR_IA32_VMX_BASIC_MSR, vmx_msr_low, vmx_msr_high); 521 rdmsr(MSR_IA32_VMX_BASIC, vmx_msr_low, vmx_msr_high);
523 vmcs_descriptor.size = vmx_msr_high & 0x1fff; 522 vmcs_descriptor.size = vmx_msr_high & 0x1fff;
524 vmcs_descriptor.order = get_order(vmcs_descriptor.size); 523 vmcs_descriptor.order = get_order(vmcs_descriptor.size);
525 vmcs_descriptor.revision_id = vmx_msr_low; 524 vmcs_descriptor.revision_id = vmx_msr_low;
526}; 525}
527 526
528static struct vmcs *alloc_vmcs_cpu(int cpu) 527static struct vmcs *alloc_vmcs_cpu(int cpu)
529{ 528{
@@ -1039,12 +1038,12 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
1039 vmcs_write64(GUEST_IA32_DEBUGCTL, 0); 1038 vmcs_write64(GUEST_IA32_DEBUGCTL, 0);
1040 1039
1041 /* Control */ 1040 /* Control */
1042 vmcs_write32_fixedbits(MSR_IA32_VMX_PINBASED_CTLS_MSR, 1041 vmcs_write32_fixedbits(MSR_IA32_VMX_PINBASED_CTLS,
1043 PIN_BASED_VM_EXEC_CONTROL, 1042 PIN_BASED_VM_EXEC_CONTROL,
1044 PIN_BASED_EXT_INTR_MASK /* 20.6.1 */ 1043 PIN_BASED_EXT_INTR_MASK /* 20.6.1 */
1045 | PIN_BASED_NMI_EXITING /* 20.6.1 */ 1044 | PIN_BASED_NMI_EXITING /* 20.6.1 */
1046 ); 1045 );
1047 vmcs_write32_fixedbits(MSR_IA32_VMX_PROCBASED_CTLS_MSR, 1046 vmcs_write32_fixedbits(MSR_IA32_VMX_PROCBASED_CTLS,
1048 CPU_BASED_VM_EXEC_CONTROL, 1047 CPU_BASED_VM_EXEC_CONTROL,
1049 CPU_BASED_HLT_EXITING /* 20.6.2 */ 1048 CPU_BASED_HLT_EXITING /* 20.6.2 */
1050 | CPU_BASED_CR8_LOAD_EXITING /* 20.6.2 */ 1049 | CPU_BASED_CR8_LOAD_EXITING /* 20.6.2 */
@@ -1127,7 +1126,7 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
1127 virt_to_phys(vcpu->guest_msrs + NR_BAD_MSRS)); 1126 virt_to_phys(vcpu->guest_msrs + NR_BAD_MSRS));
1128 vmcs_writel(VM_EXIT_MSR_LOAD_ADDR, 1127 vmcs_writel(VM_EXIT_MSR_LOAD_ADDR,
1129 virt_to_phys(vcpu->host_msrs + NR_BAD_MSRS)); 1128 virt_to_phys(vcpu->host_msrs + NR_BAD_MSRS));
1130 vmcs_write32_fixedbits(MSR_IA32_VMX_EXIT_CTLS_MSR, VM_EXIT_CONTROLS, 1129 vmcs_write32_fixedbits(MSR_IA32_VMX_EXIT_CTLS, VM_EXIT_CONTROLS,
1131 (HOST_IS_64 << 9)); /* 22.2,1, 20.7.1 */ 1130 (HOST_IS_64 << 9)); /* 22.2,1, 20.7.1 */
1132 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, nr_good_msrs); /* 22.2.2 */ 1131 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, nr_good_msrs); /* 22.2.2 */
1133 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, nr_good_msrs); /* 22.2.2 */ 1132 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, nr_good_msrs); /* 22.2.2 */
@@ -1135,7 +1134,7 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
1135 1134
1136 1135
1137 /* 22.2.1, 20.8.1 */ 1136 /* 22.2.1, 20.8.1 */
1138 vmcs_write32_fixedbits(MSR_IA32_VMX_ENTRY_CTLS_MSR, 1137 vmcs_write32_fixedbits(MSR_IA32_VMX_ENTRY_CTLS,
1139 VM_ENTRY_CONTROLS, 0); 1138 VM_ENTRY_CONTROLS, 0);
1140 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 0); /* 22.2.1 */ 1139 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 0); /* 22.2.1 */
1141 1140
diff --git a/drivers/kvm/vmx.h b/drivers/kvm/vmx.h
index 797278341581..4c0ab151836a 100644
--- a/drivers/kvm/vmx.h
+++ b/drivers/kvm/vmx.h
@@ -286,11 +286,11 @@ enum vmcs_field {
286 286
287#define CR4_VMXE 0x2000 287#define CR4_VMXE 0x2000
288 288
289#define MSR_IA32_VMX_BASIC_MSR 0x480 289#define MSR_IA32_VMX_BASIC 0x480
290#define MSR_IA32_FEATURE_CONTROL 0x03a 290#define MSR_IA32_FEATURE_CONTROL 0x03a
291#define MSR_IA32_VMX_PINBASED_CTLS_MSR 0x481 291#define MSR_IA32_VMX_PINBASED_CTLS 0x481
292#define MSR_IA32_VMX_PROCBASED_CTLS_MSR 0x482 292#define MSR_IA32_VMX_PROCBASED_CTLS 0x482
293#define MSR_IA32_VMX_EXIT_CTLS_MSR 0x483 293#define MSR_IA32_VMX_EXIT_CTLS 0x483
294#define MSR_IA32_VMX_ENTRY_CTLS_MSR 0x484 294#define MSR_IA32_VMX_ENTRY_CTLS 0x484
295 295
296#endif 296#endif
dd the User IO core code' href='/cgit/cgit.cgi/litmus-rt-budgetable-locks.git/.git/commit/drivers/uio/uio.c?h=update_litmus_2019&id=beafc54c4e2fba24e1ca45cdb7f79d9aa83e3db1'>beafc54c4e2f
beafc54c4e2f




70a9156bad9d
beafc54c4e2f
beafc54c4e2f




70a9156bad9d
beafc54c4e2f
beafc54c4e2f
c66fdab64fd7




beafc54c4e2f

c66fdab64fd7



beafc54c4e2f







e70c412ee453
beafc54c4e2f
e70c412ee453
beafc54c4e2f
81e7c6a636c8
e70c412ee453

beafc54c4e2f
beafc54c4e2f





81e7c6a636c8


e70c412ee453
beafc54c4e2f
81e7c6a636c8

e70c412ee453
f9cb074bff8e
81e7c6a636c8

b2d6db5878a0
81e7c6a636c8
e70c412ee453
81e7c6a636c8
beafc54c4e2f
e70c412ee453


























beafc54c4e2f



e70c412ee453







beafc54c4e2f

81e7c6a636c8
c10997f6575f
beafc54c4e2f
c10997f6575f
beafc54c4e2f





e70c412ee453
beafc54c4e2f
e70c412ee453



beafc54c4e2f

c10997f6575f
beafc54c4e2f
c10997f6575f
e70c412ee453







beafc54c4e2f



beafc54c4e2f












c6edc42fe1b5






beafc54c4e2f






0d4a7bc12ffe
beafc54c4e2f
0d4a7bc12ffe
beafc54c4e2f










































0d4a7bc12ffe
beafc54c4e2f
0d4a7bc12ffe
fbc8a81d66bb



beafc54c4e2f
fbc8a81d66bb



610ad5064cb9
beafc54c4e2f
610ad5064cb9



beafc54c4e2f





beafc54c4e2f
610ad5064cb9

beafc54c4e2f
610ad5064cb9


610ad5064cb9
610ad5064cb9
0d4a7bc12ffe
610ad5064cb9
beafc54c4e2f
fbc8a81d66bb
beafc54c4e2f
















610ad5064cb9
beafc54c4e2f
610ad5064cb9

beafc54c4e2f








6427a7655afd
beafc54c4e2f
















6427a7655afd
beafc54c4e2f






































328a14e70e7f







6427a7655afd
328a14e70e7f















beafc54c4e2f

beafc54c4e2f

f0c554fddd3b

beafc54c4e2f
f0c554fddd3b
beafc54c4e2f















a18b630d1bec
beafc54c4e2f

a18b630d1bec
02683ffdf655
beafc54c4e2f


a18b630d1bec
beafc54c4e2f
02683ffdf655





beafc54c4e2f
02683ffdf655
beafc54c4e2f
27a90700a427
beafc54c4e2f
a18b630d1bec

beafc54c4e2f

f0f37e2f7773
beafc54c4e2f

a18b630d1bec
beafc54c4e2f









c9698d6b1a90

beafc54c4e2f

































6da2d377bba0

beafc54c4e2f



beafc54c4e2f
beafc54c4e2f













4f0146919be6
beafc54c4e2f



328a14e70e7f
beafc54c4e2f


6038f373a3dc
beafc54c4e2f



91960a46c658























d80df1cea036
91960a46c658



d80df1cea036

beafc54c4e2f



91960a46c658

beafc54c4e2f



3d4f9d76b064
beafc54c4e2f





c66fdab64fd7



beafc54c4e2f


c66fdab64fd7
beafc54c4e2f




3d4f9d76b064
beafc54c4e2f
c66fdab64fd7
beafc54c4e2f
beafc54c4e2f





















beafc54c4e2f














c66fdab64fd7
a9b12619f7b6

beafc54c4e2f




beafc54c4e2f






6427a7655afd


beafc54c4e2f








c66fdab64fd7
beafc54c4e2f




beafc54c4e2f



















6427a7655afd
beafc54c4e2f



c66fdab64fd7
beafc54c4e2f
beafc54c4e2f






3d4f9d76b064
beafc54c4e2f



3d4f9d76b064
beafc54c4e2f




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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907




                                                                  
                                                     












                                                         
                       

                      
                        

                          
                       

                             
                                                 









                                             
                                         
                                            


                     
                             
                           
                                             
 


                                



             


                            
  
                                                           
 







                                                            
                                                            
 
                                                                       
 
 


                                                            

 

                                                              
                                                                                    

 
                        




                                                                 

                                                   
                                              
                                                   
                                              
                                                   
                                                
                                                       
 
                                    
                             
                             
                             
                               
                                                                   

  





                                             




                                                                          
                                      
 
                                                                 






                                     
                                               


                              
                                         
                                      
                                         
                                

  





                                                                       







                                                                 

























                                                                      

                                                        







                                                              
                                    


























                                                                             
                                                  








                                            



                                                                  
                                                      
 




                                                                     
                                                         
 




                                                                   
                                                                             
 
 




                                                         

  



                                          







                                                          
                   
                          
                             
                            
                            

                                  
 





                                               


                                                                          
                                             
                 

                                                        
                                     
                                                         

                               
                                                                          
                        
                                     
                                                           
                        


























                                                                           



                 







                                             

                                           
                               
                                        
         
                                   





                                                                     
              
                            



                                            

                                   
                                             
         
                                   







                                                    



                                                 












                                                   






                                                             






                                                   
                                
                                          
                                  










































                                                               
                                
                                                 
                                  



                              
 



                                           
 
                                                          



                                        





                                                          
                                                          

                                          
         


                 
                        
 
                   
                                
 
    
















                                                                
                                
                                                             

                                








                                                                  
                             
















                                                               
                             






































                                                                    







                                                                    
                             















                                                            

                                                         

                                                       

                                                             
                                  
                                          















                                                       
                                                                          

                                                       
                          
                             


                                         
                                       
 





                                                                             
                                                           
                                                                       
            
                                                                                                 
                       

                         

 
                                                       

                               
                               









                                                        

                                                                

































                                                                      

                                                                                 



                                           
                                                        













                                                      
                                                



                                      
                                    


                                     
                                      



                               























                                                                         
                 



                                                           

                      



                                   

                                                                       



                               
                





                                                                        



                                                                   


                 
                   




                            
                                   
 
                                     
                            





















                                                              














                                                  
                                                     

                                                                      




                                                                 






                                                


                                                                     








                                             
                                                                  




                             



















                                                            
                                                       



                                          
                                                                  
                    






                                         
                                



                                 
                            




                         
/*
 * drivers/uio/uio.c
 *
 * Copyright(C) 2005, Benedikt Spranger <b.spranger@linutronix.de>
 * Copyright(C) 2005, Thomas Gleixner <tglx@linutronix.de>
 * Copyright(C) 2006, Hans J. Koch <hjk@hansjkoch.de>
 * Copyright(C) 2006, Greg Kroah-Hartman <greg@kroah.com>
 *
 * Userspace IO
 *
 * Base Functions
 *
 * Licensed under the GPLv2 only.
 */

#include <linux/module.h>
#include <linux/init.h>
#include <linux/poll.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/idr.h>
#include <linux/sched.h>
#include <linux/string.h>
#include <linux/kobject.h>
#include <linux/cdev.h>
#include <linux/uio_driver.h>

#define UIO_MAX_DEVICES		(1U << MINORBITS)

struct uio_device {
	struct module		*owner;
	struct device		*dev;
	int			minor;
	atomic_t		event;
	struct fasync_struct	*async_queue;
	wait_queue_head_t	wait;
	int			vma_count;
	struct uio_info		*info;
	struct kobject		*map_dir;
	struct kobject		*portio_dir;
};

static int uio_major;
static struct cdev *uio_cdev;
static DEFINE_IDR(uio_idr);
static const struct file_operations uio_fops;

/* Protect idr accesses */
static DEFINE_MUTEX(minor_lock);

/*
 * attributes
 */

struct uio_map {
	struct kobject kobj;
	struct uio_mem *mem;
};
#define to_map(map) container_of(map, struct uio_map, kobj)

static ssize_t map_name_show(struct uio_mem *mem, char *buf)
{
	if (unlikely(!mem->name))
		mem->name = "";

	return sprintf(buf, "%s\n", mem->name);
}

static ssize_t map_addr_show(struct uio_mem *mem, char *buf)
{
	return sprintf(buf, "0x%llx\n", (unsigned long long)mem->addr);
}

static ssize_t map_size_show(struct uio_mem *mem, char *buf)
{
	return sprintf(buf, "0x%lx\n", mem->size);
}

static ssize_t map_offset_show(struct uio_mem *mem, char *buf)
{
	return sprintf(buf, "0x%llx\n", (unsigned long long)mem->addr & ~PAGE_MASK);
}

struct map_sysfs_entry {
	struct attribute attr;
	ssize_t (*show)(struct uio_mem *, char *);
	ssize_t (*store)(struct uio_mem *, const char *, size_t);
};

static struct map_sysfs_entry name_attribute =
	__ATTR(name, S_IRUGO, map_name_show, NULL);
static struct map_sysfs_entry addr_attribute =
	__ATTR(addr, S_IRUGO, map_addr_show, NULL);
static struct map_sysfs_entry size_attribute =
	__ATTR(size, S_IRUGO, map_size_show, NULL);
static struct map_sysfs_entry offset_attribute =
	__ATTR(offset, S_IRUGO, map_offset_show, NULL);

static struct attribute *attrs[] = {
	&name_attribute.attr,
	&addr_attribute.attr,
	&size_attribute.attr,
	&offset_attribute.attr,
	NULL,	/* need to NULL terminate the list of attributes */
};

static void map_release(struct kobject *kobj)
{
	struct uio_map *map = to_map(kobj);
	kfree(map);
}

static ssize_t map_type_show(struct kobject *kobj, struct attribute *attr,
			     char *buf)
{
	struct uio_map *map = to_map(kobj);
	struct uio_mem *mem = map->mem;
	struct map_sysfs_entry *entry;

	entry = container_of(attr, struct map_sysfs_entry, attr);

	if (!entry->show)
		return -EIO;

	return entry->show(mem, buf);
}

static const struct sysfs_ops map_sysfs_ops = {
	.show = map_type_show,
};

static struct kobj_type map_attr_type = {
	.release	= map_release,
	.sysfs_ops	= &map_sysfs_ops,
	.default_attrs	= attrs,
};

struct uio_portio {
	struct kobject kobj;
	struct uio_port *port;
};
#define to_portio(portio) container_of(portio, struct uio_portio, kobj)

static ssize_t portio_name_show(struct uio_port *port, char *buf)
{
	if (unlikely(!port->name))
		port->name = "";

	return sprintf(buf, "%s\n", port->name);
}

static ssize_t portio_start_show(struct uio_port *port, char *buf)
{
	return sprintf(buf, "0x%lx\n", port->start);
}

static ssize_t portio_size_show(struct uio_port *port, char *buf)
{
	return sprintf(buf, "0x%lx\n", port->size);
}

static ssize_t portio_porttype_show(struct uio_port *port, char *buf)
{
	const char *porttypes[] = {"none", "x86", "gpio", "other"};

	if ((port->porttype < 0) || (port->porttype > UIO_PORT_OTHER))
		return -EINVAL;

	return sprintf(buf, "port_%s\n", porttypes[port->porttype]);
}

struct portio_sysfs_entry {
	struct attribute attr;
	ssize_t (*show)(struct uio_port *, char *);
	ssize_t (*store)(struct uio_port *, const char *, size_t);
};

static struct portio_sysfs_entry portio_name_attribute =
	__ATTR(name, S_IRUGO, portio_name_show, NULL);
static struct portio_sysfs_entry portio_start_attribute =
	__ATTR(start, S_IRUGO, portio_start_show, NULL);
static struct portio_sysfs_entry portio_size_attribute =
	__ATTR(size, S_IRUGO, portio_size_show, NULL);
static struct portio_sysfs_entry portio_porttype_attribute =
	__ATTR(porttype, S_IRUGO, portio_porttype_show, NULL);

static struct attribute *portio_attrs[] = {
	&portio_name_attribute.attr,
	&portio_start_attribute.attr,
	&portio_size_attribute.attr,
	&portio_porttype_attribute.attr,
	NULL,
};

static void portio_release(struct kobject *kobj)
{
	struct uio_portio *portio = to_portio(kobj);
	kfree(portio);
}

static ssize_t portio_type_show(struct kobject *kobj, struct attribute *attr,
			     char *buf)
{
	struct uio_portio *portio = to_portio(kobj);
	struct uio_port *port = portio->port;
	struct portio_sysfs_entry *entry;

	entry = container_of(attr, struct portio_sysfs_entry, attr);

	if (!entry->show)
		return -EIO;

	return entry->show(port, buf);
}

static const struct sysfs_ops portio_sysfs_ops = {
	.show = portio_type_show,
};

static struct kobj_type portio_attr_type = {
	.release	= portio_release,
	.sysfs_ops	= &portio_sysfs_ops,
	.default_attrs	= portio_attrs,
};

static ssize_t show_name(struct device *dev,
			 struct device_attribute *attr, char *buf)
{
	struct uio_device *idev = dev_get_drvdata(dev);
	return sprintf(buf, "%s\n", idev->info->name);
}

static ssize_t show_version(struct device *dev,
			    struct device_attribute *attr, char *buf)
{
	struct uio_device *idev = dev_get_drvdata(dev);
	return sprintf(buf, "%s\n", idev->info->version);
}

static ssize_t show_event(struct device *dev,
			  struct device_attribute *attr, char *buf)
{
	struct uio_device *idev = dev_get_drvdata(dev);
	return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
}

static struct device_attribute uio_class_attributes[] = {
	__ATTR(name, S_IRUGO, show_name, NULL),
	__ATTR(version, S_IRUGO, show_version, NULL),
	__ATTR(event, S_IRUGO, show_event, NULL),
	{}
};

/* UIO class infrastructure */
static struct class uio_class = {
	.name = "uio",
	.dev_attrs = uio_class_attributes,
};

/*
 * device functions
 */
static int uio_dev_add_attributes(struct uio_device *idev)
{
	int ret;
	int mi, pi;
	int map_found = 0;
	int portio_found = 0;
	struct uio_mem *mem;
	struct uio_map *map;
	struct uio_port *port;
	struct uio_portio *portio;

	for (mi = 0; mi < MAX_UIO_MAPS; mi++) {
		mem = &idev->info->mem[mi];
		if (mem->size == 0)
			break;
		if (!map_found) {
			map_found = 1;
			idev->map_dir = kobject_create_and_add("maps",
							&idev->dev->kobj);
			if (!idev->map_dir)
				goto err_map;
		}
		map = kzalloc(sizeof(*map), GFP_KERNEL);
		if (!map)
			goto err_map;
		kobject_init(&map->kobj, &map_attr_type);
		map->mem = mem;
		mem->map = map;
		ret = kobject_add(&map->kobj, idev->map_dir, "map%d", mi);
		if (ret)
			goto err_map;
		ret = kobject_uevent(&map->kobj, KOBJ_ADD);
		if (ret)
			goto err_map;
	}

	for (pi = 0; pi < MAX_UIO_PORT_REGIONS; pi++) {
		port = &idev->info->port[pi];
		if (port->size == 0)
			break;
		if (!portio_found) {
			portio_found = 1;
			idev->portio_dir = kobject_create_and_add("portio",
							&idev->dev->kobj);
			if (!idev->portio_dir)
				goto err_portio;
		}
		portio = kzalloc(sizeof(*portio), GFP_KERNEL);
		if (!portio)
			goto err_portio;
		kobject_init(&portio->kobj, &portio_attr_type);
		portio->port = port;
		port->portio = portio;
		ret = kobject_add(&portio->kobj, idev->portio_dir,
							"port%d", pi);
		if (ret)
			goto err_portio;
		ret = kobject_uevent(&portio->kobj, KOBJ_ADD);
		if (ret)
			goto err_portio;
	}

	return 0;

err_portio:
	for (pi--; pi >= 0; pi--) {
		port = &idev->info->port[pi];
		portio = port->portio;
		kobject_put(&portio->kobj);
	}
	kobject_put(idev->portio_dir);
err_map:
	for (mi--; mi>=0; mi--) {
		mem = &idev->info->mem[mi];
		map = mem->map;
		kobject_put(&map->kobj);
	}
	kobject_put(idev->map_dir);
	dev_err(idev->dev, "error creating sysfs files (%d)\n", ret);
	return ret;
}

static void uio_dev_del_attributes(struct uio_device *idev)
{
	int i;
	struct uio_mem *mem;
	struct uio_port *port;

	for (i = 0; i < MAX_UIO_MAPS; i++) {
		mem = &idev->info->mem[i];
		if (mem->size == 0)
			break;
		kobject_put(&mem->map->kobj);
	}
	kobject_put(idev->map_dir);

	for (i = 0; i < MAX_UIO_PORT_REGIONS; i++) {
		port = &idev->info->port[i];
		if (port->size == 0)
			break;
		kobject_put(&port->portio->kobj);
	}
	kobject_put(idev->portio_dir);
}

static int uio_get_minor(struct uio_device *idev)
{
	int retval = -ENOMEM;
	int id;

	mutex_lock(&minor_lock);
	if (idr_pre_get(&uio_idr, GFP_KERNEL) == 0)
		goto exit;

	retval = idr_get_new(&uio_idr, idev, &id);
	if (retval < 0) {
		if (retval == -EAGAIN)
			retval = -ENOMEM;
		goto exit;
	}
	if (id < UIO_MAX_DEVICES) {
		idev->minor = id;
	} else {