| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: pci.h,v 1.1.2.8 2013/07/24 03:04:18 riastradh Exp $ */ | | 1 | /* $NetBSD: pci.h,v 1.1.2.9 2013/07/24 03:10:37 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. |
| @@ -54,35 +54,59 @@ struct pci_dev { | | | @@ -54,35 +54,59 @@ struct pci_dev { |
54 | | | 54 | |
55 | #define PCI_CAP_ID_AGP PCI_CAP_AGP | | 55 | #define PCI_CAP_ID_AGP PCI_CAP_AGP |
56 | | | 56 | |
57 | static inline int | | 57 | static inline int |
58 | pci_find_capability(struct pci_dev *pdev, int cap) | | 58 | pci_find_capability(struct pci_dev *pdev, int cap) |
59 | { | | 59 | { |
60 | return pci_get_capability(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, cap, | | 60 | return pci_get_capability(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, cap, |
61 | NULL, NULL); | | 61 | NULL, NULL); |
62 | } | | 62 | } |
63 | | | 63 | |
64 | static inline void | | 64 | static inline void |
65 | pci_read_config_dword(struct pci_dev *pdev, int reg, uint32_t *valuep) | | 65 | pci_read_config_dword(struct pci_dev *pdev, int reg, uint32_t *valuep) |
66 | { | | 66 | { |
| | | 67 | KASSERT(!ISSET(reg, 3)); |
67 | *valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg); | | 68 | *valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg); |
68 | } | | 69 | } |
69 | | | 70 | |
70 | static inline void | | 71 | static inline void |
71 | pci_write_config_dword(struct pci_dev *pdev, int reg, uint32_t value) | | 72 | pci_write_config_dword(struct pci_dev *pdev, int reg, uint32_t value) |
72 | { | | 73 | { |
| | | 74 | KASSERT(!ISSET(reg, 3)); |
73 | pci_conf_write(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg, value); | | 75 | pci_conf_write(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, reg, value); |
74 | } | | 76 | } |
75 | | | 77 | |
| | | 78 | static inline void |
| | | 79 | pci_read_config_word(struct pci_dev *pdev, int reg, uint16_t *valuep) |
| | | 80 | { |
| | | 81 | KASSERT(!ISSET(reg, 1)); |
| | | 82 | *valuep = pci_conf_read(pdev->pd_pa.pa_pc, pdev->pd_pa.pa_tag, |
| | | 83 | (reg &~ 3)) >> (ISSET(reg, 3)? 16 : 0); |
| | | 84 | } |
| | | 85 | |
| | | 86 | static inline void |
| | | 87 | pci_write_config_word(struct pci_dev *pdev, int reg, uint16_t value) |
| | | 88 | { |
| | | 89 | const int reg32 = (reg &~ 3); |
| | | 90 | const unsigned int shift = (ISSET(reg, 3)? 16 : 0); |
| | | 91 | uint32_t value32; |
| | | 92 | |
| | | 93 | KASSERT(!ISSET(reg, 1)); |
| | | 94 | pci_read_config_dword(pdev, reg32, &value32); |
| | | 95 | value32 &=~ (0xffffUL << shift); |
| | | 96 | value32 |= (value << shift); |
| | | 97 | pci_write_config_dword(pdev, reg32, value32); |
| | | 98 | } |
| | | 99 | |
76 | /* | | 100 | /* |
77 | * XXX pci msi | | 101 | * XXX pci msi |
78 | */ | | 102 | */ |
79 | static inline void | | 103 | static inline void |
80 | pci_enable_msi(struct pci_dev *pdev) | | 104 | pci_enable_msi(struct pci_dev *pdev) |
81 | { | | 105 | { |
82 | KASSERT(!pdev->msi_enabled); | | 106 | KASSERT(!pdev->msi_enabled); |
83 | pdev->msi_enabled = true; | | 107 | pdev->msi_enabled = true; |
84 | } | | 108 | } |
85 | | | 109 | |
86 | static inline void | | 110 | static inline void |
87 | pci_disable_msi(struct pci_dev *pdev) | | 111 | pci_disable_msi(struct pci_dev *pdev) |
88 | { | | 112 | { |