Changeset 94e46c9 in mainline for uspace/drv/audio/hdaudio/stream.c
- Timestamp:
- 2015-05-23T04:09:11Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b5143bd
- Parents:
- a25d893 (diff), 0683992 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/audio/hdaudio/stream.c
ra25d893 r94e46c9 48 48 #include "stream.h" 49 49 50 static int hda_stream_buffers_alloc(hda_stream_t *stream)50 int hda_stream_buffers_alloc(hda_t *hda, hda_stream_buffers_t **rbufs) 51 51 { 52 52 void *bdl; 53 53 void *buffer; 54 54 uintptr_t buffer_phys; 55 hda_stream_buffers_t *bufs = NULL; 55 56 size_t i; 56 57 // size_t j, k; 57 58 int rc; 58 59 59 stream->nbuffers = 4; 60 stream->bufsize = 16384; 60 bufs = calloc(1, sizeof(hda_stream_buffers_t)); 61 if (bufs == NULL) { 62 rc = ENOMEM; 63 goto error; 64 } 65 66 bufs->nbuffers = 4; 67 bufs->bufsize = 16384; 61 68 62 69 /* … … 65 72 */ 66 73 bdl = AS_AREA_ANY; 67 rc = dmamem_map_anonymous( stream->nbuffers * sizeof(hda_buffer_desc_t),68 stream->hda->ctl->ok64bit ? 0 : DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE,69 0, & stream->bdl_phys, &bdl);74 rc = dmamem_map_anonymous(bufs->nbuffers * sizeof(hda_buffer_desc_t), 75 hda->ctl->ok64bit ? 0 : DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 76 0, &bufs->bdl_phys, &bdl); 70 77 if (rc != EOK) 71 78 goto error; 72 79 73 stream->bdl = bdl;80 bufs->bdl = bdl; 74 81 75 82 /* Allocate arrays of buffer pointers */ 76 83 77 stream->buf = calloc(stream->nbuffers, sizeof(void *));78 if ( stream->buf == NULL)79 goto error; 80 81 stream->buf_phys = calloc(stream->nbuffers, sizeof(uintptr_t));82 if ( stream->buf_phys == NULL)84 bufs->buf = calloc(bufs->nbuffers, sizeof(void *)); 85 if (bufs->buf == NULL) 86 goto error; 87 88 bufs->buf_phys = calloc(bufs->nbuffers, sizeof(uintptr_t)); 89 if (bufs->buf_phys == NULL) 83 90 goto error; 84 91 85 92 /* Allocate buffers */ 86 93 /* 87 for (i = 0; i < stream->nbuffers; i++) {94 for (i = 0; i < bufs->nbuffers; i++) { 88 95 buffer = AS_AREA_ANY; 89 rc = dmamem_map_anonymous( stream->bufsize,90 stream->hda->ctl->ok64bit ? 0 : DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE,96 rc = dmamem_map_anonymous(bufs->bufsize, 97 bufs->hda->ctl->ok64bit ? 0 : DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 91 98 0, &buffer_phys, &buffer); 92 99 if (rc != EOK) … … 96 103 (unsigned long long)buffer_phys, buffer); 97 104 98 stream->buf[i] = buffer;99 stream->buf_phys[i] = buffer_phys;105 bufs->buf[i] = buffer; 106 bufs->buf_phys[i] = buffer_phys; 100 107 101 108 k = 0; 102 for (j = 0; j < stream->bufsize / 2; j++) {103 int16_t *bp = stream->buf[i];109 for (j = 0; j < bufs->bufsize / 2; j++) { 110 int16_t *bp = bufs->buf[i]; 104 111 bp[j] = (k > 128) ? -100 : 100; 105 112 ++k; … … 111 118 /* audio_pcm_iface requires a single contiguous buffer */ 112 119 buffer = AS_AREA_ANY; 113 rc = dmamem_map_anonymous( stream->bufsize * stream->nbuffers,114 stream->hda->ctl->ok64bit ? 0 : DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE,120 rc = dmamem_map_anonymous(bufs->bufsize * bufs->nbuffers, 121 hda->ctl->ok64bit ? 0 : DMAMEM_4GiB, AS_AREA_READ | AS_AREA_WRITE, 115 122 0, &buffer_phys, &buffer); 116 123 if (rc != EOK) { … … 119 126 } 120 127 121 for (i = 0; i < stream->nbuffers; i++) {122 stream->buf[i] = buffer + i * stream->bufsize;123 stream->buf_phys[i] = buffer_phys + i * stream->bufsize;128 for (i = 0; i < bufs->nbuffers; i++) { 129 bufs->buf[i] = buffer + i * bufs->bufsize; 130 bufs->buf_phys[i] = buffer_phys + i * bufs->bufsize; 124 131 125 132 ddf_msg(LVL_NOTE, "Stream buf phys=0x%llx virt=%p", 126 (long long unsigned)(uintptr_t) stream->buf[i],127 (void *) stream->buf_phys[i]);133 (long long unsigned)(uintptr_t)bufs->buf[i], 134 (void *)bufs->buf_phys[i]); 128 135 /* k = 0; 129 for (j = 0; j < stream->bufsize / 2; j++) {130 int16_t *bp = stream->buf[i];136 for (j = 0; j < bufs->bufsize / 2; j++) { 137 int16_t *bp = bufs->buf[i]; 131 138 bp[j] = (k > 128) ? -10000 : 10000; 132 139 ++k; … … 138 145 139 146 /* Fill in BDL */ 140 for (i = 0; i < stream->nbuffers; i++) { 141 stream->bdl[i].address = host2uint64_t_le(stream->buf_phys[i]); 142 stream->bdl[i].length = host2uint32_t_le(stream->bufsize); 143 stream->bdl[i].flags = BIT_V(uint32_t, bdf_ioc); 144 } 145 147 for (i = 0; i < bufs->nbuffers; i++) { 148 bufs->bdl[i].address = host2uint64_t_le(bufs->buf_phys[i]); 149 bufs->bdl[i].length = host2uint32_t_le(bufs->bufsize); 150 bufs->bdl[i].flags = BIT_V(uint32_t, bdf_ioc); 151 } 152 153 *rbufs = bufs; 146 154 return EOK; 147 155 error: 156 hda_stream_buffers_free(bufs); 148 157 return ENOMEM; 149 158 } 150 159 160 void hda_stream_buffers_free(hda_stream_buffers_t *bufs) 161 { 162 if (bufs == NULL) 163 return; 164 165 /* XXX */ 166 free(bufs); 167 } 168 151 169 static void hda_stream_desc_configure(hda_stream_t *stream) 152 170 { 153 171 hda_sdesc_regs_t *sdregs; 172 hda_stream_buffers_t *bufs = stream->buffers; 154 173 uint8_t ctl1; 155 174 uint8_t ctl3; … … 161 180 hda_reg8_write(&sdregs->ctl3, ctl3); 162 181 hda_reg8_write(&sdregs->ctl1, ctl1); 163 hda_reg32_write(&sdregs->cbl, stream->nbuffers * stream->bufsize);164 hda_reg16_write(&sdregs->lvi, stream->nbuffers - 1);182 hda_reg32_write(&sdregs->cbl, bufs->nbuffers * bufs->bufsize); 183 hda_reg16_write(&sdregs->lvi, bufs->nbuffers - 1); 165 184 hda_reg16_write(&sdregs->fmt, stream->fmt); 166 hda_reg32_write(&sdregs->bdpl, LOWER32( stream->bdl_phys));167 hda_reg32_write(&sdregs->bdpu, UPPER32( stream->bdl_phys));185 hda_reg32_write(&sdregs->bdpl, LOWER32(bufs->bdl_phys)); 186 hda_reg32_write(&sdregs->bdpu, UPPER32(bufs->bdl_phys)); 168 187 } 169 188 … … 205 224 206 225 hda_stream_t *hda_stream_create(hda_t *hda, hda_stream_dir_t dir, 207 uint32_t fmt)226 hda_stream_buffers_t *bufs, uint32_t fmt) 208 227 { 209 228 hda_stream_t *stream; 210 int rc;229 uint8_t sdid; 211 230 212 231 stream = calloc(1, sizeof(hda_stream_t)); … … 214 233 return NULL; 215 234 235 sdid = 0; 236 237 switch (dir) { 238 case sdir_input: 239 sdid = 0; /* XXX Allocate - first input SDESC */ 240 break; 241 case sdir_output: 242 sdid = hda->ctl->iss; /* XXX Allocate - First output SDESC */ 243 break; 244 case sdir_bidi: 245 sdid = hda->ctl->iss + hda->ctl->oss; /* XXX Allocate - First bidi SDESC */ 246 break; 247 } 248 216 249 stream->hda = hda; 217 250 stream->dir = dir; 218 251 stream->sid = 1; /* XXX Allocate this */ 219 stream->sdid = hda->ctl->iss; /* XXX Allocate - First output SDESC */252 stream->sdid = sdid; 220 253 stream->fmt = fmt; 254 stream->buffers = bufs; 221 255 222 256 ddf_msg(LVL_NOTE, "snum=%d sdidx=%d", stream->sid, stream->sdid); 223 224 ddf_msg(LVL_NOTE, "Allocate buffers");225 rc = hda_stream_buffers_alloc(stream);226 if (rc != EOK)227 goto error;228 257 229 258 ddf_msg(LVL_NOTE, "Configure stream descriptor"); 230 259 hda_stream_desc_configure(stream); 231 260 return stream; 232 error:233 return NULL;234 261 } 235 262
Note:
See TracChangeset
for help on using the changeset viewer.