Wed Jul 24 03:20:05 2013 UTC ()
Add pci_{read,write}_config_byte to <linux/pci.h>.


(riastradh)
diff -r1.1.2.11 -r1.1.2.12 src/sys/external/bsd/drm2/include/linux/pci.h

cvs diff -r1.1.2.11 -r1.1.2.12 src/sys/external/bsd/drm2/include/linux/pci.h (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/include/linux/pci.h 2013/07/24 03:18:24 1.1.2.11
+++ src/sys/external/bsd/drm2/include/linux/pci.h 2013/07/24 03:20:05 1.1.2.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pci.h,v 1.1.2.11 2013/07/24 03:18:24 riastradh Exp $ */ 1/* $NetBSD: pci.h,v 1.1.2.12 2013/07/24 03:20:05 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc. 4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell. 8 * by Taylor R. Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -96,54 +96,77 @@ pci_find_capability(struct pci_dev *pdev @@ -96,54 +96,77 @@ pci_find_capability(struct pci_dev *pdev
96{ 96{
97 return pci_get_capability(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, cap, 97 return pci_get_capability(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, cap,
98 NULL, NULL); 98 NULL, NULL);
99} 99}
100 100
101static inline void 101static inline void
102pci_read_config_dword(struct pci_dev *pdev, int reg, uint32_t *valuep) 102pci_read_config_dword(struct pci_dev *pdev, int reg, uint32_t *valuep)
103{ 103{
104 KASSERT(!ISSET(reg, 3)); 104 KASSERT(!ISSET(reg, 3));
105 *valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg); 105 *valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg);
106} 106}
107 107
108static inline void 108static inline void
109pci_write_config_dword(struct pci_dev *pdev, int reg, uint32_t value) 109pci_read_config_word(struct pci_dev *pdev, int reg, uint16_t *valuep)
110{ 110{
111 KASSERT(!ISSET(reg, 3)); 111 KASSERT(!ISSET(reg, 1));
112 pci_conf_write(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg, value); 112 *valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag,
 113 (reg &~ 3)) >> (8 * (reg & 3));
113} 114}
114 115
115static inline void 116static inline void
116pci_read_config_word(struct pci_dev *pdev, int reg, uint16_t *valuep) 117pci_read_config_byte(struct pci_dev *pdev, int reg, uint8_t *valuep)
117{ 118{
118 KASSERT(!ISSET(reg, 1)); 
119 *valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, 119 *valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag,
120 (reg &~ 3)) >> (ISSET(reg, 3)? 16 : 0); 120 (reg &~ 1)) >> (8 * (reg & 1));
121} 121}
122 122
123static inline void 123static inline void
124pci_write_config_word(struct pci_dev *pdev, int reg, uint16_t value) 124pci_write_config_dword(struct pci_dev *pdev, int reg, uint32_t value)
125{ 125{
 126 KASSERT(!ISSET(reg, 3));
 127 pci_conf_write(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg, value);
 128}
 129
 130static inline void
 131pci_rmw_config(struct pci_dev *pdev, int reg, unsigned int bytes,
 132 uint32_t value)
 133{
 134 const uint32_t mask = ~((~0UL) << (8 * bytes));
126 const int reg32 = (reg &~ 3); 135 const int reg32 = (reg &~ 3);
127 const unsigned int shift = (ISSET(reg, 3)? 16 : 0); 136 const unsigned int shift = (8 * (reg & 3));
128 uint32_t value32; 137 uint32_t value32;
129 138
130 KASSERT(!ISSET(reg, 1)); 139 KASSERT(bytes <= 4);
 140 KASSERT(!ISSET(value, ~mask));
131 pci_read_config_dword(pdev, reg32, &value32); 141 pci_read_config_dword(pdev, reg32, &value32);
132 value32 &=~ (0xffffUL << shift); 142 value32 &=~ (mask << shift);
133 value32 |= (value << shift); 143 value32 |= (value << shift);
134 pci_write_config_dword(pdev, reg32, value32); 144 pci_write_config_dword(pdev, reg32, value32);
135} 145}
136 146
 147static inline void
 148pci_write_config_word(struct pci_dev *pdev, int reg, uint16_t value)
 149{
 150 KASSERT(!ISSET(reg, 1));
 151 pci_rmw_config(pdev, reg, 2, value);
 152}
 153
 154static inline void
 155pci_write_config_byte(struct pci_dev *pdev, int reg, uint8_t value)
 156{
 157 pci_rmw_config(pdev, reg, 1, value);
 158}
 159
137/* 160/*
138 * XXX pci msi 161 * XXX pci msi
139 */ 162 */
140static inline void 163static inline void
141pci_enable_msi(struct pci_dev *pdev) 164pci_enable_msi(struct pci_dev *pdev)
142{ 165{
143 KASSERT(!pdev->msi_enabled); 166 KASSERT(!pdev->msi_enabled);
144 pdev->msi_enabled = true; 167 pdev->msi_enabled = true;
145} 168}
146 169
147static inline void 170static inline void
148pci_disable_msi(struct pci_dev *pdev) 171pci_disable_msi(struct pci_dev *pdev)
149{ 172{