在SUSE中,mmap到PCI栏失败

时间:2018-05-15 10:42:31

标签: linux mmap opensuse pci sles

我正在尝试将mmap应用到PCI CSR栏。 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);
}

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失败,错误字符串&#34;无效的参数&#34;。相同的代码段在RHEL 7.2中工作正常,但在SLES15操作系统中失败。

0 个答案:

没有答案