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; |