-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfiregl_public.c
6679 lines (5805 loc) · 188 KB
/
firegl_public.c
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
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
* *
* Copyright 1999-2005 ATI Technologies Inc., Markham, Ontario, CANADA. *
* All Rights Reserved. *
* *
* Your use and or redistribution of this software in source and \ or *
* binary form, with or without modification, is subject to: (i) your *
* ongoing acceptance of and compliance with the terms and conditions of *
* the ATI Technologies Inc. software End User License Agreement; and (ii) *
* your inclusion of this notice in any version of this software that you *
* use or redistribute. A copy of the ATI Technologies Inc. software End *
* User License Agreement is included with this software and is also *
* available by contacting ATI Technologies Inc. at http://www.ati.com *
* *
****************************************************************************/
#ifdef __KERNEL__
#ifndef MODULE
!!! This is not currently supported,
!!! since it requires changes to linux/init/main.c.
#endif /* !MODULE */
// ============================================================
#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
#error Kernel versions older than 2.6.0 are no longer supported by this module.
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
#include <generated/autoconf.h>
#else
#include <linux/autoconf.h>
#endif
#if !defined(CONFIG_X86)
#if !defined(CONFIG_X86_PC)
#if !defined(CONFIG_X86_XEN)
#if !defined(CONFIG_X86_64)
#if !defined(CONFIG_X86_VOYAGER)
#if !defined(CONFIG_X86_NUMAQ)
#if !defined(CONFIG_X86_SUMMIT)
#if !defined(CONFIG_X86_BIGSMP)
#if !defined(CONFIG_X86_VISWS)
#if !defined(CONFIG_X86_GENERICARCH)
#error unknown or undefined architecture configured
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
#endif
/* The dirty-page-tracking patch included in NLD 9 SMP kernels defines
* a static inline function that uses a GPL-only symbol in a header
* file. Therefore any non-GPL module built against such a kernel
* configuration is broken and cannot be loaded. We work around that
* problem by disabling the respective kernel configuration option for
* our module build.
*
* This will break page tracking when this kernel module is
* used. However, on a standard system page tracking is disabled
* anyways. It is only activated and used by specific in-kernel agents
* for example for CPU hot-plugging. I wonder why a desktop
* distribution would even include such a kernel patch. */
#ifdef CONFIG_MEM_MIRROR
/* Prevent asm/mm_track.h from being included in subsequent
* kernel headers as that would redefine CONFIG_MEM_MIRROR. */
#ifndef CONFIG_X86_64
#define __I386_MMTRACK_H__
#define mm_track(ptep)
#else
#define __X86_64_MMTRACK_H__
#define mm_track_pte(ptep)
#define mm_track_pmd(ptep)
#define mm_track_pgd(ptep)
#define mm_track_pml4(ptep)
#define mm_track_phys(x)
#endif
#warning "Disabling CONFIG_MEM_MIRROR because it does not work with non-GPL modules."
#warning "This will break page tracking when the fglrx kernel module is used."
#undef CONFIG_MEM_MIRROR
#endif /* CONFIG_MEM_MIRROR */
/* To avoid compatibility issues with old kernels, only use DMA API
for kernels configured to support hardware IOMMU in NB chipset.
Note, AMD and Intel have differnt iommu drivers in different loacations
and they use different config options. These options can only be enabled
on x86_64 with newer 2.6 kernels (2.6.23 for intel, 2.6.26 for amd).
*/
#if defined(CONFIG_AMD_IOMMU) || defined(CONFIG_INTEL_IOMMU) || defined(CONFIG_DMAR)
#define FIREGL_DMA_REMAPPING
#endif
// ============================================================
// always defined
#define __AGP__BUILTIN__
//#define FGL_USE_SCT /* for developer use only */
// ============================================================
#include <asm/unistd.h> /* for installing the patch wrapper */
#include <linux/module.h>
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/init.h>
#include <linux/file.h>
#include <linux/pci.h>
#include <linux/wait.h>
#include <linux/miscdevice.h>
// newer SuSE kernels need this
#include <linux/highmem.h>
#include <linux/vmalloc.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/console.h>
#include <linux/random.h>
#include <linux/timex.h>
#include <linux/kthread.h>
#include <linux/err.h>
#include <asm/io.h>
#include <asm/mman.h>
#include <asm/uaccess.h>
#include <asm/processor.h>
#include <asm/tlbflush.h> // for flush_tlb_page
#include <asm/cpufeature.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)
#undef CONFIG_MTRR
#endif
#ifdef CONFIG_MTRR
#include <asm/mtrr.h>
#endif
#ifdef CONFIG_EFI
#include <linux/efi.h>
#endif
#include <linux/screen_info.h>
#include <asm/delay.h>
#include <linux/agp_backend.h>
#ifndef EXPORT_NO_SYMBOLS
#define EXPORT_NO_SYMBOLS
#endif
#include <linux/poll.h> /* for poll() */
#include <asm/poll.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
#ifdef __x86_64__
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
#include "linux/ioctl32.h"
#else
#include "asm/ioctl32.h"
#endif
#endif
#ifdef __x86_64__
#include "asm/compat.h"
#endif
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
#include "linux/freezer.h"
#endif
// For 2.6.18 or higher, the UTS_RELEASE is defined in the linux/utsrelease.h.
#ifndef UTS_RELEASE
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
#include <generated/utsrelease.h>
#else
#include <linux/utsrelease.h>
#endif
#endif
#if defined(__i386__)
#ifndef do_div
#include "asm/div64.h"
#endif
#endif
#include <linux/kmod.h>
#include <linux/sysrq.h>
#include <linux/string.h>
#include <linux/gfp.h>
#include <linux/swap.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)
#include <asm/fpu/api.h>
#else
#include "asm/i387.h"
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)
#include <asm/fpu/internal.h>
#else
#include <asm/fpu-internal.h>
#endif
#endif
#include "firegl_public.h"
#include "kcl_osconfig.h"
#include "kcl_io.h"
#include "kcl_debug.h"
// ============================================================
// VM_SHM is deleted in 2.6.18 or higher kernels.
#ifndef VM_SHM
#define VM_SHM 0
#endif
#ifdef FGL_LINUX253P1_VMA_API
// Linux 2.5.3-pre1 and compatibles
#define FGL_VMA_API_TYPE struct vm_area_struct *
#define FGL_VMA_API_NAME vma
#define FGL_VMA_API_PROTO FGL_VMA_API_TYPE FGL_VMA_API_NAME,
#define FGL_VMA_API_PASS FGL_VMA_API_NAME,
#else /* FGL_253P1_VMA_API */
// Linux 2.4.0 and compatibles
#define FGL_VMA_API_TYPE /* none */
#define FGL_VMA_API_NAME /* none */
#define FGL_VMA_API_PROTO /* none */
#define FGL_VMA_API_PASS /* none */
#endif /* FGL_253P1_VMA_API */
#ifndef preempt_disable
#define preempt_disable()
#define preempt_enable()
#endif
// VM_RESERVED is removed from 3.7.0
#ifndef VM_RESERVED
#define VM_RESERVED VM_DONTEXPAND | VM_DONTDUMP
#endif
// ============================================================
#if defined(__get_cpu_var)
#define GET_CPU_VAR(var) __get_cpu_var(var)
#else
#define GET_CPU_VAR(var) (*this_cpu_ptr(&(var)))
#endif
// read_cr4() and write_cr4() has changed from 4.0.0, 3.18.17
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,0,0) || ((LINUX_VERSION_CODE < KERNEL_VERSION(3,19,0)) && (LINUX_VERSION_CODE > KERNEL_VERSION(3,18,16)))
#define READ_CR4() __read_cr4()
#define WRITE_CR4(x) __write_cr4(x)
#else
#define READ_CR4() read_cr4()
#define WRITE_CR4(x) write_cr4(x)
#endif
// ============================================================
/* globals */
char* firegl = NULL;
static struct pci_device_id fglrx_pci_table[] =
{
#define FGL_ASIC_ID(x) \
{ \
.vendor = PCI_VENDOR_ID_ATI, \
.device = x, \
.subvendor = PCI_ANY_ID, \
.subdevice = PCI_ANY_ID, \
}
#include "fglrxko_pci_ids.h"
{ 0, }
};
/* global module vars and constants - defined trough macros */
MODULE_AUTHOR("Fire GL - ATI Research GmbH, Germany");
MODULE_DESCRIPTION("ATI Fire GL");
#ifdef MODULE_PARM
MODULE_PARM(firegl, "s");
#else
module_param(firegl, charp, 0);
#endif
#ifdef MODULE_LICENSE
MODULE_LICENSE("Proprietary. (C) 2002 - ATI Technologies, Starnberg, GERMANY");
#endif
#ifdef MODULE_DEVICE_TABLE
MODULE_DEVICE_TABLE(pci, fglrx_pci_table);
#endif
MODULE_INFO(supported, "external");
/* globals constants */
const char* KCL_SYSINFO_OsVersionString = UTS_RELEASE;
const unsigned int KCL_SYSINFO_PageSize = PAGE_SIZE;
const unsigned long KCL_SYSINFO_OsVersionCode = LINUX_VERSION_CODE;
// create global constants and hint symbols (i.e. for objdump checking)
#ifdef MODVERSIONS
const unsigned long KCL_SYSINFO_BinaryModuleSupport = 1;
const char BUILD_KERNEL_HAS_MODVERSIONS_SET;
#else
const unsigned long KCL_SYSINFO_BinaryModuleSupport = 0;
const char BUILD_KERNEL_HAS_MODVERSIONS_CLEARED;
#endif
#ifdef __SMP__
const unsigned long KCL_SYSINFO_SmpSupport = 1;
const char BUILD_KERNEL_HAS_SMP_SET;
#else
const unsigned long KCL_SYSINFO_SmpSupport = 0;
const char BUILD_KERNEL_HAS_SMP_CLEARED;
#endif
/* PAE is always disabled if it's not x86_64 or CONFIG_X86_PAE is disabled on a 32 bit system.*/
#if !defined(__x86_64__) && !defined(CONFIG_X86_PAE)
const unsigned long KCL_SYSINFO_PaeSupport = 0;
#else
const unsigned long KCL_SYSINFO_PaeSupport = 1;
#endif
#if defined(CONFIG_HUGETLBFS) && defined(CONFIG_HUGETLB_PAGE)
#define FGL_LNX_SUPPORT_LARGE_PAGE
#endif
#ifdef FIREGL_USWC_SUPPORT
typedef enum
{
KCL_MEM_PAT_DISABLED = 0,
KCL_MEM_PAT_ENABLED_BUILTIN,
KCL_MEM_PAT_ENABLED_KERNEL
} kcl_mem_pat_status_t;
static kcl_mem_pat_status_t kcl_mem_pat_status = KCL_MEM_PAT_DISABLED;
static u64 kcl_mem_pat_orig_val;
static kcl_mem_pat_status_t ATI_API_CALL kcl_mem_pat_enable (unsigned int save_orig_pat);
static void ATI_API_CALL kcl_mem_pat_disable (void);
#endif //FIREGL_USWC_SUPPORT
/* globals vars that are in fact constants */
unsigned long KCL_SYSINFO_TimerTicksPerSecond;
extern int firegl_get_num_devices (void);
// ============================================================
/* global structures */
int ip_firegl_open(struct inode* inode, struct file* filp)
{
int m;
#ifndef MINOR
m = minor(inode->i_rdev);
#else
m = MINOR(inode->i_rdev);
#endif
return firegl_open(m, (KCL_IO_FILE_Handle)filp);
}
int ip_firegl_release(struct inode* inode, struct file* filp)
{
return firegl_release((KCL_IO_FILE_Handle)filp);
}
#ifdef HAVE_UNLOCKED_IOCTL
long ip_firegl_unlocked_ioctl(struct file* filp, unsigned int cmd, unsigned long arg)
#else
int ip_firegl_ioctl(struct inode* inode, struct file* filp, unsigned int cmd, unsigned long arg)
#endif
{
return firegl_ioctl((KCL_IO_FILE_Handle)filp, cmd, arg);
}
int ip_firegl_mmap(struct file* filp, struct vm_area_struct* vma)
{
int ret;
KCL_DEBUG_TRACEIN(FN_FIREGL_MMAP, vma, NULL);
ret = firegl_mmap((KCL_IO_FILE_Handle)filp, vma);
KCL_DEBUG_TRACEOUT(FN_FIREGL_MMAP, ret, NULL);
return ret;
}
#if defined(KCL_OSCONFIG_IOCTL_COMPAT) && defined(__x86_64__)
long ip_firegl_compat_ioctl(struct file* filp, unsigned int cmd, unsigned long arg)
{
long ret;
KCL_DEBUG_TRACEIN(FN_FIREGL_COMPAT_IOCTL, cmd, NULL);
ret = firegl_compat_ioctl((KCL_IO_FILE_Handle)filp, cmd, arg);
KCL_DEBUG_TRACEOUT(FN_FIREGL_COMPAT_IOCTL, ret, NULL);
return ret;
}
#endif
kcl_ssize_t ip_firegl_read( struct file *filp,
char *buf,
kcl_size_t size,
kcl_loff_t *off_ptr)
{
kcl_ssize_t ret;
KCL_DEBUG_TRACEIN(FN_FIREGL_READ_WRITE, size, NULL);
ret = firegl_asyncio_read((KCL_IO_FILE_Handle)filp, buf, size, off_ptr);
KCL_DEBUG_TRACEOUT(FN_FIREGL_READ_WRITE, ret, NULL);
return ret;
}
kcl_ssize_t ip_firegl_write( struct file *filp,
const char *buf,
kcl_size_t size,
kcl_loff_t *off_ptr)
{
kcl_ssize_t ret;
KCL_DEBUG_TRACEIN(FN_FIREGL_READ_WRITE, size, NULL);
ret = firegl_asyncio_write((KCL_IO_FILE_Handle)filp, buf, size, off_ptr);
KCL_DEBUG_TRACEOUT(FN_FIREGL_READ_WRITE, ret, NULL);
return ret;
}
unsigned int ip_firegl_poll(struct file* filp, struct poll_table_struct* table)
{
unsigned int ret;
KCL_DEBUG_TRACEIN(FN_FIREGL_POLL, table, NULL);
ret = firegl_asyncio_poll(
(KCL_IO_FILE_Handle)filp, (KCL_IO_FILE_PollTableHandle)table);
KCL_DEBUG_TRACEOUT(FN_FIREGL_POLL, ret, NULL);
return ret;
}
int ip_firegl_fasync(int fd, struct file *filp, int mode)
{
int ret;
KCL_DEBUG_TRACEIN(FN_FIREGL_FASYNC, filp, NULL);
ret = firegl_asyncio_fasync(fd, (KCL_IO_FILE_Handle)filp, mode);
KCL_DEBUG_TRACEOUT(FN_FIREGL_FASYNC, ret,NULL);
return ret;
}
kcl_loff_t ip_firegl_lseek(struct file *filp, kcl_loff_t off, int whence)
{
return __KE_ESPIPE; /* unseekable */
}
static struct semaphore fireglAsyncioSemaphore[FIREGL_ASYNCIO_MAX_SEMA];
static unsigned char fireglAsyncioSemaphoreUsed[FIREGL_ASYNCIO_MAX_SEMA];
static struct file_operations firegl_fops =
{
#ifdef THIS_MODULE
owner: THIS_MODULE,
#endif
open: ip_firegl_open,
release: ip_firegl_release,
#ifdef HAVE_UNLOCKED_IOCTL
unlocked_ioctl: ip_firegl_unlocked_ioctl,
#else
ioctl: ip_firegl_ioctl,
#endif
mmap: ip_firegl_mmap,
write: ip_firegl_write,
read: ip_firegl_read,
fasync: ip_firegl_fasync,
poll: ip_firegl_poll,
llseek: ip_firegl_lseek,
#if defined(KCL_OSCONFIG_IOCTL_COMPAT) && defined(__x86_64__)
compat_ioctl: ip_firegl_compat_ioctl,
#endif
};
typedef struct {
kcl_device_t pubdev; // MUST BE FIRST MEMBER, we can directly deferencee to (device_t*)pubdev
dev_t device; // Device number for mknod
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
struct device *krldev;
#endif
/* Locking */
spinlock_t spinlock[__KE_MAX_SPINLOCKS]; /* For inuse, open_count, buf_use */
struct semaphore struct_sem[__KE_MAX_SEMAPHORES]; /* For linked list manipulations */
} device_t;
static device_t firegl_public_device; // The Fire GL public device
/*****************************************************************************/
// standard XFree86 DRM proc support
#define DRM(x) FGLDRM_##x
#include "drm.h"
// mem_info() is missing in drm_proc.h. But, it is a DRM design problem anyway!
// The first registered DRM device could never report memory statisticts of another
// DRM device, cause the DRM mem_info routine uses local variables. So, let's use a dummy.
static int DRM(mem_info)(char *buf __attribute__((unused)), char **start __attribute__((unused)), off_t offset __attribute__((unused)), int len __attribute__((unused)), int *eof, void *data __attribute__((unused)))
{
*eof = 1;
return 0;
}
#include "drm_proc.h"
static int major = -1;
static kcl_proc_list_t *drm_proclist = NULL;
/*****************************************************************************/
// Fire GL DRM stub support (compatible with standard DRM stub)
#define FIREGL_STUB_MAXCARDS 16
typedef struct firegl_stub_list_tag {
const char *name;
struct file_operations *fops;
struct proc_dir_entry *dev_root;
kcl_proc_list_t *proclist;
} firegl_stub_list_t;
static firegl_stub_list_t firegl_stub_list[FIREGL_STUB_MAXCARDS];
static struct proc_dir_entry *firegl_stub_root;
static int firegl_minors;
typedef struct firegl_drm_stub_info_tag {
int (*info_register)(const char *name, struct file_operations *fops, device_t *dev);
int (*info_unregister)(int minor);
unsigned long signature; // to check for compatible Fire GL DRM device
} firegl_drm_stub_info_t;
static firegl_drm_stub_info_t firegl_stub_info;
static char *kcl_pte_phys_addr_str(pte_t pte, char *buf, kcl_dma_addr_t* phys_address);
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
#define READ_PROC_WRAP(func) \
static int func##_wrap(char *buf, char **start, kcl_off_t offset, \
int len, int* eof, void* data) \
{ \
if (offset > 0) \
{ \
KCL_DEBUG1(FN_FIREGL_PROC,"partial requests not supported!\n"); \
return 0; /* no partial requests */ \
} \
*start = buf; \
*eof = 1; \
return func(buf, len, data); \
}
#else
#define READ_PROC_WRAP(func) \
static int func##_wrap(struct seq_file *m, void* data) \
{ \
int len = 0; \
len = func(m->buf+m->count, m->size-m->count, m->private); \
if (m->count + len < m->size) \
{ \
m->count += len; \
return 0; \
} \
else \
{ \
m->count = m->size; \
return -1; \
} \
}
#endif
READ_PROC_WRAP(drm_name_info)
READ_PROC_WRAP(drm_mem_info)
READ_PROC_WRAP(drm_mem_info1)
READ_PROC_WRAP(drm_vm_info)
READ_PROC_WRAP(drm_clients_info)
READ_PROC_WRAP(firegl_lock_info)
#ifdef DEBUG
READ_PROC_WRAP(drm_bq_info)
#endif
READ_PROC_WRAP(firegl_debug_proc_read)
READ_PROC_WRAP(firegl_bios_version)
READ_PROC_WRAP(firegl_interrupt_info)
READ_PROC_WRAP(firegl_ptm_info)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
static kcl_ssize_t firegl_debug_proc_write_wrap(struct file *file, const char *buffer, kcl_size_t count, kcl_loff_t *data)
#else
static int firegl_debug_proc_write_wrap(void* file, const char *buffer, unsigned long count, void *data)
#endif
{
return firegl_debug_proc_write(file, buffer, count, data);
}
/** \brief Callback function for reading from /proc/ati/major
*
* Returns the major device number in the outupt buffer in decimal.
*
* \param buf buffer to write into [out]
* \param start start of new output within the buffer [out]
* \param offset offset to start reading from (only 0 is supported) [in]
* \param request number of bytes to be read [in]
* \param eof indicate end-of-file [out]
* \param data callback data pointer (unused) [in]
*
* \return number of bytes written
*/
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
static int firegl_major_proc_read(char *buf, char **start, kcl_off_t offset,
int request, int* eof, void* data)
#else
static int firegl_major_proc_read(struct seq_file *m, void* data)
#endif
{
int len = 0; // For ProcFS: fill buf from the beginning
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
KCL_DEBUG1(FN_FIREGL_PROC, "offset %d\n", (int)offset);
if (offset > 0)
{
KCL_DEBUG1(FN_FIREGL_PROC, "no partial requests\n");
return 0; /* no partial requests */
}
*start = buf; // For ProcFS: inform procfs that we start output at the beginning of the buffer
*eof = 1;
len = snprintf(buf, request, "%d\n", major);
#else
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)
seq_printf(m, "%d\n", major);
len = 0;
#else
len = seq_printf(m, "%d\n", major);
#endif
#endif
KCL_DEBUG1(FN_FIREGL_PROC, "return len=%i\n",len);
return len;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
static int firegl_major_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, firegl_major_proc_read, PDE_DATA(inode));
}
static const struct file_operations firegl_major_fops =
{
.open = firegl_major_proc_open,
.read = seq_read,
.llseek = seq_lseek,
};
static int firegl_debug_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, firegl_debug_proc_read_wrap, PDE_DATA(inode));
}
static const struct file_operations firegl_debug_fops =
{
.open = firegl_debug_proc_open,
.write = firegl_debug_proc_write_wrap,
.read = seq_read,
.llseek = seq_lseek,
};
static int firegl_name_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, drm_name_info_wrap, PDE_DATA(inode));
}
static const struct file_operations firegl_name_fops =
{
.open = firegl_name_proc_open,
.read = seq_read,
.llseek = seq_lseek,
};
static int firegl_mem_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, drm_mem_info_wrap, PDE_DATA(inode));
}
static const struct file_operations firegl_mem_fops =
{
.open = firegl_mem_proc_open,
.read = seq_read,
.llseek = seq_lseek,
};
static int firegl_mem1_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, drm_mem_info1_wrap, PDE_DATA(inode));
}
static const struct file_operations firegl_mem1_fops =
{
.open = firegl_mem1_proc_open,
.read = seq_read,
.llseek = seq_lseek,
};
static int firegl_vm_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, drm_vm_info_wrap, PDE_DATA(inode));
}
static const struct file_operations firegl_vm_fops =
{
.open = firegl_vm_proc_open,
.read = seq_read,
.llseek = seq_lseek,
};
static int firegl_clients_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, drm_clients_info_wrap, PDE_DATA(inode));
}
static const struct file_operations firegl_clients_fops =
{
.open = firegl_clients_proc_open,
.read = seq_read,
.llseek = seq_lseek,
};
static int firegl_lock_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, firegl_lock_info_wrap, PDE_DATA(inode));
}
static const struct file_operations firegl_lock_fops =
{
.open = firegl_lock_proc_open,
.read = seq_read,
.llseek = seq_lseek,
};
#ifdef DEBUG
static int firegl_bq_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, drm_bq_info_wrap, PDE_DATA(inode));
}
static const struct file_operations firegl_bq_fops =
{
.open = firegl_bq_proc_open,
.read = seq_read,
.llseek = seq_lseek,
};
#endif
static int firegl_bios_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, firegl_bios_version_wrap, PDE_DATA(inode));
}
static const struct file_operations firegl_bios_fops =
{
.open = firegl_bios_proc_open,
.read = seq_read,
.llseek = seq_lseek,
};
static int firegl_interrupt_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, firegl_interrupt_info_wrap, PDE_DATA(inode));
}
static const struct file_operations firegl_interrupt_fops =
{
.open = firegl_interrupt_proc_open,
.read = seq_read,
.llseek = seq_lseek,
};
static int firegl_ptm_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, firegl_ptm_info_wrap, PDE_DATA(inode));
}
static const struct file_operations firegl_ptm_fops =
{
.open = firegl_ptm_proc_open,
.read = seq_read,
.llseek = seq_lseek,
};
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
kcl_proc_list_t KCL_PROC_FileList[] =
{
{ "name", drm_name_info_wrap, NULL ,NULL},
{ "mem", drm_mem_info_wrap, NULL ,NULL},
{ "mem1", drm_mem_info1_wrap, NULL ,NULL},
{ "vm", drm_vm_info_wrap, NULL ,NULL},
{ "clients", drm_clients_info_wrap, NULL ,NULL},
{ "lock", firegl_lock_info_wrap, NULL ,NULL},
#ifdef DEBUG
{ "bq_info", drm_bq_info_wrap, NULL ,NULL},
#endif
{ "biosversion", firegl_bios_version_wrap, NULL ,NULL},
{ "interrupt_info", firegl_interrupt_info_wrap, NULL ,NULL},
{ "ptm_info", firegl_ptm_info_wrap, NULL ,NULL},
{ "NULL", NULL, NULL ,NULL} // Terminate List!!!
};
kcl_proc_list_t KCL_GLOBAL_PROC_FILELIST[] =
{
{ "major", firegl_major_proc_read, NULL ,NULL},
{ "debug", firegl_debug_proc_read_wrap, firegl_debug_proc_write_wrap, NULL},
{ "NULL", NULL, NULL ,NULL}
};
#else
kcl_proc_list_t KCL_PROC_FileList[] =
{
{ "name", NULL, NULL, (kcl_file_operations_t*)&firegl_name_fops},
{ "mem", NULL, NULL, (kcl_file_operations_t*)&firegl_mem_fops},
{ "mem1", NULL, NULL, (kcl_file_operations_t*)&firegl_mem1_fops},
{ "vm", NULL, NULL, (kcl_file_operations_t*)&firegl_vm_fops},
{ "clients", NULL, NULL, (kcl_file_operations_t*)&firegl_clients_fops},
{ "lock", NULL, NULL, (kcl_file_operations_t*)&firegl_lock_fops},
#ifdef DEBUG
{ "bq_info", NULL, NULL, (kcl_file_operations_t*)&firegl_bq_fops},
#endif
{ "biosversion", NULL, NULL, (kcl_file_operations_t*)&firegl_bios_fops},
{ "interrupt_info", NULL, NULL, (kcl_file_operations_t*)&firegl_interrupt_fops},
{ "ptm_info", NULL, NULL, (kcl_file_operations_t*)&firegl_ptm_fops},
{ "NULL", NULL, NULL, NULL} // Terminate List!!!
};
kcl_proc_list_t KCL_GLOBAL_PROC_FILELIST[] =
{
{ "major", NULL, NULL, (kcl_file_operations_t*)&firegl_major_fops},
{ "debug", NULL, NULL, (kcl_file_operations_t*)&firegl_debug_fops},
{ "NULL", NULL, NULL, NULL}
};
#endif
static struct proc_dir_entry *firegl_proc_init( device_t *dev,
int minor,
struct proc_dir_entry *root,
struct proc_dir_entry **dev_root,
kcl_proc_list_t *proc_list ) // proc_list must be terminated!
{
struct proc_dir_entry *ent;
char name[64];
kcl_proc_list_t *list = proc_list;
kcl_proc_list_t *globallist = &KCL_GLOBAL_PROC_FILELIST[0];
KCL_DEBUG1(FN_FIREGL_PROC, "minor %d, proc_list 0x%08lx\n", minor, (unsigned long)proc_list);
if (!minor)
{
root = KCL_create_proc_dir(NULL, "ati", S_IRUGO|S_IXUGO);
}
if (!root)
{
KCL_DEBUG_ERROR("Cannot create /proc/ati\n");
return NULL;
}
if (minor == 0)
{
// Global major debice number entry and Global debug entry
while (globallist->rp || globallist->fops)
{
ent = KCL_create_proc_entry(root, globallist->name, S_IFREG|S_IRUGO, globallist->fops, globallist->rp, globallist->wp, dev);
if (!ent)
{
KCL_remove_proc_dir_entry(NULL, "ati");
KCL_DEBUG_ERROR("Cannot create /proc/ati/major\n");
return NULL;
}
globallist++;
}
}
sprintf(name, "%d", minor);
*dev_root = KCL_create_proc_dir(root, name, S_IRUGO|S_IXUGO);
if (!*dev_root) {
KCL_remove_proc_dir_entry(root, "major");
KCL_remove_proc_dir_entry(NULL, "ati");
KCL_DEBUG_ERROR("Cannot create /proc/ati/%s\n", name);
return NULL;
}
while (list->rp || list->fops)
{
ent = KCL_create_proc_entry(*dev_root, list->name, S_IFREG|S_IRUGO, list->fops, list->rp, list->wp,
((dev->pubdev.signature == FGL_DEVICE_SIGNATURE)? firegl_find_device(minor) : (dev)));
if (!ent)
{
KCL_DEBUG_ERROR("Cannot create /proc/ati/%s/%s\n", name, list->name);
while (proc_list != list)
{
KCL_remove_proc_dir_entry(*dev_root, proc_list->name);
proc_list++;
}
KCL_remove_proc_dir_entry(root, name);
if (!minor)
{
KCL_remove_proc_dir_entry(root, "major");
KCL_remove_proc_dir_entry(NULL, "ati");
}
return NULL;
}
list++;
}
return root;
}
static int firegl_proc_cleanup( int minor,
struct proc_dir_entry *root,
struct proc_dir_entry *dev_root,
kcl_proc_list_t *proc_list )
{
char name[64];
if (!root || !dev_root)
{
KCL_DEBUG_ERROR("no root\n");
return 0;
}
while (proc_list->rp || proc_list->fops)
{
KCL_DEBUG1(FN_FIREGL_PROC, "proc_list : 0x%x, proc_list->name:%s\n", proc_list, proc_list->name);
KCL_remove_proc_dir_entry(dev_root, proc_list->name);
proc_list++;
}
sprintf(name, "%d", minor);
KCL_remove_proc_dir_entry(root, name);
if ( minor == (firegl_minors-1) )
{
KCL_remove_proc_dir_entry(root, "major");
KCL_remove_proc_dir_entry(root, "debug");
KCL_remove_proc_dir_entry(NULL, "ati");
KCL_DEBUG1(FN_FIREGL_PROC,"remove /proc/ati. \n");
}
return 0;
}
static int firegl_stub_open(struct inode *inode, struct file *filp)
{
#ifndef MINOR
int minor = minor(inode->i_rdev);
#else
int minor = MINOR(inode->i_rdev);
#endif
int err = -ENODEV;
const struct file_operations *old_fops;
KCL_DEBUG1(FN_FIREGL_INIT,"\n");
if (minor >= FIREGL_STUB_MAXCARDS)
return -ENODEV;
if (!firegl_stub_list[minor].fops)
return -ENODEV;
old_fops = filp->f_op;
filp->f_op = fops_get(firegl_stub_list[minor].fops);
if (filp->f_op->open && (err = filp->f_op->open(inode, filp))) {
fops_put(filp->f_op);
filp->f_op =(struct file_operations *) fops_get(old_fops);
}
fops_put(old_fops);
return err;
}
static struct file_operations firegl_stub_fops = {
owner: THIS_MODULE,
open: firegl_stub_open
};
static int firegl_stub_getminor(const char *name, struct file_operations *fops, device_t *dev)
{
int i;
int count = 0;
KCL_DEBUG1(FN_FIREGL_INIT, "firegl_stub_getminor: name=\"%s\"\n", name);
for( i = 0; i < FIREGL_STUB_MAXCARDS; i++ )
{
if( !firegl_stub_list[i].fops )
{