[Xorg-driver-geode] libpciaccess patch - please test!

Jordan Crouse jordan.crouse at amd.com
Mon Mar 10 09:03:56 PDT 2008


On 10/03/08 12:02 +0200, Martin-Éric Racine wrote:
> Core X.org developer David Airlie contributed these changes. Please
> test them by applying against 2.7.7.6 and report any anomaly you
> experience.
> 
> Jordan: is this what you had in mind?

Looks like David went ahead and committed the code.  please test immediately,
especially people who are still pre libpciaccess.

Jordan

> -- 
> Martin-Éric Racine
> http://q-funk.iki.fi

> diff --git a/configure.ac b/configure.ac
> index c219e06..b13576f 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -86,10 +86,21 @@ PKG_CHECK_MODULES(XORG, [xorg-server xproto fontsproto $REQUIRED_MODULES])
>  sdkdir=$(pkg-config --variable=sdkdir xorg-server)
>  
>  # Checks for libraries.
> +SAVE_CPPFLAGS="$CPPFLAGS"
> +CPPFLAGS="$CPPFLAGS $XORG_CFLAGS"
> +AC_CHECK_DECL(XSERVER_LIBPCIACCESS,
> +              [XSERVER_LIBPCIACCESS=yes],[XSERVER_LIBPCIACCESS=no],
> +              [#include "xorg-server.h"])
> +CPPFLAGS="$SAVE_CPPFLAGS"
>  
>  # Checks for header files.
>  AC_HEADER_STDC
>  
> +if test "x$XSERVER_LIBPCIACCESS" = xyes; then
> +    PKG_CHECK_MODULES([PCIACCESS], [pciaccess >= 0.8.0])
> +    XORG_CFLAGS="$XORG_CFLAGS $PCIACCESS_CFLAGS"
> +fi
> +
>  AC_SUBST([XORG_CFLAGS])
>  AC_SUBST([moduledir])
>  AC_SUBST([AMD_CFLAGS])
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 9da493e..035007a 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -64,7 +64,8 @@ amd_drv_la_SOURCES = \
>  	amd_lx_rotate.c \
>  	amd_lx_randr.c \
>  	amd_lx_exa.c \
> -        cimarron.c
> +        cimarron.c \
> +	amd_pcirename.h
>  
>  EXTRA_DIST = \
>          cim/cim_defs.h \
> diff --git a/src/amd.h b/src/amd.h
> index 8eb2253..fe2ac54 100644
> --- a/src/amd.h
> +++ b/src/amd.h
> @@ -28,6 +28,8 @@
>  #ifndef _AMD_GEODE_H_
>  #define _AMD_GEODE_H_
>  
> +#include "amd_pcirename.h"
> +
>  #include "xaa.h"
>  #include "exa.h"
>  #include "xf86Cursor.h"
> diff --git a/src/amd_driver.c b/src/amd_driver.c
> index 42e49ba..b153295 100644
> --- a/src/amd_driver.c
> +++ b/src/amd_driver.c
> @@ -419,7 +419,10 @@ AmdProbe(DriverPtr drv, int flags)
>      }
>      DEBUGMSG(1, (0, X_INFO, "AmdProbe: Before MatchPciInstances!\n"));
>      /* PCI BUS */
> -    if (xf86GetPciVideoInfo()) {
> +#ifndef XSERVER_LIBPCIACCESS
> +    if (xf86GetPciVideoInfo()) 
> +#endif
> +    {
>          numUsed = xf86MatchPciInstances(AMD_NAME, PCI_VENDOR_ID_NS,
>              GeodeChipsets, GeodePCIchipsets,
>              devSections, numDevSections, drv, &usedChips);
> diff --git a/src/amd_gx_driver.c b/src/amd_gx_driver.c
> index da4fa0b..3c66d05 100644
> --- a/src/amd_gx_driver.c
> +++ b/src/amd_gx_driver.c
> @@ -317,7 +317,27 @@ GXSaveScreen(ScreenPtr pScrn, int mode)
>  
>  
>  /* Common function - used by the LX too */
> -
> +#ifdef XSERVER_LIBPCIACCESS
> +static inline void * map_pci_mem(ScrnInfoPtr pScrni, int vram,
> +				 struct pci_device *dev,
> +				 int bar, int size)
> +{
> +  void *ptr;
> +  void** result = (void**)&ptr;
> +  int map_size = size ? size : dev->regions[bar].size;
> +    
> +  int err = pci_device_map_range(dev,
> +				 dev->regions[bar].base_addr,
> +				 map_size,
> +				 PCI_DEV_MAP_FLAG_WRITABLE |
> +				 (vram ? PCI_DEV_MAP_FLAG_WRITE_COMBINE : 0),
> +				 result);
> +  
> +  if (err) 
> +    return NULL;
> +  return ptr;
> +}
> +#endif
>  
>  
>  extern unsigned long gfx_gx2_scratch_base;
> @@ -328,8 +348,9 @@ GXMapMem(ScrnInfoPtr pScrni)
>    GeodeRec *pGeode = GEODEPTR(pScrni);
>    int index = pScrni->scrnIndex;
>  
> -  pciVideoRec *pci = xf86GetPciInfoForEntity(pGeode->pEnt->index);
> +  pciVideoPtr pci = xf86GetPciInfoForEntity(pGeode->pEnt->index);
>  
> +#ifndef XSERVER_LIBPCIACCESS
>    gfx_virt_regptr = (unsigned char *)xf86MapVidMem(index, VIDMEM_MMIO,
>  						   pci->memBase[2], pci->size[2]);
>  
> @@ -341,6 +362,12 @@ GXMapMem(ScrnInfoPtr pScrni)
>  
>    gfx_virt_fbptr = (unsigned char *)xf86MapVidMem(index, VIDMEM_FRAMEBUFFER,
>  						  pci->memBase[0], pGeode->FBAvail);
> +#else
> +  gfx_virt_regptr = map_pci_mem(pScrni, 0, pci, 2, 0);
> +  gfx_virt_gpptr = map_pci_mem(pScrni, 0, pci, 1, 0);
> +  gfx_virt_vidptr = map_pci_mem(pScrni, 0, pci, 3, 0);
> +  gfx_virt_fbptr = map_pci_mem(pScrni, 1, pci, 0, pGeode->FBAvail);
> +#endif
>  
>    gfx_gx2_scratch_base = pGeode->FBAvail - 0x4000;
>  
> diff --git a/src/amd_gx_randr.c b/src/amd_gx_randr.c
> index a4fa743..96f3f5d 100644
> --- a/src/amd_gx_randr.c
> +++ b/src/amd_gx_randr.c
> @@ -33,6 +33,7 @@
>  #include "xf86.h"
>  #include "xf86Priv.h"
>  #include "xf86DDC.h"
> +#include "xf86Module.h"
>  #include "mipointer.h"
>  #include "windowstr.h"
>  #include <X11/extensions/randr.h>
> @@ -40,7 +41,6 @@
>  
>  #include "amd.h"
>  
> -static int GXRandRIndex;
>  static int GXRandRGeneration;
>  
>  typedef struct _GXRandRInfo
> @@ -55,7 +55,20 @@ typedef struct _GXRandRInfo
>      Rotation supported_rotations;      /* driver supported */
>  } XF86RandRInfoRec, *XF86RandRInfoPtr;
>  
> -#define XF86RANDRINFO(p)    ((XF86RandRInfoPtr) (p)->devPrivates[GXRandRIndex].ptr)
> +#define AMD_OLDPRIV (GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 4)
> +
> +#if AMD_OLDPRIV
> +
> +static int GXRandRIndex;
> +#define XF86RANDRINFO(p) ((XF86RandRInfoPtr) (p)->devPrivates[GXRandRIndex].ptr)
> +#else
> +
> +static DevPrivateKey GXRandRKey;
> +#define XF86RANDRINFO(p) ((XF86RandRInfoPtr) \
> +			  dixLookupPrivate(&(p)->devPrivates, GXRandRKey));
> +
> +
> +#endif
>  
>  static int
>  GXRandRModeRefresh(DisplayModePtr mode)
> @@ -299,10 +312,15 @@ GXRandRInit(ScreenPtr pScreen, int rotation)
>      rrScrPrivPtr rp;
>  
>      if (GXRandRGeneration != serverGeneration) {
> -	GXRandRIndex = AllocateScreenPrivateIndex();
>  	GXRandRGeneration = serverGeneration;
>      }
>  
> +#if AMD_OLDPRIV
> +    GXRandRIndex = AllocateScreenPrivateIndex();
> +#else
> +    GXRandRKey = &GXRandRKey;
> +#endif
> +
>      pRandr = xcalloc(sizeof(XF86RandRInfoRec), 1);
>      if (pRandr == NULL)
>  	return FALSE;
> @@ -326,6 +344,10 @@ GXRandRInit(ScreenPtr pScreen, int rotation)
>      pRandr->supported_rotations = rotation;
>      pRandr->maxX = pRandr->maxY = 0;
>  
> +#if AMD_OLDPRIV
>      pScreen->devPrivates[GXRandRIndex].ptr = pRandr;
> +#else
> +    dixSetPrivate(&pScreen->devPrivates, GXRandRKey, pRandr);
> +#endif
>      return TRUE;
>  }
> diff --git a/src/amd_lx_driver.c b/src/amd_lx_driver.c
> index a2db90e..6acd09f 100644
> --- a/src/amd_lx_driver.c
> +++ b/src/amd_lx_driver.c
> @@ -391,6 +391,27 @@ LXWriteMSR(unsigned long addr, unsigned long lo, unsigned long hi)
>      LX_MSR_WRITE(addr, lo, hi);
>  }
>  
> +#ifdef XSERVER_LIBPCIACCESS
> +static inline void * map_pci_mem(ScrnInfoPtr pScrni, int vram,
> +				 struct pci_device *dev,
> +				 int bar, int size)
> +{
> +  void *ptr;
> +  void** result = (void**)&ptr;
> +  int map_size = size ? size : dev->regions[bar].size;
> +    
> +  int err = pci_device_map_range(dev,
> +				 dev->regions[bar].base_addr,
> +				 map_size,
> +				 PCI_DEV_MAP_FLAG_WRITABLE |
> +				 (vram ? PCI_DEV_MAP_FLAG_WRITE_COMBINE : 0),
> +				 result);
> +  
> +  if (err) 
> +    return NULL;
> +  return ptr;
> +}
> +#endif
>  
>  static Bool
>  LXMapMem(ScrnInfoPtr pScrni)
> @@ -398,9 +419,12 @@ LXMapMem(ScrnInfoPtr pScrni)
>      GeodeRec *pGeode = GEODEPTR(pScrni);
>      int index = pScrni->scrnIndex;
>      unsigned long cmd_bfr_phys;
> +
> +    pciVideoPtr pci = xf86GetPciInfoForEntity(pGeode->pEnt->index);
> +
> +#ifndef XSERVER_LIBPCIACCESS
>      PCITAG tag;
>  
> -    pciVideoRec *pci = xf86GetPciInfoForEntity(pGeode->pEnt->index);
>      tag = pciTag(pci->bus, pci->device, pci->func);
>  
>      cim_gp_ptr = (unsigned char *)xf86MapPciMem(index, VIDMEM_MMIO,
> @@ -417,18 +441,26 @@ LXMapMem(ScrnInfoPtr pScrni)
>  
>      cim_fb_ptr = (unsigned char *)xf86MapPciMem(index, VIDMEM_FRAMEBUFFER,
>  						tag, pci->memBase[0], pGeode->FBAvail + CIM_CMD_BFR_SZ);
> +#else
> +    cim_gp_ptr = map_pci_mem(pScrni, 0, pci, 1, LX_GP_REG_SIZE);
> +    cim_vg_ptr = map_pci_mem(pScrni, 0, pci, 2, LX_VG_REG_SIZE);
> +    cim_vid_ptr = map_pci_mem(pScrni, 0, pci, 3, LX_VID_REG_SIZE);
> +    cim_vip_ptr = map_pci_mem(pScrni, 0, pci, 4, LX_VIP_REG_SIZE);
> +    cim_fb_ptr = map_pci_mem(pScrni, 1, pci, 0, pGeode->FBAvail + CIM_CMD_BFR_SZ);
> +#endif
>  
>      if (pScrni->memPhysBase == 0)
> -      pScrni->memPhysBase = pci->memBase[0];
> +      pScrni->memPhysBase = PCI_REGION_BASE(pci, 0, REGION_MEM);
> +      
>  
> -    cmd_bfr_phys = pci->memBase[0] + pGeode->CmdBfrOffset;
> +    cmd_bfr_phys = PCI_REGION_BASE(pci, 0, REGION_MEM) + pGeode->CmdBfrOffset;
>      cim_cmd_base_ptr = cim_fb_ptr + pGeode->CmdBfrOffset;
>  
>      if (!cim_gp_ptr || !cim_vg_ptr || !cim_vid_ptr || !cim_fb_ptr ||
>  	!cim_vip_ptr)
>        return FALSE;
>  
> -    gp_set_frame_buffer_base(pci->memBase[0], pGeode->FBAvail);
> +    gp_set_frame_buffer_base(PCI_REGION_BASE(pci, 0, REGION_MEM), pGeode->FBAvail);
>      gp_set_command_buffer_base(cmd_bfr_phys, 0, pGeode->CmdBfrSize);
>  
>      XpressROMPtr = xf86MapVidMem(index, VIDMEM_FRAMEBUFFER, 0xF0000, 0x10000);
> diff --git a/src/amd_lx_randr.c b/src/amd_lx_randr.c
> index e46ae20..155eefa 100644
> --- a/src/amd_lx_randr.c
> +++ b/src/amd_lx_randr.c
> @@ -40,7 +40,6 @@
>  
>  #include "amd.h"
>  
> -static int LXRandRIndex;
>  static int LXRandRGeneration;
>  
>  typedef struct _LXRandRInfo
> @@ -55,8 +54,20 @@ typedef struct _LXRandRInfo
>      Rotation supported_rotations;      /* driver supported */
>  } XF86RandRInfoRec, *XF86RandRInfoPtr;
>  
> +#define AMD_OLDPRIV (GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 4)
> +#if AMD_OLDPRIV
> +
> +static int LXRandRIndex;
>  #define XF86RANDRINFO(p) ((XF86RandRInfoPtr) (p)->devPrivates[LXRandRIndex].ptr)
>  
> +#else
> +
> +static DevPrivateKey LXRandRKey;
> +#define XF86RANDRINFO(p) ((XF86RandRInfoPtr) \
> +			  dixLookupPrivate(&(p)->devPrivates, LXRandRKey));
> +
> +#endif
> +
>  static int
>  LXRandRModeRefresh(DisplayModePtr mode)
>  {
> @@ -299,10 +310,15 @@ LXRandRInit(ScreenPtr pScreen, int rotation)
>      rrScrPrivPtr rp;
>  
>      if (LXRandRGeneration != serverGeneration) {
> -	LXRandRIndex = AllocateScreenPrivateIndex();
>  	LXRandRGeneration = serverGeneration;
>      }
>  
> +#if AMD_OLDPRIV
> +    LXRandRIndex = AllocateScreenPrivateIndex();
> +#else
> +    LXRandRKey = &LXRandRKey;
> +#endif
> +
>      pRandr = xcalloc(sizeof(XF86RandRInfoRec), 1);
>      if (pRandr == NULL)
>  	return FALSE;
> @@ -326,6 +342,10 @@ LXRandRInit(ScreenPtr pScreen, int rotation)
>      pRandr->supported_rotations = rotation;
>      pRandr->maxX = pRandr->maxY = 0;
>  
> +#if AMD_OLDPRIV
>      pScreen->devPrivates[LXRandRIndex].ptr = pRandr;
> +#else
> +    dixSetPrivate(&pScreen->devPrivates, LXRandRKey, pRandr);
> +#endif
>      return TRUE;
>  }
> diff --git a/src/amd_pcirename.h b/src/amd_pcirename.h
> new file mode 100644
> index 0000000..f0f5cf8
> --- /dev/null
> +++ b/src/amd_pcirename.h
> @@ -0,0 +1,122 @@
> +/*
> + * Copyright 2007 George Sapountzis
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + */
> +
> +/**
> + * Macros for porting drivers from legacy xfree86 PCI code to the pciaccess
> + * library. The main purpose being to facilitate source code compatibility.
> + */
> +
> +#ifndef CIRPCIRENAME_H
> +#define CIRPCIRENAME_H
> +
> +enum region_type {
> +    REGION_MEM,
> +    REGION_IO 
> +};
> +
> +#ifndef XSERVER_LIBPCIACCESS
> +
> +/* pciVideoPtr */
> +#define PCI_DEV_VENDOR_ID(_pcidev) ((_pcidev)->vendor)
> +#define PCI_DEV_DEVICE_ID(_pcidev) ((_pcidev)->chipType)
> +#define PCI_DEV_REVISION(_pcidev)  ((_pcidev)->chipRev)
> +
> +#define PCI_SUB_VENDOR_ID(_pcidev) ((_pcidev)->subsysVendor)
> +#define PCI_SUB_DEVICE_ID(_pcidev) ((_pcidev)->subsysCard)
> +
> +#define PCI_DEV_TAG(_pcidev) pciTag((_pcidev)->bus,    \
> +                                    (_pcidev)->device, \
> +                                    (_pcidev)->func)
> +#define PCI_DEV_BUS(_pcidev)       ((_pcidev)->bus)
> +#define PCI_DEV_DEV(_pcidev)       ((_pcidev)->device)
> +#define PCI_DEV_FUNC(_pcidev)      ((_pcidev)->func)
> +
> +/* pciConfigPtr */
> +#define PCI_CFG_TAG(_pcidev)  (((pciConfigPtr)(_pcidev)->thisCard)->tag)
> +#define PCI_CFG_BUS(_pcidev)  (((pciConfigPtr)(_pcidev)->thisCard)->busnum)
> +#define PCI_CFG_DEV(_pcidev)  (((pciConfigPtr)(_pcidev)->thisCard)->devnum)
> +#define PCI_CFG_FUNC(_pcidev) (((pciConfigPtr)(_pcidev)->thisCard)->funcnum)
> +
> +/* region addr: xfree86 uses different fields for memory regions and I/O ports */
> +#define PCI_REGION_BASE(_pcidev, _b, _type)             \
> +    (((_type) == REGION_MEM) ? (_pcidev)->memBase[(_b)] \
> +                             : (_pcidev)->ioBase[(_b)])
> +
> +/* region size: xfree86 uses the log2 of the region size,
> + * but with zero meaning no region, not size of one XXX */
> +#define PCI_REGION_SIZE(_pcidev, _b) \
> +    (((_pcidev)->size[(_b)] > 0) ? (1 << (_pcidev)->size[(_b)]) : 0)
> +
> +/* read/write PCI configuration space */
> +#define PCI_READ_BYTE(_pcidev, _value_ptr, _offset) \
> +    *(_value_ptr) = pciReadByte(PCI_CFG_TAG(_pcidev), (_offset))
> +
> +#define PCI_READ_LONG(_pcidev, _value_ptr, _offset) \
> +    *(_value_ptr) = pciReadLong(PCI_CFG_TAG(_pcidev), (_offset))
> +
> +#define PCI_WRITE_LONG(_pcidev, _value, _offset) \
> +    pciWriteLong(PCI_CFG_TAG(_pcidev), (_offset), (_value))
> +
> +#else /* XSERVER_LIBPCIACCESS */
> +
> +typedef struct pci_device *pciVideoPtr;
> +
> +#define PCI_DEV_VENDOR_ID(_pcidev) ((_pcidev)->vendor_id)
> +#define PCI_DEV_DEVICE_ID(_pcidev) ((_pcidev)->device_id)
> +#define PCI_DEV_REVISION(_pcidev)  ((_pcidev)->revision)
> +
> +#define PCI_SUB_VENDOR_ID(_pcidev) ((_pcidev)->subvendor_id)
> +#define PCI_SUB_DEVICE_ID(_pcidev) ((_pcidev)->subdevice_id)
> +
> +/* pci-rework functions take a 'pci_device' parameter instead of a tag */
> +#define PCI_DEV_TAG(_pcidev)        (_pcidev)
> +
> +/* PCI_DEV macros, typically used in printf's, add domain ? XXX */
> +#define PCI_DEV_BUS(_pcidev)       ((_pcidev)->bus)
> +#define PCI_DEV_DEV(_pcidev)       ((_pcidev)->dev)
> +#define PCI_DEV_FUNC(_pcidev)      ((_pcidev)->func)
> +
> +/* pci-rework functions take a 'pci_device' parameter instead of a tag */
> +#define PCI_CFG_TAG(_pcidev)        (_pcidev)
> +
> +/* PCI_CFG macros, typically used in DRI init, contain the domain */
> +#define PCI_CFG_BUS(_pcidev)      (((_pcidev)->domain << 8) | \
> +                                    (_pcidev)->bus)
> +#define PCI_CFG_DEV(_pcidev)       ((_pcidev)->dev)
> +#define PCI_CFG_FUNC(_pcidev)      ((_pcidev)->func)
> +
> +#define PCI_REGION_BASE(_pcidev, _b, _type) ((_pcidev)->regions[(_b)].base_addr)
> +#define PCI_REGION_SIZE(_pcidev, _b)        ((_pcidev)->regions[(_b)].size)
> +
> +#define PCI_READ_BYTE(_pcidev, _value_ptr, _offset) \
> +    pci_device_cfg_read_u8((_pcidev), (_value_ptr), (_offset))
> +
> +#define PCI_READ_LONG(_pcidev, _value_ptr, _offset) \
> +    pci_device_cfg_read_u32((_pcidev), (_value_ptr), (_offset))
> +
> +#define PCI_WRITE_LONG(_pcidev, _value, _offset) \
> +    pci_device_cfg_write_u32((_pcidev), (_value), (_offset))
> +
> +#endif /* XSERVER_LIBPCIACCESS */
> +
> +#endif /* CIRPCIRENAME_H */

> _______________________________________________
> Xorg-driver-geode mailing list
> Xorg-driver-geode at lists.x.org
> http://lists.x.org/mailman/listinfo/xorg-driver-geode


-- 
Jordan Crouse
Systems Software Development Engineer 
Advanced Micro Devices, Inc.



More information about the Xorg-driver-geode mailing list