| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: i915_pci_autoconf.c,v 1.5 2021/12/19 11:33:49 riastradh Exp $ */ | | 1 | /* $NetBSD: i915_pci_autoconf.c,v 1.6 2021/12/19 11:53:02 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. |
| @@ -20,27 +20,27 @@ | | | @@ -20,27 +20,27 @@ |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: i915_pci_autoconf.c,v 1.5 2021/12/19 11:33:49 riastradh Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: i915_pci_autoconf.c,v 1.6 2021/12/19 11:53:02 riastradh Exp $"); |
34 | | | 34 | |
35 | #include <sys/types.h> | | 35 | #include <sys/types.h> |
36 | #include <sys/queue.h> | | 36 | #include <sys/queue.h> |
37 | #include <sys/systm.h> | | 37 | #include <sys/systm.h> |
38 | #include <sys/queue.h> | | 38 | #include <sys/queue.h> |
39 | #include <sys/workqueue.h> | | 39 | #include <sys/workqueue.h> |
40 | | | 40 | |
41 | #include <drm/drm_pci.h> | | 41 | #include <drm/drm_pci.h> |
42 | | | 42 | |
43 | #include "i915_drv.h" | | 43 | #include "i915_drv.h" |
44 | #include "i915_pci.h" | | 44 | #include "i915_pci.h" |
45 | | | 45 | |
46 | struct drm_device; | | 46 | struct drm_device; |
| @@ -54,81 +54,81 @@ struct i915drmkms_softc { | | | @@ -54,81 +54,81 @@ struct i915drmkms_softc { |
54 | I915DRMKMS_TASK_ATTACH, | | 54 | I915DRMKMS_TASK_ATTACH, |
55 | I915DRMKMS_TASK_WORKQUEUE, | | 55 | I915DRMKMS_TASK_WORKQUEUE, |
56 | } sc_task_state; | | 56 | } sc_task_state; |
57 | union { | | 57 | union { |
58 | struct workqueue *workqueue; | | 58 | struct workqueue *workqueue; |
59 | struct i915drmkms_task_head attach; | | 59 | struct i915drmkms_task_head attach; |
60 | } sc_task_u; | | 60 | } sc_task_u; |
61 | struct drm_device *sc_drm_dev; | | 61 | struct drm_device *sc_drm_dev; |
62 | struct pci_dev sc_pci_dev; | | 62 | struct pci_dev sc_pci_dev; |
63 | bool sc_pci_attached; | | 63 | bool sc_pci_attached; |
64 | bool sc_dev_registered; | | 64 | bool sc_dev_registered; |
65 | }; | | 65 | }; |
66 | | | 66 | |
67 | static const struct intel_device_info * | | 67 | static const struct pci_device_id * |
68 | i915drmkms_pci_lookup(const struct pci_attach_args *); | | 68 | i915drmkms_pci_lookup(const struct pci_attach_args *); |
69 | | | 69 | |
70 | static int i915drmkms_match(device_t, cfdata_t, void *); | | 70 | static int i915drmkms_match(device_t, cfdata_t, void *); |
71 | static void i915drmkms_attach(device_t, device_t, void *); | | 71 | static void i915drmkms_attach(device_t, device_t, void *); |
72 | static void i915drmkms_attach_real(device_t); | | 72 | static void i915drmkms_attach_real(device_t); |
73 | static int i915drmkms_detach(device_t, int); | | 73 | static int i915drmkms_detach(device_t, int); |
74 | | | 74 | |
75 | static bool i915drmkms_suspend(device_t, const pmf_qual_t *); | | 75 | static bool i915drmkms_suspend(device_t, const pmf_qual_t *); |
76 | static bool i915drmkms_resume(device_t, const pmf_qual_t *); | | 76 | static bool i915drmkms_resume(device_t, const pmf_qual_t *); |
77 | | | 77 | |
78 | static void i915drmkms_task_work(struct work *, void *); | | 78 | static void i915drmkms_task_work(struct work *, void *); |
79 | | | 79 | |
80 | CFATTACH_DECL_NEW(i915drmkms, sizeof(struct i915drmkms_softc), | | 80 | CFATTACH_DECL_NEW(i915drmkms, sizeof(struct i915drmkms_softc), |
81 | i915drmkms_match, i915drmkms_attach, i915drmkms_detach, NULL); | | 81 | i915drmkms_match, i915drmkms_attach, i915drmkms_detach, NULL); |
82 | | | 82 | |
83 | /* XXX Kludge to get these from i915_drv.c. */ | | 83 | /* XXX Kludge to get these from i915_drv.c. */ |
84 | extern struct drm_driver *const i915_drm_driver; | | 84 | extern struct drm_driver *const i915_drm_driver; |
85 | extern const struct pci_device_id *const i915_device_ids; | | 85 | extern const struct pci_device_id *const i915_device_ids; |
86 | extern const size_t i915_n_device_ids; | | 86 | extern const size_t i915_n_device_ids; |
87 | | | 87 | |
88 | static const struct intel_device_info * | | 88 | static const struct pci_device_id * |
89 | i915drmkms_pci_lookup(const struct pci_attach_args *pa) | | 89 | i915drmkms_pci_lookup(const struct pci_attach_args *pa) |
90 | { | | 90 | { |
91 | size_t i; | | 91 | size_t i; |
92 | | | 92 | |
93 | /* Attach only at function 0 to work around Intel lossage. */ | | 93 | /* Attach only at function 0 to work around Intel lossage. */ |
94 | if (pa->pa_function != 0) | | 94 | if (pa->pa_function != 0) |
95 | return NULL; | | 95 | return NULL; |
96 | | | 96 | |
97 | /* We're interested only in Intel products. */ | | 97 | /* We're interested only in Intel products. */ |
98 | if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL) | | 98 | if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL) |
99 | return NULL; | | 99 | return NULL; |
100 | | | 100 | |
101 | /* We're interested only in Intel display devices. */ | | 101 | /* We're interested only in Intel display devices. */ |
102 | if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY) | | 102 | if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY) |
103 | return NULL; | | 103 | return NULL; |
104 | | | 104 | |
105 | for (i = 0; i < i915_n_device_ids; i++) | | 105 | for (i = 0; i < i915_n_device_ids; i++) |
106 | if (PCI_PRODUCT(pa->pa_id) == i915_device_ids[i].device) | | 106 | if (PCI_PRODUCT(pa->pa_id) == i915_device_ids[i].device) |
107 | break; | | 107 | break; |
108 | | | 108 | |
109 | /* Did we find it? */ | | 109 | /* Did we find it? */ |
110 | if (i == i915_n_device_ids) | | 110 | if (i == i915_n_device_ids) |
111 | return NULL; | | 111 | return NULL; |
112 | | | 112 | |
113 | const struct intel_device_info *const info = | | 113 | const struct pci_device_id *ent = &i915_device_ids[i]; |
114 | (const void *)(uintptr_t)i915_device_ids[i].driver_data; | | 114 | const struct intel_device_info *const info = (struct intel_device_info *) ent->driver_data; |
115 | | | 115 | |
116 | if (info->require_force_probe) { | | 116 | if (info->require_force_probe) { |
117 | printf("i915drmkms: preliminary hardware support disabled\n"); | | 117 | printf("i915drmkms: preliminary hardware support disabled\n"); |
118 | return NULL; | | 118 | return NULL; |
119 | } | | 119 | } |
120 | | | 120 | |
121 | return info; | | 121 | return ent; |
122 | } | | 122 | } |
123 | | | 123 | |
124 | static int | | 124 | static int |
125 | i915drmkms_match(device_t parent, cfdata_t match, void *aux) | | 125 | i915drmkms_match(device_t parent, cfdata_t match, void *aux) |
126 | { | | 126 | { |
127 | extern int i915drmkms_guarantee_initialized(void); | | 127 | extern int i915drmkms_guarantee_initialized(void); |
128 | const struct pci_attach_args *const pa = aux; | | 128 | const struct pci_attach_args *const pa = aux; |
129 | int error; | | 129 | int error; |
130 | | | 130 | |
131 | error = i915drmkms_guarantee_initialized(); | | 131 | error = i915drmkms_guarantee_initialized(); |
132 | if (error) { | | 132 | if (error) { |
133 | aprint_error("i915drmkms: failed to initialize: %d\n", error); | | 133 | aprint_error("i915drmkms: failed to initialize: %d\n", error); |
134 | return 0; | | 134 | return 0; |
| @@ -158,29 +158,28 @@ i915drmkms_attach(device_t parent, devic | | | @@ -158,29 +158,28 @@ i915drmkms_attach(device_t parent, devic |
158 | * images. | | 158 | * images. |
159 | */ | | 159 | */ |
160 | sc->sc_dev = self; | | 160 | sc->sc_dev = self; |
161 | sc->sc_pa = *pa; | | 161 | sc->sc_pa = *pa; |
162 | | | 162 | |
163 | config_mountroot(self, &i915drmkms_attach_real); | | 163 | config_mountroot(self, &i915drmkms_attach_real); |
164 | } | | 164 | } |
165 | | | 165 | |
166 | static void | | 166 | static void |
167 | i915drmkms_attach_real(device_t self) | | 167 | i915drmkms_attach_real(device_t self) |
168 | { | | 168 | { |
169 | struct i915drmkms_softc *const sc = device_private(self); | | 169 | struct i915drmkms_softc *const sc = device_private(self); |
170 | struct pci_attach_args *const pa = &sc->sc_pa; | | 170 | struct pci_attach_args *const pa = &sc->sc_pa; |
171 | const struct intel_device_info *const info = i915drmkms_pci_lookup(pa); | | 171 | const struct pci_device_id *ent = i915drmkms_pci_lookup(pa); |
172 | const unsigned long cookie = | | 172 | const struct intel_device_info *const info = (struct intel_device_info *) ent->driver_data; |
173 | (unsigned long)(uintptr_t)(const void *)info; | | | |
174 | int error; | | 173 | int error; |
175 | | | 174 | |
176 | KASSERT(info != NULL); | | 175 | KASSERT(info != NULL); |
177 | | | 176 | |
178 | sc->sc_task_state = I915DRMKMS_TASK_ATTACH; | | 177 | sc->sc_task_state = I915DRMKMS_TASK_ATTACH; |
179 | SIMPLEQ_INIT(&sc->sc_task_u.attach); | | 178 | SIMPLEQ_INIT(&sc->sc_task_u.attach); |
180 | | | 179 | |
181 | /* Initialize the Linux PCI device descriptor. */ | | 180 | /* Initialize the Linux PCI device descriptor. */ |
182 | linux_pci_dev_init(&sc->sc_pci_dev, self, device_parent(self), pa, 0); | | 181 | linux_pci_dev_init(&sc->sc_pci_dev, self, device_parent(self), pa, 0); |
183 | | | 182 | |
184 | sc->sc_drm_dev = drm_dev_alloc(i915_drm_driver, self); | | 183 | sc->sc_drm_dev = drm_dev_alloc(i915_drm_driver, self); |
185 | if (IS_ERR(sc->sc_drm_dev)) { | | 184 | if (IS_ERR(sc->sc_drm_dev)) { |
186 | aprint_error_dev(self, "unable to create drm device: %ld\n", | | 185 | aprint_error_dev(self, "unable to create drm device: %ld\n", |
| @@ -188,27 +187,27 @@ i915drmkms_attach_real(device_t self) | | | @@ -188,27 +187,27 @@ i915drmkms_attach_real(device_t self) |
188 | sc->sc_drm_dev = NULL; | | 187 | sc->sc_drm_dev = NULL; |
189 | return; | | 188 | return; |
190 | } | | 189 | } |
191 | | | 190 | |
192 | /* XXX errno Linux->NetBSD */ | | 191 | /* XXX errno Linux->NetBSD */ |
193 | error = -drm_pci_attach(sc->sc_drm_dev, pa, &sc->sc_pci_dev); | | 192 | error = -drm_pci_attach(sc->sc_drm_dev, pa, &sc->sc_pci_dev); |
194 | if (error) { | | 193 | if (error) { |
195 | aprint_error_dev(self, "unable to attach drm: %d\n", error); | | 194 | aprint_error_dev(self, "unable to attach drm: %d\n", error); |
196 | return; | | 195 | return; |
197 | } | | 196 | } |
198 | sc->sc_pci_attached = true; | | 197 | sc->sc_pci_attached = true; |
199 | | | 198 | |
200 | /* XXX errno Linux->NetBSD */ | | 199 | /* XXX errno Linux->NetBSD */ |
201 | error = -drm_dev_register(sc->sc_drm_dev, cookie); | | 200 | error = -i915_driver_probe(&sc->sc_pci_dev, ent); |
202 | if (error) { | | 201 | if (error) { |
203 | aprint_error_dev(self, "unable to register drm: %d\n", error); | | 202 | aprint_error_dev(self, "unable to register drm: %d\n", error); |
204 | return; | | 203 | return; |
205 | } | | 204 | } |
206 | sc->sc_dev_registered = true; | | 205 | sc->sc_dev_registered = true; |
207 | | | 206 | |
208 | while (!SIMPLEQ_EMPTY(&sc->sc_task_u.attach)) { | | 207 | while (!SIMPLEQ_EMPTY(&sc->sc_task_u.attach)) { |
209 | struct i915drmkms_task *const task = | | 208 | struct i915drmkms_task *const task = |
210 | SIMPLEQ_FIRST(&sc->sc_task_u.attach); | | 209 | SIMPLEQ_FIRST(&sc->sc_task_u.attach); |
211 | | | 210 | |
212 | SIMPLEQ_REMOVE_HEAD(&sc->sc_task_u.attach, ift_u.queue); | | 211 | SIMPLEQ_REMOVE_HEAD(&sc->sc_task_u.attach, ift_u.queue); |
213 | (*task->ift_fn)(task); | | 212 | (*task->ift_fn)(task); |
214 | } | | 213 | } |