Rev 1002 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1002 | Rev 1026 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | 4 | ||
Line 5... | Line 5... | ||
5 | unsigned pitch; |
5 | unsigned pitch; |
6 | size_t size; |
6 | size_t size; |
Line -... | Line 7... | ||
- | 7 | ||
- | 8 | addr_t mem_local = 0; |
|
7 | 9 | addr_t mem_dma = 0; |
|
Line 8... | Line 10... | ||
8 | void *local; |
10 | void *mapped; |
9 | 11 | ||
10 | if( (io->width == 0) || (io->width > 2048)|| |
12 | if( (io->width == 0) || (io->width > 2048)|| |
11 | (io->height == 0)|| (io->height > 2048)) |
13 | (io->height == 0)|| (io->height > 2048)) |
12 | { |
14 | { |
13 | dbgprintf("Invalid pixmap size w:%d h:%d\n", io->width,io->height); |
15 | dbgprintf("Invalid pixmap size w:%d h:%d\n", io->width,io->height); |
Line -... | Line 16... | ||
- | 16 | return ERR_PARAM; |
|
- | 17 | }; |
|
- | 18 | ||
- | 19 | pixmap = malloc(sizeof(local_pixmap_t)); |
|
- | 20 | ||
14 | return ERR_PARAM; |
21 | if(!pixmap) |
15 | }; |
22 | return ERR_PARAM; |
Line 16... | Line 23... | ||
16 | 23 | ||
Line -... | Line 24... | ||
- | 24 | pitch = ((io->width+15)&~15)*4; |
|
17 | pitch = ((io->width+15)&~15)*4; |
25 | size = pitch*io->height; |
18 | size = pitch*io->height; |
26 | |
19 | 27 | dbgprintf("pitch = %d\n", pitch); |
|
- | 28 | ||
- | 29 | if( (io->flags & PX_MEM_MASK) == PX_MEM_LOCAL ) { |
|
- | 30 | mem_local = rhd_mem_alloc(&rhd,RHD_MEM_FB,size); |
|
- | 31 | mem_dma = mem_local + rhd.fbLocation; |
|
20 | dbgprintf("pitch = %d\n", pitch); |
32 | } |
- | 33 | else |
|
21 | 34 | mem_local = mem_dma = AllocPages( size >> 12 ); |
|
22 | local = rhd_mem_alloc(&rhd,RHD_MEM_FB,size) ; |
35 | |
Line 23... | Line 36... | ||
23 | if ( !local) |
36 | if ( !mem_local) { |
24 | { |
- | |
25 | dbgprintf("Not enough memory for pixmap\n"); |
- | |
26 | return ERR_PARAM; |
- | |
27 | }; |
- | |
28 | - | ||
29 | pixmap = malloc(sizeof(local_pixmap_t)); |
- | |
30 | if(!pixmap) |
- | |
31 | { |
37 | dbgprintf("Not enough memory for pixmap\n"); |
Line 32... | Line 38... | ||
32 | rhd_mem_free(&rhd, RHD_MEM_FB,local); |
38 | free(pixmap); |
Line 33... | Line 39... | ||
33 | return ERR_PARAM; |
39 | return ERR_PARAM; |
34 | } |
40 | }; |
35 | else |
41 | |
Line 36... | Line 42... | ||
36 | { |
42 | pixmap->pitch_offset = ((pitch/64)<<22)| (mem_dma>>10); |
37 | void *mapped; |
43 | pixmap->local = mem_dma; |
38 | 44 | ||
Line 39... | Line 45... | ||
39 | size = (size+4095) & ~ 4095; |
45 | size = (size+4095) & ~ 4095; |
40 | 46 | ||
41 | if (mapped = UserAlloc(size)) |
47 | if (mapped = UserAlloc(size)) |
42 | { |
48 | { |
43 | CommitPages(mapped, ((u32_t)local+rhd.LinearAddr)|7|(1<<9), size); |
49 | CommitPages(mapped, mem_dma|7|(1<<9), size); |
44 | 50 | ||
45 | io->mapped = mapped; |
- | |
46 | io->pitch = pitch; |
- | |
Line 47... | Line 51... | ||
47 | io->handle = (u32_t)pixmap; |
51 | io->mapped = mapped; |
48 | 52 | io->pitch = pitch; |
|
49 | pixmap->width = io->width; |
53 | io->handle = (u32_t)pixmap; |
Line 50... | Line 54... | ||
50 | pixmap->height = io->height; |
54 | |
51 | pixmap->format = PICT_a8r8g8b8; |
55 | pixmap->width = io->width; |
52 | pixmap->flags = PX_MEM_LOCAL; //io->flags; |
56 | pixmap->height = io->height; |
53 | pixmap->pitch = pitch; |
57 | pixmap->format = PICT_a8r8g8b8; |
54 | pixmap->mapped = mapped; |
58 | pixmap->flags = io->flags; |
55 | pixmap->pitch_offset = ((pitch/64)<<22)| (((u32_t)local+rhd.fbLocation)>>10); |
59 | pixmap->pitch = pitch; |
56 | pixmap->local = local+rhd.fbLocation; |
60 | pixmap->mapped = mapped; |
Line 57... | Line 61... | ||
57 | 61 | ||
Line 84... | Line 88... | ||
84 | 88 | ||
Line 85... | Line 89... | ||
85 | UnmapPages(pixmap->mapped, size); |
89 | UnmapPages(pixmap->mapped, size); |
86 | UserFree(pixmap->mapped); |
90 | UserFree(pixmap->mapped); |
Line -... | Line 91... | ||
- | 91 | ||
- | 92 | if( (io->flags & PX_MEM_MASK) == PX_MEM_LOCAL ) |
|
87 | 93 | { |
|
- | 94 | rhd_mem_free(&rhd,RHD_MEM_FB,pixmap->local-rhd.fbLocation); |
|
- | 95 | } |
|
- | 96 | else |
|
- | 97 | { |
|
- | 98 | count_t pages = size >> 12; |
|
- | 99 | addr_t base = pixmap->local; |
|
- | 100 | ||
- | 101 | while( pages--) |
|
- | 102 | { |
|
- | 103 | addr_t tmp; |
|
- | 104 | // __asm__ __volatile__( |
|
- | 105 | // "call *__imp__PageFree" |
|
- | 106 | // :"=eax" (tmp):"a" (base) ); |
|
- | 107 | // base+= 4096; |
|
- | 108 | }; |
|
- | 109 | } |
|
88 | rhd_mem_free(&rhd,RHD_MEM_FB,pixmap->local-rhd.fbLocation); |
110 | |
Line 89... | Line 111... | ||
89 | free(pixmap); |
111 | free(pixmap); |
90 | 112 | ||
91 | io->format = 0; |
113 | io->format = 0; |
92 | io->pitch = 0; |
114 | io->pitch = 0; |
Line 93... | Line 115... | ||
93 | io->mapped = NULL; |
115 | io->mapped = NULL; |
94 | io->handle = 0; |
116 | io->handle = 0; |
- | 117 | ||
- | 118 | return ERR_OK; |
|
- | 119 | }; |
|
- | 120 | ||
- | 121 | ||
- | 122 | # define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */ |
|
- | 123 | # define ATI_PCIGART_PAGE_MASK (~(ATI_PCIGART_PAGE_SIZE-1)) |
|
- | 124 | ||
- | 125 | #define ATI_PCIE_WRITE 0x4 |
|
- | 126 | #define ATI_PCIE_READ 0x8 |
|
- | 127 | ||
- | 128 | #define upper_32_bits(n) ((u32_t)(((n) >> 16) >> 16)) |
|
- | 129 | ||
- | 130 | ||
- | 131 | static addr_t bind_pixmap(local_pixmap_t *pixmap) |
|
- | 132 | { |
|
- | 133 | count_t pages; |
|
- | 134 | addr_t base; |
|
- | 135 | ||
- | 136 | u32_t tmp; |
|
- | 137 | ||
- | 138 | u32_t *gart = rhd.gart_table; |
|
- | 139 | ||
- | 140 | pages = ((pixmap->height * pixmap->pitch+4095)&~4095)>>12; |
|
- | 141 | base = pixmap->local; |
|
- | 142 | ||
- | 143 | // tmp = INREG(RADEON_AIC_CNTL); |
|
- | 144 | // OUTREG(RADEON_AIC_CNTL, tmp & ~RADEON_PCIGART_TRANSLATE_EN); |
|
- | 145 | ||
- | 146 | while(pages--) |
|
- | 147 | { |
|
- | 148 | addr_t page_base; |
|
- | 149 | ||
- | 150 | // *gart = base & ATI_PCIGART_PAGE_MASK; |
|
- | 151 | // base+= 4096; |
|
- | 152 | // gart++; |
|
- | 153 | page_base = base & ATI_PCIGART_PAGE_MASK; |
|
- | 154 | ||
- | 155 | page_base >>= 8; |
|
- | 156 | page_base |= (upper_32_bits(base) & 0xff) << 24; |
|
- | 157 | page_base |= ATI_PCIE_READ | ATI_PCIE_WRITE; |
|
- | 158 | ||
- | 159 | *gart = page_base; |
|
- | 160 | base+= 4096; |
|
- | 161 | gart++; |
|
- | 162 | } |
|
- | 163 | __asm__ __volatile("sfence":::"memory"); |
|
- | 164 | ||
- | 165 | // OUTREG(RADEON_AIC_CNTL, tmp | RADEON_PCIGART_TRANSLATE_EN); |
|
- | 166 | // OUTREG(RADEON_AIC_PT_BASE, rhd.gart_table_dma); |
|
- | 167 | RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_CNTL, |
|
- | 168 | RADEON_PCIE_TX_GART_EN |
|
- | 169 | | RADEON_PCIE_TX_GART_INVALIDATE_TLB); |
|
- | 170 | ||
- | 171 | return ((pixmap->pitch / 64) << 22) | (rhd.gart_vm_start >> 10); |
|
- | 172 | } |
|
- | 173 | ||
- | 174 | #if 0 |
|
- | 175 | ||
- | 176 | int LockPixmap(userpixmap_t *io) |
|
- | 177 | { |
|
- | 178 | pixmap_t *pixmap; |
|
- | 179 | size_t size; |
|
- | 180 | void *usermap; |
|
- | 181 | ||
- | 182 | dbgprintf("Lock pixmap %x\n", io->pixmap); |
|
- | 183 | ||
- | 184 | if(io->pixmap == (pixmap_t*)-1) |
|
- | 185 | return ERR_PARAM; |
|
- | 186 | else |
|
- | 187 | pixmap = io->pixmap; |
|
- | 188 | ||
- | 189 | if( (pixmap->flags & 1) == PX_LOCK ) |
|
- | 190 | return ERR_PARAM; |
|
- | 191 | ||
- | 192 | size = (pixmap->pitch*pixmap->width+4095) & ~ 4095; |
|
- | 193 | if (usermap = UserAlloc(size)) |
|
- | 194 | { |
|
- | 195 | CommitPages(usermap, ((u32_t)pixmap->raw+rhd.PhisBase)|7|(1<<9), size); |
|
- | 196 | pixmap->flags |= PX_LOCK; |
|
- | 197 | pixmap->usermap = usermap; |
|
- | 198 | io->usermap = usermap; |
|
- | 199 | io->pitch = pixmap->pitch; |
|
- | 200 | dbgprintf("map at %x\n", io->usermap); |
|
- | 201 | ||
- | 202 | return ERR_OK; |
|
- | 203 | } |
|
- | 204 | else |
|
- | 205 | return ERR_PARAM; |
|
- | 206 | }; |
|
- | 207 | ||
- | 208 | int UnlockPixmap(userpixmap_t *io) |
|
- | 209 | { |
|
- | 210 | pixmap_t *pixmap; |
|
- | 211 | size_t size; |
|
- | 212 | ||
- | 213 | dbgprintf("Unlock pixmap %x\n", io->pixmap); |
|
- | 214 | ||
- | 215 | if(io->pixmap == (pixmap_t*)-1) |
|
- | 216 | return ERR_PARAM; |
|
- | 217 | else |
|
- | 218 | pixmap = io->pixmap; |
|
- | 219 | ||
- | 220 | if( (pixmap->flags & 1) != PX_LOCK ) |
|
- | 221 | return ERR_PARAM; |
|
- | 222 | ||
- | 223 | /* Sanity checks */ |
|
- | 224 | ||
- | 225 | if( (pixmap->usermap == 0)|| |
|
- | 226 | ((u32_t)pixmap->usermap >= 0x80000000) || |
|
- | 227 | ((u32_t)pixmap->usermap & 4095) |
|
- | 228 | ) |
|
- | 229 | return ERR_PARAM; |
|
- | 230 | ||
- | 231 | size = (pixmap->pitch*pixmap->width+4095) & ~ 4095; |
|
- | 232 | ||
- | 233 | UnmapPages(pixmap->usermap, size); |
|
- | 234 | UserFree(pixmap->usermap); |
|
- | 235 | pixmap->usermap = NULL; |
|
- | 236 | pixmap->flags &= ~PX_LOCK; |
|
- | 237 | io->usermap = NULL; |
|
- | 238 | io->pitch = 0; |
|
- | 239 | ||
- | 240 | return ERR_OK; |
|
- | 241 | }; |