summaryrefslogtreecommitdiff
path: root/PciReworkHowto.mdwn
diff options
context:
space:
mode:
authorAlanCoopersmith <AlanCoopersmith@web>2013-09-14 18:37:24 -0700
committerxorg <iki-xorg@freedesktop.org>2013-09-14 18:37:24 -0700
commit4701c3bb3064507cf20b963aef115658b3a393d3 (patch)
tree719e2dd58b86bc3f7d852869dfd837adb2378e44 /PciReworkHowto.mdwn
parentf97d0aee0fae9acf6c1eff607e8b9d1e9fa18a5a (diff)
fix formatting after moin->iki conversion
Diffstat (limited to 'PciReworkHowto.mdwn')
-rw-r--r--PciReworkHowto.mdwn82
1 files changed, 40 insertions, 42 deletions
diff --git a/PciReworkHowto.mdwn b/PciReworkHowto.mdwn
index 301baf5d..0672b57d 100644
--- a/PciReworkHowto.mdwn
+++ b/PciReworkHowto.mdwn
@@ -1,13 +1,11 @@
-
-
## PCI Rework HOWTO
-Here's a list of steps you need to take to convert a video driver to the new libpciaccess library. Please feel free to fix this page where you find it inaccurate or incomplete. The examples here are from the intel driver and assume that you want to continue allowing the driver to be built with older X servers by making all of the changes conditional on whether the server uses libpciaccess.
+Here's a list of steps you need to take to convert a video driver to the new libpciaccess library. Please feel free to fix this page where you find it inaccurate or incomplete. The examples here are from the intel driver and assume that you want to continue allowing the driver to be built with older X servers by making all of the changes conditional on whether the server uses libpciaccess.
### configure.ac changes
-This patch adds a check to see if the X server is using libpciaccess (the server will have XSERVER_LIBPCIACCESS defined in xorg-server.h), then makes sure the pciaccess package is installed and available.
+This patch adds a check to see if the X server is using libpciaccess (the server will have XSERVER_LIBPCIACCESS defined in xorg-server.h), then makes sure the pciaccess package is installed and available.
[[!format txt """
@@ -18,31 +16,31 @@ This patch adds a check to see if the X server is using libpciaccess (the server
+ [XSERVER_LIBPCIACCESS=yes],[XSERVER_LIBPCIACCESS=no],
+ [#include "xorg-server.h"])
CFLAGS="$save_CFLAGS"
-
+
+if test x$XSERVER_LIBPCIACCESS = xyes; then
+ PKG_CHECK_MODULES([PCIACCESS], [pciaccess >= 0.8.0])
+fi
+
+AM_CONDITIONAL(XSERVER_LIBPCIACCESS, test "x$XSERVER_LIBPCIACCESS" = xyes)
AM_CONDITIONAL(XMODES, test "x$XMODES" = xno)
-
+
if test "x$XSERVER_SOURCE" = x; then
"""]]
-
-Note: I have always encountered the xorg header files in /usr/include/xorg/, so i corrected the include. If this is not the usual location, please revert it.
+
+Note: I have always encountered the xorg header files in /usr/include/xorg/, so i corrected the include. If this is not the usual location, please revert it.
### pciVideoPtr → struct pci_device *
-In the [[ScrnInfoRec|ScrnInfoRec]] driver private structure, there is a pointer to the pciVideoPtr structure which contains identification information about the associated PCI device. libpciaccess has a parallel structure, struct pci_device which contains the same information using different names. Another change here is to compute (and store) the PCI base address register indices in this structure; mapping PCI space now requires using these register indices instead of just the physical address of the hardware.
+In the `ScrnInfoRec` driver private structure, there is a pointer to the pciVideoPtr structure which contains identification information about the associated PCI device. libpciaccess has a parallel structure, struct pci_device which contains the same information using different names. Another change here is to compute (and store) the PCI base address register indices in this structure; mapping PCI space now requires using these register indices instead of just the physical address of the hardware.
[[!format txt """
@ -61,6 +61,11 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "xf86Crtc.h"
#include "xf86RandR12.h"
-
+
+#include "xorg-server.h"
+#ifdef XSERVER_LIBPCIACCESS
+#include <pciaccess.h>
@@ -65,13 +63,13 @@ In the [[ScrnInfoRec|ScrnInfoRec]] driver private structure, there is a pointer
PCITAG PciTag;
+#endif
CARD8 variant;
-
+
unsigned int BR[20];
"""]]
### Macros to fetch PCI device ids
-Instead of changing the code to have conditional use of these new structures everywhere, we create macros to fetch various PCI identification data from either the old or new structures. Now, everywhere the driver used to refer to one of the old fields, just replace that using one of these macros. Placing these macros in your header file keeps the driver building against older servers.
+Instead of changing the code to have conditional use of these new structures everywhere, we create macros to fetch various PCI identification data from either the old or new structures. Now, everywhere the driver used to refer to one of the old fields, just replace that using one of these macros. Placing these macros in your header file keeps the driver building against older servers.
[[!format txt """
@@ -94,7 +92,7 @@ Instead of changing the code to have conditional use of these new structures eve
### DRI interface changes
-This change is simple; DRI needs to know the PCI address of the video card in several places, as these values are now stored in a new structure, the code must change to reflect the new names.
+This change is simple; DRI needs to know the PCI address of the video card in several places, as these values are now stored in a new structure, the code must change to reflect the new names.
[[!format txt """
@@ -115,7 +113,7 @@ This change is simple; DRI needs to know the PCI address of the video card in se
pDRIInfo->ddxDriverMajorVersion = I810_MAJOR_VERSION;
pDRIInfo->ddxDriverMinorVersion = I810_MINOR_VERSION;
@@ -972,12 +978,20 @@ I810DRIScreenInit(ScreenPtr pScreen)
-
+
if (!pI810DRI->irq) {
pI810DRI->irq = drmGetInterruptFromBusID(pI810->drmSubFD,
+#if XSERVER_LIBPCIACCESS
@@ -139,7 +137,7 @@ This change is simple; DRI needs to know the PCI address of the video card in se
@@ -991,7 +1005,7 @@ I810DRIScreenInit(ScreenPtr pScreen)
xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"[drm] dma control initialized, using IRQ %d\n", pI810DRI->irq);
-
+
- pI810DRI->deviceID = pI810->PciInfo->chipType;
+ pI810DRI->deviceID = DEVICE_ID(pI810->PciInfo);
pI810DRI->width = pScrn->virtualX;
@@ -149,22 +147,22 @@ This change is simple; DRI needs to know the PCI address of the video card in se
### Mechanical API conversions
-Where your driver code calls various pci access functions, you need to mechanically convert them to using functions from libpciaccess
+Where your driver code calls various pci access functions, you need to mechanically convert them to using functions from libpciaccess
[[!table header="no" class="mointable" data="""
Mapping built-in PCI functions to libpciaccess functions|||
- Built-in | libpciaccess
- xf86ReadPciBIOS | pci_device_read_rom
- pciReadByte | pci_device_cfg_read_u8
- pciReadWord | pci_device_cfg_read_u16
- pciReadLong | pci_device_cfg_read_u32
+ Built-in | libpciaccess
+ xf86ReadPciBIOS | pci_device_read_rom
+ pciReadByte | pci_device_cfg_read_u8
+ pciReadWord | pci_device_cfg_read_u16
+ pciReadLong | pci_device_cfg_read_u32
"""]]
### Listing the supported devices
-The device probing function will now relies on the libpciaccess code to identify all devices automatically. The match works much like the kernel; you fill in a description of which devices your driver supports and the library finds the available devices on the system.
+The device probing function will now relies on the libpciaccess code to identify all devices automatically. The match works much like the kernel; you fill in a description of which devices your driver supports and the library finds the available devices on the system.
-Here's a list of all of the devices supported by the intel driver:
+Here's a list of all of the devices supported by the intel driver:
[[!format txt """
@@ -207,7 +205,7 @@ Here's a list of all of the devices supported by the intel driver:
### DriverRec changes
-The exported [[DriverRec|DriverRec]] has some new fields that refer to the above list of devices and a new libpciaccess-compatible probe function. Note that the structure places NULL for the old Probe field while listing the new probe function in the new slot.
+The exported `DriverRec` has some new fields that refer to the above list of devices and a new libpciaccess-compatible probe function. Note that the structure places NULL for the old Probe field while listing the new probe function in the new slot.
[[!format txt """
@@ -234,7 +232,7 @@ _X_EXPORT DriverRec I810 = {
### Registering the driver with the system
-In your setup function, you'll be adding a driver to the system. To make the server know that your [[DriverRec|DriverRec]] contains the new fields for libpciaccess, you need to pass the [[HaveDriverFuncs|HaveDriverFuncs]] flag or the server will never call your new probe function:
+In your setup function, you'll be adding a driver to the system. To make the server know that your `DriverRec` contains the new fields for libpciaccess, you need to pass the `HaveDriverFuncs` or the server will never call your new probe function:
[[!format txt """
@@ -254,9 +252,9 @@ In your setup function, you'll be adding a driver to the system. To make the ser
### The new probe function
-The hardest part of the conversion is building a new probe function. This will replace your existing probe function when the server uses libpciaccess as the two mechanisms are incompatible.
+The hardest part of the conversion is building a new probe function. This will replace your existing probe function when the server uses libpciaccess as the two mechanisms are incompatible.
-Here's the new intel probe function
+Here's the new intel probe function
[[!format txt """
@@ -288,7 +286,7 @@ Here's the new intel probe function
+ scrn->Probe = NULL;
+
+ entity = xf86GetEntityInfo (entity_num);
-+
++
+ switch (DEVICE_ID(device)) {
+#ifndef I830_ONLY
+ case PCI_CHIP_I810:
@@ -319,12 +317,12 @@ Here's the new intel probe function
+ */
+ xf86SetEntitySharable(entity_num);
+
-+ /* Allocate an entity private if necessary */
-+ if (I830EntityIndex < 0)
-+ I830EntityIndex = xf86AllocateEntityPrivateIndex();
++ /* Allocate an entity private if necessary */
++ if (I830EntityIndex < 0)
++ I830EntityIndex = xf86AllocateEntityPrivateIndex();
+
+ private = xf86GetEntityPrivate(scrn->entityList[0],
-+ I830EntityIndex);
++ I830EntityIndex);
+ i830_ent = private->ptr;
+ if (!i830_ent)
+ {
@@ -340,9 +338,9 @@ Here's the new intel probe function
+ * the "slave".
+ */
+ i830_ent->lastInstance++;
-+ xf86SetEntityInstanceForScreen(scrn,
++ xf86SetEntityInstanceForScreen(scrn,
+ scrn->entityList[0],
-+ i830_ent->lastInstance);
++ i830_ent->lastInstance);
+ I830InitpScrn(scrn);
+ break;
+ }
@@ -353,9 +351,9 @@ Here's the new intel probe function
### Mapping device regions
-The final changes here affect how the driver maps bus regions into the server address space. This is a fairly mechanical change, except that the driver must know which BAR refers to each portion of the card address space.
+The final changes here affect how the driver maps bus regions into the server address space. This is a fairly mechanical change, except that the driver must know which BAR refers to each portion of the card address space.
-Here's a sample patch that maps the intel MMIO region:
+Here's a sample patch that maps the intel MMIO region:
[[!format txt """
@@ -366,16 +364,16 @@ Here's a sample patch that maps the intel MMIO region:
+ struct pci_device *const device = pI810->PciInfo;
+ int err;
+#endif
-
+
#if !defined(__alpha__)
mmioFlags = VIDMEM_MMIO | VIDMEM_READSIDEEFFECT;
@@ -1211,11 +1408,23 @@ I810MapMMIO(ScrnInfoPtr pScrn)
mmioFlags = VIDMEM_MMIO | VIDMEM_READSIDEEFFECT | VIDMEM_SPARSE;
#endif
-
+
+#if XSERVER_LIBPCIACCESS
+ err = pci_device_map_region (device, pI810->mmio_bar, TRUE);
-+ if (err)
++ if (err)
+ {
+ xf86DrvMsg (pScrn->scrnIndex, X_ERROR,
+ "Unable to map mmio BAR. %s (%d)\n",
@@ -393,14 +391,14 @@ Here's a sample patch that maps the intel MMIO region:
return TRUE;
}
"""]]
-Unmapping requires similar changes:
+Unmapping requires similar changes:
[[!format txt """
@ -1246,8 +1472,12 @@ I810UnmapMMIO(ScrnInfoPtr pScrn)
{
I810Ptr pI810 = I810PTR(pScrn);
-
+
+#if XSERVER_LIBPCIACCESS
+ pci_device_unmap_region (pI810->PciInfo, pI810->mmio_bar);
+#else
@@ -413,4 +411,4 @@ Unmapping requires similar changes:
### That's it
-The steps above are all that I found necessary to convert the intel driver; of course there are lots of other changes than the short patch excerpts here, but they're all available by looking at the intel driver git log.
+The steps above are all that I found necessary to convert the intel driver; of course there are lots of other changes than the short patch excerpts here, but they're all available by looking at the intel driver git log.