Here’s a small example from a real project. Even if you don’t use
DMA, use _PMF_DMA_SAFE flag to tell the OS you need a
contiguos chunk of memory. Good luck.
typedef struct
{
int segno; /* segment number /
int seglen; / segment length /
paddr_t phys_addr; / physical address /
caddr_t bufp; / logical address */
} dmabuf_t;
int alloc_dmabuf(dmabuf_t *p, int nbytes)
{
struct _seginfo sbuf;
int selector;
int fd;
/* allocate memory */
if ((selector = qnx_segment_alloc_flags(nbytes,
_PMF_DMA_SAFE | _PMF_DMA_HIGH | _PMF_NOCACHE)) == -1)
return -1;
/* get physical address */
if (qnx_segment_info(PROC_PID, 0, selector, &sbuf) == -1)
qnx_segment_free(selector);
return -1;
}
p->phys_addr = sbuf.addr;
p->segno = selector;
p->seglen = nbytes;
/* map to the buffer */
if ((fd=shm_open(“Physical”,O_RDWR,0)) == -1)
qnx_segment_free(selector);
return -1;
}
p->bufp = (caddr_t)mmap(0,nbytes,
PROT_READ|PROT_WRITE|PROT_NOCACHE,
MAP_SHARED,fd, p->phys_addr);
close(fd);
if (p->phys_addr == (paddr_t)-1)
qnx_segment_free(selector);
return -1;
}
return 0;
}
int free_dmabuf(dmabuf_t *p)
{
munmap(p->bufp,p->seglen);
qnx_segment_free(p->segno);
return 0;
}
Enjoy
“Jay Marchetti” <marchetti@pittsburghfirmware.com> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ ×
ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ: news:aa9mfl$t8$1@inn.qnx.com…
I’m building an interface between 2 QNX4.25 machines that uses the
dataBLIZZARD PCI card from SBS Technologies. This card maps PCI resources
between the machines for very low latency data transfers.
In QNX4, how do I malloc a small (say 8K bytes) chunk of non-page-able
memory and then obtain the physical address of it? I need the physical
address to initialize the dataBLIZZARD card so that the other machine can
make accesses to this memory.
Thanks in advance…
Jay Marchetti
Pittsburgh Firmware, Inc.