我正在尝试对 PCI CSR 栏进行 mmap。mmap 失败并出现错误 EINVAL。下面是我的代码片段。
snprintf(csr_bar_path,256,"/sys/bus/pci/devices/0000:16:00.0/resource2");
csr_fd = open(csr_bar_path,O_RDWR | O_SYNC);
if(csr_fd < 0)
{
printf("Cannot open CSR bar file %s\n",csr_bar_path);
}
if(fstat(csr_fd,&sb) == -1)
{
printf("CSR file size = %d\n",sb.st_size);
close(csr_fd);
}
printf("CSR file size OK = %d\n",sb.st_size);
csr_bar = (unsigned char *)mmap(NULL,sb.st_size,PROT_READ |
PROT_WRITE,MAP_SHARED,csr_fd,0);
if(csr_bar == (void *) -1)
{
printf("mmap failed for CSR bar %s %d\n",strerror(errno),errno);
close(csr_fd);
}
为 sb.st_size 获得的值为 65536。但 mmap 失败,错误字符串为“无效参数”。相同的代码片段在 RHEL 7.2 中运行良好,但在 SLES15 操作系统中失败。