sylware / si-user (public) (License: Unspecified) (since 2019-09-09) (hash sha1)
old sample user level code to go with my gpu driver (has interesting code)
List of commits:
Subject Hash Author Date (UTC)
use of simpler userland API e7f555a4d2ab2944efcae0c840c19a1cec929325 Sylvain BERTRAND 2013-09-20 11:16:15
timeouts in userspace a9dcf2e0c1e8d1601305a4afd47e09a7a4aff748 Sylvain BERTRAND 2013-09-01 21:27:20
use monotonic raw timespec for page flipping aa5758c53e6a58038013c7be87a1ba865cb9b3df Sylvain BERTRAND 2013-08-31 02:48:33
pf is now asynchronous 246114120ed41152e5cc551ff28da99cac20d470 Sylvain BERTRAND 2013-08-28 00:16:17
memory caches love c51aedf797f97ec3426511b1578e52d575f25321 Sylvain BERTRAND 2013-08-23 14:48:06
add files 28fe912c85541ca80777d87fc4ac21447e9d57d0 Sylvain BERTRAND 2013-08-23 13:44:21
Initial commit 18d8ad18c54c32f78561e26d949d58efb8483bd3 Sylvain BERTRAND 2013-08-23 12:50:05
Commit e7f555a4d2ab2944efcae0c840c19a1cec929325 - use of simpler userland API
Author: Sylvain BERTRAND
Author date (UTC): 2013-09-20 11:16
Committer name: Sylvain BERTRAND
Committer date (UTC): 2013-09-20 11:16
Parent(s): a9dcf2e0c1e8d1601305a4afd47e09a7a4aff748
Signer:
Signing key:
Signing status: N
Tree: 773e7ddab9faee5ae374d5392b78f5df7bd27305
File Lines added Lines deleted
dma_l2l.c 0 1
dma_u32_fill.c 0 1
dpm.c 0 1
edid.c 0 1
modeset.c 66 70
pf.c 0 1
tri.c 0 1
File dma_l2l.c changed (mode: 100644) (index 1de18e9..1c4b0d5)
16 16
17 17 #include <linux/types.h> #include <linux/types.h>
18 18
19 #include <alga/timing.h>
20 19 #include <alga/pixel_fmts.h> #include <alga/pixel_fmts.h>
21 20 #include <alga/amd/dce6/dce6.h> #include <alga/amd/dce6/dce6.h>
22 21 #include <alga/amd/si/ioctl.h> #include <alga/amd/si/ioctl.h>
File dma_u32_fill.c changed (mode: 100644) (index bd9e1db..a4d2242)
16 16
17 17 #include <linux/types.h> #include <linux/types.h>
18 18
19 #include <alga/timing.h>
20 19 #include <alga/pixel_fmts.h> #include <alga/pixel_fmts.h>
21 20 #include <alga/amd/dce6/dce6.h> #include <alga/amd/dce6/dce6.h>
22 21 #include <alga/amd/si/ioctl.h> #include <alga/amd/si/ioctl.h>
File dpm.c changed (mode: 100644) (index 3a32cd5..a458be5)
13 13
14 14 #include <linux/types.h> #include <linux/types.h>
15 15
16 #include <alga/timing.h>
17 16 #include <alga/pixel_fmts.h> #include <alga/pixel_fmts.h>
18 17 #include <alga/amd/dce6/dce6.h> #include <alga/amd/dce6/dce6.h>
19 18 #include <alga/amd/si/ioctl.h> #include <alga/amd/si/ioctl.h>
File edid.c changed (mode: 100644) (index 83fc10f..3650ee1)
14 14
15 15 #include <linux/types.h> #include <linux/types.h>
16 16
17 #include <alga/timing.h>
18 17 #include <alga/pixel_fmts.h> #include <alga/pixel_fmts.h>
19 18 #include <alga/amd/dce6/dce6.h> #include <alga/amd/dce6/dce6.h>
20 19 #include <alga/amd/si/ioctl.h> #include <alga/amd/si/ioctl.h>
File modeset.c changed (mode: 100644) (index 333ebd6..77fa089)
10 10 #include <stdlib.h> #include <stdlib.h>
11 11 #include <error.h> #include <error.h>
12 12
13 #include <linux/types.h>
14
15 #include <alga/timing.h>
13 //#include <linux/types.h>
16 14 #include <alga/pixel_fmts.h> #include <alga/pixel_fmts.h>
17 15 #include <alga/amd/dce6/dce6.h> #include <alga/amd/dce6/dce6.h>
18 16 #include <alga/amd/si/ioctl.h> #include <alga/amd/si/ioctl.h>
19 17
20 18 #define e(m,...) error(0,0,m,##__VA_ARGS__) #define e(m,...) error(0,0,m,##__VA_ARGS__)
21 #define BIT(x) (1<<x)
19 #define o(m,...) printf(m "\n",##__VA_ARGS__)
22 20 #define unsignedl unsigned long #define unsignedl unsigned long
23 21 #define unsignedll unsigned long long #define unsignedll unsigned long long
24 22
25 static uint8_t v_refresh(struct alga_timing *t)
23 static void mode(char *str, uint16_t *h, uint16_t *v, uint8_t *r)
26 24 { {
27 float line_pixels=t->h+t->h_bl;
28 float frame_lines=t->v+t->v_bl;
29 float frame_pixels=frame_lines*line_pixels;
30 float r=(float)(t->pixel_clk)*1000/frame_pixels;
31 return (uint8_t)round(r);
32 }
25 *h=0;
26 *v=0;
27 *r=0;
28 char *c=str;
29
30 //hhhhx
31 while(1){
32 if(*c=='\0') return;
33 if(*c=='x') break;
34 ++c;
35 }
36 *c='\0';
37 *h=(uint16_t)strtoul(str,NULL,10);
38 *c='x';
39
40 ++c;
41 str=c;
42 //vvvv@
43 while(1){
44 if(*c=='\0') return;
45 if(*c=='@') break;
46 ++c;
47 }
48 *c='\0';
49 *v=(uint16_t)strtoul(str,NULL,10);
50 *c='@';
33 51
34 static void timing_print(struct alga_timing *t)
35 {
36 printf("\t\t\t%ux%u@%uHz\n\t\t\tpixel_clk=%ukHz,h_bl=%u,h_so=%u,h_spw=%u"
37 ",h_sp=%u,v_bl=%u,v_so=%u,v_spw=%u,v_sp=%u\n",t->h,t->v,v_refresh(t),
38 t->pixel_clk,t->h_bl,t->h_so,t->h_spw,t->h_sp,t->v_bl,t->v_so,
39 t->v_spw,t->v_sp);
52 ++c;
53 //rrr\0
54 *r=(uint8_t)strtoul(c,NULL,10);
40 55 } }
41 56
42 static void dce_dps_info_print(struct si_dce_dps_info *info)
57 uint8_t alga_pixel_fmt(char *str)
43 58 { {
44 printf("dps info:\n\tused=0x%02x,connected=0x%02x\n",info->used,
45 info->connected);
46 for(uint8_t i=0;i<CRTCS_N_MAX;++i){
47 if((info->used&BIT(i))==0) continue;
48 if((info->connected&BIT(i))==0) continue;
49 printf("\tdp%u\n",i);
50 printf("\t\tpixel formats:\n");
51 for(uint8_t j=0;j<ALGA_PIXEL_FMTS_MAX;++j){
52 if(info->pixel_fmts[i][j]==ALGA_PIXEL_FMT_INVALID) break;
53 printf("\t\t\t%s\n",alga_pixel_fmts_str[info->pixel_fmts[i][j]]);
54 }
55 printf("\t\ttimings\n");
56 for(uint8_t j=0;j<ALGA_TIMINGS_MAX;++j){
57 if(info->timings[i][j].pixel_clk==0) break;
58 timing_print(&info->timings[i][j]);
59 }
59 uint8_t fmt=1;
60 while(1){
61 if(fmt==ALGA_PIXEL_FMTS_N) return 0;
62 if(!strncmp(str,alga_pixel_fmts_str[fmt],sizeof("ARGB2101010")))
63 return fmt;
64 ++fmt;
60 65 } }
61 66 } }
62 67
63 68 int main(int argc, char *argv[]) int main(int argc, char *argv[])
64 69 { {
70 if(argc<4){
71 e("missing arguments:idx(0->5) mode(1920x1080@60) pixel_fmt(ARGB8888)");
72 goto err;
73 }
74
65 75 int f=open("/dev/si0", O_RDWR); int f=open("/dev/si0", O_RDWR);
66 76 if(f==-1){ if(f==-1){
67 e("open failed\n");
77 e("open failed");
68 78 goto err; goto err;
69 79 } }
70 80
71 81 //XXX:why did I do that? //XXX:why did I do that?
72 82 long p_sz=sysconf(_SC_PAGESIZE); long p_sz=sysconf(_SC_PAGESIZE);
73 83 if(p_sz==-1){ if(p_sz==-1){
74 e("get page size failed\n");
75 goto err_file_close;
84 e("get page size failed");
85 goto err;
76 86 } }
77 87
78 struct si_dce_dps_info info;
79 unsignedl req=_IOR('d',SI_DCE_DPS_INFO,info);
80 int r=ioctl(f,req,&info);
81 if(r==-1){
82 e("get dps info failed\n");
83 goto err_file_close;
84 }
85 dce_dps_info_print(&info);
88 uint16_t h;
89 uint16_t v;
90 uint8_t r;
91 mode(argv[2],&h,&v,&r);
92 o("from '%s' horizontal=%u pixels, vertical=%u pixels, refresh rate=%u Hz",
93 argv[2],h,v,r);
86 94
87 uint8_t idx=strtoul(argv[1],NULL,10);
88 struct alga_timing *t=&info.timings[idx][0];//hardcode timing selection
95 uint8_t pixel_fmt=alga_pixel_fmt(argv[3]);
89 96
90 97 struct si_mem mem; struct si_mem mem;
91 98 //Why did I do that? Anyway, for the GPU color blocks the frame buffer must //Why did I do that? Anyway, for the GPU color blocks the frame buffer must
92 99 //be aligned on 256 bytes boundary. //be aligned on 256 bytes boundary.
93 100 mem.align=p_sz; mem.align=p_sz;
94 uint64_t sz=2*(t->h*t->v*alga_pixel_fmts_sz[ALGA_ARGB8888]);
101 uint64_t sz=2*(h*v*alga_pixel_fmts_sz[pixel_fmt]);
95 102 mem.sz=sz; mem.sz=sz;
96 printf("db_fb alloc sz=%016llx\n",(unsignedll)mem.sz);
97 req=_IOWR('d',SI_MEM_ALLOC,mem);
103 o("db_fb alloc sz=%016llx",(unsignedll)mem.sz);
104 unsignedl req=_IOWR('d',SI_MEM_ALLOC,mem);
98 105 r=ioctl(f,req,&mem); r=ioctl(f,req,&mem);
99 106 if(r==-1){ if(r==-1){
100 e("alloc db_fb failed\n");
101 goto err_file_close;
107 e("alloc db_fb failed");
108 goto err;
102 109 } }
103 printf("front_fb=0x%016llx back_fb=0x%016llx\n",(unsignedll)mem.gpu_addr,
110 o("front_fb=0x%016llx back_fb=0x%016llx",(unsignedll)mem.gpu_addr,
104 111 (unsignedll)mem.gpu_addr+sz/2); (unsignedll)mem.gpu_addr+sz/2);
105 112
106 113 struct si_dce_dp_set dp_set; struct si_dce_dp_set dp_set;
107 dp_set.idx=idx;
114 memset(&dp_set,0,sizeof(dp_set));
115 dp_set.idx=strtoul(argv[1],NULL,10);
108 116 dp_set.primary=mem.gpu_addr; dp_set.primary=mem.gpu_addr;
109 117 dp_set.secondary=mem.gpu_addr+sz/2; dp_set.secondary=mem.gpu_addr+sz/2;
110 dp_set.pixel_fmt=ALGA_ARGB8888;
111 dp_set.timing=*t;
112 //dp_set.pitch=t->h*pixel_fmts_szs[ALGA_ARGB8888];
113 dp_set.pitch=t->h;
118 strncpy(&dp_set.mode[0],argv[2],sizeof(dp_set.mode));
119 strncpy(&dp_set.pixel_fmt[0],argv[3],sizeof(dp_set.pixel_fmt));
114 120 req=_IOR('d',SI_DCE_DP_SET,dp_set); req=_IOR('d',SI_DCE_DP_SET,dp_set);
115 121 r=ioctl(f,req,&dp_set); r=ioctl(f,req,&dp_set);
116 122 if(r==-1){ if(r==-1){
117 e("dp set failed\n");
123 e("dp set failed");
118 124 goto err_free_fb; goto err_free_fb;
119 125 } }
120
121 r=close(f);
122 if(r==-1){
123 e("close failed\n");
124 goto err;
125 }
126 126 return 0; return 0;
127 127
128 128 err_free_fb: err_free_fb:
129 129 req=_IOW('d',SI_MEM_FREE,mem.gpu_addr); req=_IOW('d',SI_MEM_FREE,mem.gpu_addr);
130 130 r=ioctl(f,req,&mem.gpu_addr); r=ioctl(f,req,&mem.gpu_addr);
131 if(r==-1) e("free vram fb failed (LEAK!)\n");
132
133 err_file_close:
134 r=close(f);
135 if(r==-1) e("close failed\n");
131 if(r==-1) e("free vram fb failed (LEAK!)");
136 132
137 133 err: err:
138 134 return EXIT_FAILURE; return EXIT_FAILURE;
File pf.c changed (mode: 100644) (index ccfb304..32aa9c7)
15 15
16 16 #include <linux/types.h> #include <linux/types.h>
17 17
18 #include <alga/timing.h>
19 18 #include <alga/pixel_fmts.h> #include <alga/pixel_fmts.h>
20 19 #include <alga/amd/dce6/dce6.h> #include <alga/amd/dce6/dce6.h>
21 20 #include <alga/amd/si/ioctl.h> #include <alga/amd/si/ioctl.h>
File tri.c changed (mode: 100644) (index 2371677..e4aee49)
23 23
24 24 #include <linux/types.h> #include <linux/types.h>
25 25
26 #include <alga/timing.h>
27 26 #include <alga/pixel_fmts.h> #include <alga/pixel_fmts.h>
28 27 #include <alga/amd/dce6/dce6.h> #include <alga/amd/dce6/dce6.h>
29 28 #include <alga/amd/si/ioctl.h> #include <alga/amd/si/ioctl.h>
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/sylware/si-user

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/sylware/si-user

Clone this repository using git:
git clone git://git.rocketgit.com/user/sylware/si-user

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main