[PATCH v13 01/16] PCI: Let pci_mmap_page_range() take resource address

Yinghai Lu yinghai at kernel.org
Thu Jun 23 05:22:56 AEST 2016


On Wed, Jun 22, 2016 at 8:22 AM, Bjorn Helgaas <helgaas at kernel.org> wrote:
> On Tue, Jun 21, 2016 at 09:32:49PM -0700, Yinghai Lu wrote:
>
> If sparc is broken, let's make this a tiny sparc-only patch that fixes
> only the breakage -- no cleanup or restructuring.  Then we can do the
> more extensive work in a separate patch.

ok. please check attached two patches that take position for
[PATCH v13 01/16]

>
> The example mmap() I keep asking for would be very helpful to me in
> understanding the problem.  It would probably also help folks who
> maintain user programs that use mmap.  They need to figure out whether
> they have code that worked most places but has always been broken on
> sparc, or code that depended on the previous sparc behavior and will
> be broken by this change, or what.

ok.

calling : ./test_mmap_proc /proc/bus/pci/0000:00/04.0 0x2000000

code : test_mmap_proc.c

#include <stdio.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define PCIIOC_BASE             ('P' << 24 | 'C' << 16 | 'I' << 8)
#define PCIIOC_CONTROLLER       (PCIIOC_BASE | 0x00)    /* Get
controller for PCI device. */
#define PCIIOC_MMAP_IS_IO       (PCIIOC_BASE | 0x01)    /* Set mmap
state to I/O space. */
#define PCIIOC_MMAP_IS_MEM      (PCIIOC_BASE | 0x02)    /* Set mmap
state to MEM space. */
#define PCIIOC_WRITE_COMBINE    (PCIIOC_BASE | 0x03)    /*
Enable/disable write-combining. */

/* sparc64 */
#define PAGE_SHIFT 13
#define PAGE_SIZE (1UL << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE-1))

int main(int argc, char *argv[])
{
  int i;
  int fd;
  char *addr;
  unsigned long offset = 0;
  unsigned long left = 0;

  fd = open(argv[1], O_RDONLY);
  if (fd < 0) {
    perror("open");
    return 1;
  }

  if (argc > 2)
     sscanf(argv[2], "0x%lx", &offset);

  left = offset & (PAGE_SIZE - 1);
  offset &= PAGE_MASK;

  ioctl(fd, PCIIOC_MMAP_IS_MEM);
  addr = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_SHARED, fd, offset);
  if (addr == MAP_FAILED) {
    perror("mmap");
    return 1;
  }

  printf("map finished\n");


  for (i = 0; i < 8; i++)
    printf("%x ", addr[i + left]);
  printf("\n");

  munmap(addr, PAGE_SIZE);

  close(fd);

  return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: new_pci_mmap_page_range_5_2_0.patch
Type: text/x-patch
Size: 2530 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20160622/ada66af3/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: new_pci_mmap_page_range_5_2_1.patch
Type: text/x-patch
Size: 9998 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20160622/ada66af3/attachment-0001.bin>


More information about the Linuxppc-dev mailing list