Changeset ed54cbf in mainline for uspace/drv/bus/isa/i8237.c
- Timestamp:
- 2012-08-19T12:54:35Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b881226
- Parents:
- b28dabe
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/isa/i8237.c
rb28dabe red54cbf 273 273 }; 274 274 275 /* Initialize I/O access to DMA controller I/O ports.275 /** Initialize I/O access to DMA controller I/O ports. 276 276 * 277 277 * @param controller DMA Controller structure to initialize. 278 278 * 279 279 * @return Error code. 280 *281 280 */ 282 281 static inline int dma_controller_init(dma_controller_t *controller) … … 305 304 306 305 return EOK; 306 } 307 308 /** Helper function. Channels 4,5,6, and 7 are 8 bit DMA. 309 * @pram channel DMA channel. 310 * @reutrn True, if channel is 4,5,6, or 7, false otherwise. 311 */ 312 static inline bool is_dma16(unsigned channel) 313 { 314 return (channel >= 4) && (channel < 8); 315 } 316 317 /** Helper function. Channels 0,1,2, and 3 are 8 bit DMA. 318 * @pram channel DMA channel. 319 * @reutrn True, if channel is 0,1,2, or 3, false otherwise. 320 */ 321 static inline bool is_dma8(unsigned channel) 322 { 323 return (channel < 4); 307 324 } 308 325 … … 325 342 uint8_t mode) 326 343 { 344 if (!is_dma8(channel) && !is_dma16(channel)) 345 return ENOENT; 346 327 347 if ((channel == 0) || (channel == 4)) 328 348 return ENOTSUP; 329 330 if (channel > 7)331 return ENOENT;332 349 333 350 /* DMA is limited to 24bit addresses. */ … … 336 353 337 354 /* 8 bit channels use only 4 bits from the page register. */ 338 if ( (channel > 0) && (channel < 4) && (pa >= (1 << 20)))355 if (is_dma8(channel) && (pa >= (1 << 20))) 339 356 return EINVAL; 340 357 … … 353 370 } 354 371 372 ddf_msg(LVL_DEBUG, "Unspoiled address: %p and size: %zu.", pa, size); 373 355 374 /* 16 bit transfers are a bit special */ 356 ddf_msg(LVL_DEBUG, "Unspoiled address: %p and size: %zu.", pa, size); 357 if (channel > 4) { 375 if (is_dma16(channel)) { 358 376 /* Size must be aligned to 16 bits */ 359 377 if ((size & 1) != 0) { … … 361 379 return EINVAL; 362 380 } 363 381 /* Size is in 2byte words */ 364 382 size >>= 1; 365 366 383 /* Address is fun: lower 16 bits need to be shifted by 1 */ 367 384 pa = ((pa & 0xffff) >> 1) | (pa & 0xff0000); … … 429 446 } 430 447 431 extern int dma_channel_remain(unsigned channel, uint16_t *size) 448 /** Query remaining buffer size. 449 * 450 * @param channel DMA Channel 1, 2, 3 for 8 bit transfers, 451 * 5, 6, 7 for 16 bit. 452 * @param size Place to store number of bytes pending in the assigned buffer. 453 * 454 * @return Error code. 455 */ 456 int dma_channel_remain(unsigned channel, uint16_t *size) 432 457 { 433 458 assert(size); 459 if (!is_dma8(channel) && !is_dma16(channel)) 460 return ENOENT; 461 434 462 if ((channel == 0) || (channel == 4)) 435 463 return ENOTSUP; 436 437 if (channel > 7)438 return ENOENT;439 464 440 465 fibril_mutex_lock(&guard); … … 461 486 const int remain = (value_high << 8 | value_low) + 1; 462 487 /* 16 bit DMA size is in words */ 463 *size = channel >= 4? remain << 1 : remain;488 *size = is_dma16(channel) ? remain << 1 : remain; 464 489 return EOK; 465 490 }
Note:
See TracChangeset
for help on using the changeset viewer.