Module Name:    src
Committed By:   riastradh
Date:           Wed Jul 24 03:20:05 UTC 2013

Modified Files:
        src/sys/external/bsd/drm2/include/linux [riastradh-drm2]: pci.h

Log Message:
Add pci_{read,write}_config_byte to <linux/pci.h>.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.11 -r1.1.2.12 \
    src/sys/external/bsd/drm2/include/linux/pci.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/include/linux/pci.h
diff -u src/sys/external/bsd/drm2/include/linux/pci.h:1.1.2.11 src/sys/external/bsd/drm2/include/linux/pci.h:1.1.2.12
--- src/sys/external/bsd/drm2/include/linux/pci.h:1.1.2.11	Wed Jul 24 03:18:24 2013
+++ src/sys/external/bsd/drm2/include/linux/pci.h	Wed Jul 24 03:20:05 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci.h,v 1.1.2.11 2013/07/24 03:18:24 riastradh Exp $	*/
+/*	$NetBSD: pci.h,v 1.1.2.12 2013/07/24 03:20:05 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -106,34 +106,57 @@ pci_read_config_dword(struct pci_dev *pd
 }
 
 static inline void
-pci_write_config_dword(struct pci_dev *pdev, int reg, uint32_t value)
+pci_read_config_word(struct pci_dev *pdev, int reg, uint16_t *valuep)
 {
-	KASSERT(!ISSET(reg, 3));
-	pci_conf_write(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg, value);
+	KASSERT(!ISSET(reg, 1));
+	*valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag,
+	    (reg &~ 3)) >> (8 * (reg & 3));
 }
 
 static inline void
-pci_read_config_word(struct pci_dev *pdev, int reg, uint16_t *valuep)
+pci_read_config_byte(struct pci_dev *pdev, int reg, uint8_t *valuep)
 {
-	KASSERT(!ISSET(reg, 1));
 	*valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag,
-	    (reg &~ 3)) >> (ISSET(reg, 3)? 16 : 0);
+	    (reg &~ 1)) >> (8 * (reg & 1));
 }
 
 static inline void
-pci_write_config_word(struct pci_dev *pdev, int reg, uint16_t value)
+pci_write_config_dword(struct pci_dev *pdev, int reg, uint32_t value)
 {
+	KASSERT(!ISSET(reg, 3));
+	pci_conf_write(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg, value);
+}
+
+static inline void
+pci_rmw_config(struct pci_dev *pdev, int reg, unsigned int bytes,
+    uint32_t value)
+{
+	const uint32_t mask = ~((~0UL) << (8 * bytes));
 	const int reg32 = (reg &~ 3);
-	const unsigned int shift = (ISSET(reg, 3)? 16 : 0);
+	const unsigned int shift = (8 * (reg & 3));
 	uint32_t value32;
 
-	KASSERT(!ISSET(reg, 1));
+	KASSERT(bytes <= 4);
+	KASSERT(!ISSET(value, ~mask));
 	pci_read_config_dword(pdev, reg32, &value32);
-	value32 &=~ (0xffffUL << shift);
+	value32 &=~ (mask << shift);
 	value32 |= (value << shift);
 	pci_write_config_dword(pdev, reg32, value32);
 }
 
+static inline void
+pci_write_config_word(struct pci_dev *pdev, int reg, uint16_t value)
+{
+	KASSERT(!ISSET(reg, 1));
+	pci_rmw_config(pdev, reg, 2, value);
+}
+
+static inline void
+pci_write_config_byte(struct pci_dev *pdev, int reg, uint8_t value)
+{
+	pci_rmw_config(pdev, reg, 1, value);
+}
+
 /*
  * XXX pci msi
  */

Reply via email to