| @@ -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 | |
101 | static inline void | | 101 | static inline void |
102 | pci_read_config_dword(struct pci_dev *pdev, int reg, uint32_t *valuep) | | 102 | pci_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 | |
108 | static inline void | | 108 | static inline void |
109 | pci_write_config_dword(struct pci_dev *pdev, int reg, uint32_t value) | | 109 | pci_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 | |
115 | static inline void | | 116 | static inline void |
116 | pci_read_config_word(struct pci_dev *pdev, int reg, uint16_t *valuep) | | 117 | pci_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 | |
123 | static inline void | | 123 | static inline void |
124 | pci_write_config_word(struct pci_dev *pdev, int reg, uint16_t value) | | 124 | pci_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 | |
| | | 130 | static inline void |
| | | 131 | pci_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 | |
| | | 147 | static inline void |
| | | 148 | pci_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 | |
| | | 154 | static inline void |
| | | 155 | pci_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 | */ |
140 | static inline void | | 163 | static inline void |
141 | pci_enable_msi(struct pci_dev *pdev) | | 164 | pci_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 | |
147 | static inline void | | 170 | static inline void |
148 | pci_disable_msi(struct pci_dev *pdev) | | 171 | pci_disable_msi(struct pci_dev *pdev) |
149 | { | | 172 | { |