xref: /openbsd/sys/arch/loongson/dev/sisfb.c (revision 63294167)
1 /*	$OpenBSD: sisfb.c,v 1.10 2022/07/15 17:57:26 kettenis Exp $	*/
2 
3 /*
4  * Copyright (c) 2010 Miodrag Vallat.
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /*
20  * Minimalistic driver for the SIS315 Pro frame buffer found on the
21  * Lemote Fuloong 2F systems.
22  * Does not support acceleration, mode change, secondary output, or
23  * anything fancy.
24  */
25 
26 #include <sys/param.h>
27 #include <sys/systm.h>
28 #include <sys/device.h>
29 
30 #include <machine/bus.h>
31 #include <machine/cpu.h>
32 
33 #include <uvm/uvm_extern.h>
34 
35 #include <dev/pci/pcireg.h>
36 #include <dev/pci/pcivar.h>
37 #include <dev/pci/pcidevs.h>
38 
39 #include <dev/ic/mc6845.h>
40 
41 #include <dev/wscons/wsconsio.h>
42 #include <dev/wscons/wsdisplayvar.h>
43 #include <dev/rasops/rasops.h>
44 
45 struct sisfb_softc;
46 
47 /* minimal frame buffer information, suitable for early console */
48 struct sisfb {
49 	struct sisfb_softc	*sc;
50 	struct rasops_info	 ri;
51 	uint8_t			 cmap[256 * 3];
52 
53 	bus_space_tag_t		 fbt;
54 	bus_space_handle_t	 fbh;
55 
56 	bus_space_tag_t		 mmiot;
57 	bus_space_handle_t	 mmioh;
58 
59 	bus_space_tag_t		 iot;
60 	bus_space_handle_t	 ioh;
61 
62 	struct wsscreen_descr	 wsd;
63 };
64 
65 struct sisfb_softc {
66 	struct device		 sc_dev;
67 	struct sisfb		*sc_fb;
68 	struct sisfb		 sc_fb_store;
69 
70 	struct wsscreen_list	 sc_wsl;
71 	struct wsscreen_descr	*sc_scrlist[1];
72 	int			 sc_nscr;
73 };
74 
75 int	sisfb_match(struct device *, void *, void *);
76 void	sisfb_attach(struct device *, struct device *, void *);
77 
78 const struct cfattach sisfb_ca = {
79 	sizeof(struct sisfb_softc), sisfb_match, sisfb_attach
80 };
81 
82 struct cfdriver sisfb_cd = {
83 	NULL, "sisfb", DV_DULL
84 };
85 
86 int	sisfb_alloc_screen(void *, const struct wsscreen_descr *, void **, int *,
87 	    int *, uint32_t *);
88 void	sisfb_free_screen(void *, void *);
89 int	sisfb_ioctl(void *, u_long, caddr_t, int, struct proc *);
90 int	sisfb_list_font(void *, struct wsdisplay_font *);
91 int	sisfb_load_font(void *, void *, struct wsdisplay_font *);
92 paddr_t	sisfb_mmap(void *, off_t, int);
93 int	sisfb_show_screen(void *, void *, int, void (*)(void *, int, int),
94 	    void *);
95 
96 struct wsdisplay_accessops sisfb_accessops = {
97 	.ioctl = sisfb_ioctl,
98 	.mmap = sisfb_mmap,
99 	.alloc_screen = sisfb_alloc_screen,
100 	.free_screen = sisfb_free_screen,
101 	.show_screen = sisfb_show_screen,
102 	.load_font = sisfb_load_font,
103 	.list_font = sisfb_list_font
104 };
105 
106 int	sisfb_getcmap(uint8_t *, struct wsdisplay_cmap *);
107 void	sisfb_loadcmap(struct sisfb *, int, int);
108 int	sisfb_putcmap(uint8_t *, struct wsdisplay_cmap *);
109 int	sisfb_setup(struct sisfb *);
110 
111 static struct sisfb sisfbcn;
112 
113 const struct pci_matchid sisfb_devices[] = {
114 	{ PCI_VENDOR_SIS, PCI_PRODUCT_SIS_315PRO_VGA }
115 };
116 
117 /*
118  * Control Register access
119  *
120  * These are 8 bit registers; the choice of larger width types is intentional.
121  */
122 
123 #define	SIS_VGA_PORT_OFFSET	0x380
124 
125 #define	SEQ_ADDR		(0x3c4 - SIS_VGA_PORT_OFFSET)
126 #define	SEQ_DATA		(0x3c5 - SIS_VGA_PORT_OFFSET)
127 #define	DAC_ADDR		(0x3c8 - SIS_VGA_PORT_OFFSET)
128 #define	DAC_DATA		(0x3c9 - SIS_VGA_PORT_OFFSET)
129 #undef	CRTC_ADDR
130 #define	CRTC_ADDR		(0x3d4 - SIS_VGA_PORT_OFFSET)
131 #define	CRTC_DATA		(0x3d5 - SIS_VGA_PORT_OFFSET)
132 
133 static inline uint sisfb_crtc_read(struct sisfb *, uint);
134 static inline uint sisfb_seq_read(struct sisfb *, uint);
135 static inline void sisfb_seq_write(struct sisfb *, uint, uint);
136 
137 static inline uint
sisfb_crtc_read(struct sisfb * fb,uint idx)138 sisfb_crtc_read(struct sisfb *fb, uint idx)
139 {
140 	uint val;
141 	bus_space_write_1(fb->iot, fb->ioh, CRTC_ADDR, idx);
142 	val = bus_space_read_1(fb->iot, fb->ioh, CRTC_DATA);
143 #ifdef SIS_DEBUG
144 	printf("CRTC %04x -> %02x\n", idx, val);
145 #endif
146 	return val;
147 }
148 
149 static inline uint
sisfb_seq_read(struct sisfb * fb,uint idx)150 sisfb_seq_read(struct sisfb *fb, uint idx)
151 {
152 	uint val;
153 	bus_space_write_1(fb->iot, fb->ioh, SEQ_ADDR, idx);
154 	val = bus_space_read_1(fb->iot, fb->ioh, SEQ_DATA);
155 #ifdef SIS_DEBUG
156 	printf("SEQ %04x -> %02x\n", idx, val);
157 #endif
158 	return val;
159 }
160 
161 static inline void
sisfb_seq_write(struct sisfb * fb,uint idx,uint val)162 sisfb_seq_write(struct sisfb *fb, uint idx, uint val)
163 {
164 #ifdef SIS_DEBUG
165 	printf("SEQ %04x <- %02x\n", idx, val);
166 #endif
167 	bus_space_write_1(fb->iot, fb->ioh, SEQ_ADDR, idx);
168 	bus_space_write_1(fb->iot, fb->ioh, SEQ_DATA, val);
169 }
170 
171 int
sisfb_match(struct device * parent,void * vcf,void * aux)172 sisfb_match(struct device *parent, void *vcf, void *aux)
173 {
174 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
175 
176 	return pci_matchbyid(pa, sisfb_devices, nitems(sisfb_devices));
177 }
178 
179 void
sisfb_attach(struct device * parent,struct device * self,void * aux)180 sisfb_attach(struct device *parent, struct device *self, void *aux)
181 {
182 	struct sisfb_softc *sc = (struct sisfb_softc *)self;
183 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
184 	struct wsemuldisplaydev_attach_args waa;
185 	bus_space_tag_t fbt, mmiot, iot;
186 	bus_space_handle_t fbh, mmioh, ioh;
187 	bus_size_t fbsize, mmiosize;
188 	struct sisfb *fb;
189 	int console;
190 
191 	if (pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_MEM,
192 	    BUS_SPACE_MAP_LINEAR, &fbt, &fbh, NULL, &fbsize, 0) != 0) {
193 		printf(": can't map frame buffer\n");
194 		return;
195 	}
196 
197 	if (pci_mapreg_map(pa, PCI_MAPREG_START + 4, PCI_MAPREG_TYPE_MEM,
198 	    0, &mmiot, &mmioh, NULL, &mmiosize, 0) != 0) {
199 		printf(": can't map mmio area\n");
200 		goto fail1;
201 	}
202 
203 	if (pci_mapreg_map(pa, PCI_MAPREG_START + 8, PCI_MAPREG_TYPE_IO,
204 	    0, &iot, &ioh, NULL, NULL, 0) != 0) {
205 		printf(": can't map registers\n");
206 		goto fail2;
207 	}
208 
209 	console = sisfbcn.ri.ri_hw != NULL;
210 
211 	if (console)
212 		fb = &sisfbcn;
213 	else
214 		fb = &sc->sc_fb_store;
215 
216 	fb->sc = sc;
217 	fb->fbt = fbt;
218 	fb->fbh = fbh;
219 	fb->mmiot = mmiot;
220 	fb->mmioh = mmioh;
221 	fb->iot = iot;
222 	fb->ioh = ioh;
223 	sc->sc_fb = fb;
224 
225 	if (!console) {
226 		if (sisfb_setup(fb) != 0) {
227 			printf(": can't setup frame buffer\n");
228 			return;
229 		}
230 	}
231 
232 	printf(": %dx%d, %dbpp\n",
233 	    fb->ri.ri_width, fb->ri.ri_height, fb->ri.ri_depth);
234 
235 	sc->sc_scrlist[0] = &fb->wsd;
236 	sc->sc_wsl.nscreens = 1;
237 	sc->sc_wsl.screens = (const struct wsscreen_descr **)sc->sc_scrlist;
238 
239 	waa.console = console;
240 	waa.scrdata = &sc->sc_wsl;
241 	waa.accessops = &sisfb_accessops;
242 	waa.accesscookie = sc;
243 	waa.defaultscreens = 0;
244 
245 	config_found((struct device *)sc, &waa, wsemuldisplaydevprint);
246 	return;
247 
248 fail2:
249 	bus_space_unmap(mmiot, mmioh, mmiosize);
250 fail1:
251 	bus_space_unmap(fbt, fbh, fbsize);
252 }
253 
254 /*
255  * wsdisplay accesops
256  */
257 
258 int
sisfb_alloc_screen(void * v,const struct wsscreen_descr * type,void ** cookiep,int * curxp,int * curyp,uint32_t * attrp)259 sisfb_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
260     int *curxp, int *curyp, uint32_t *attrp)
261 {
262 	struct sisfb_softc *sc = (struct sisfb_softc *)v;
263 	struct rasops_info *ri = &sc->sc_fb->ri;
264 
265 	if (sc->sc_nscr > 0)
266 		return ENOMEM;
267 
268 	*cookiep = ri;
269 	*curxp = *curyp = 0;
270 	ri->ri_ops.pack_attr(ri, 0, 0, 0, attrp);
271 	sc->sc_nscr++;
272 
273 	return 0;
274 }
275 
276 void
sisfb_free_screen(void * v,void * cookie)277 sisfb_free_screen(void *v, void *cookie)
278 {
279 	struct sisfb_softc *sc = (struct sisfb_softc *)v;
280 
281 	sc->sc_nscr--;
282 }
283 
284 int
sisfb_ioctl(void * v,u_long cmd,caddr_t data,int flags,struct proc * p)285 sisfb_ioctl(void *v, u_long cmd, caddr_t data, int flags, struct proc *p)
286 {
287 	struct sisfb_softc *sc = (struct sisfb_softc *)v;
288 	struct sisfb *fb = sc->sc_fb;
289 	struct rasops_info *ri = &fb->ri;
290 	struct wsdisplay_cmap *cm;
291 	struct wsdisplay_fbinfo *wdf;
292 	int rc;
293 
294 	switch (cmd) {
295 	case WSDISPLAYIO_GTYPE:
296 		*(uint *)data = WSDISPLAY_TYPE_SISFB;
297 		break;
298 	case WSDISPLAYIO_GINFO:
299 		wdf = (struct wsdisplay_fbinfo *)data;
300 		wdf->width = ri->ri_width;
301 		wdf->height = ri->ri_height;
302 		wdf->depth = ri->ri_depth;
303 		wdf->stride = ri->ri_stride;
304 		wdf->offset = 0;
305 		wdf->cmsize = 256;
306 		break;
307 	case WSDISPLAYIO_LINEBYTES:
308 		*(uint *)data = ri->ri_stride;
309 		break;
310 	case WSDISPLAYIO_GETCMAP:
311 		cm = (struct wsdisplay_cmap *)data;
312 		rc = sisfb_getcmap(fb->cmap, cm);
313 		if (rc != 0)
314 			return rc;
315 		break;
316 	case WSDISPLAYIO_PUTCMAP:
317 		cm = (struct wsdisplay_cmap *)data;
318 		rc = sisfb_putcmap(fb->cmap, cm);
319 		if (rc != 0)
320 			return rc;
321 		if (ri->ri_depth == 8)
322 			sisfb_loadcmap(fb, cm->index, cm->count);
323 		break;
324 	default:
325 		return -1;
326 	}
327 
328 	return 0;
329 }
330 
331 int
sisfb_show_screen(void * v,void * cookie,int waitok,void (* cb)(void *,int,int),void * cbarg)332 sisfb_show_screen(void *v, void *cookie, int waitok,
333     void (*cb)(void *, int, int), void *cbarg)
334 {
335 	return 0;
336 }
337 
338 paddr_t
sisfb_mmap(void * v,off_t offset,int prot)339 sisfb_mmap(void *v, off_t offset, int prot)
340 {
341 	struct sisfb_softc *sc = (struct sisfb_softc *)v;
342 	struct rasops_info *ri = &sc->sc_fb->ri;
343 
344 	if ((offset & PAGE_MASK) != 0)
345 		return -1;
346 
347 	if (offset < 0 || offset >= ri->ri_stride * ri->ri_height)
348 		return -1;
349 
350 	/*
351 	 * Don't allow mmap if the frame buffer area is not page aligned.
352 	 * XXX we should reprogram it to a page aligned boundary at attach
353 	 * XXX time if this isn't the case.
354 	 */
355 	if (((paddr_t)ri->ri_bits & PAGE_MASK) != 0)
356 		return -1;
357 
358 	return XKPHYS_TO_PHYS((paddr_t)ri->ri_bits) + offset;
359 }
360 
361 int
sisfb_load_font(void * v,void * emulcookie,struct wsdisplay_font * font)362 sisfb_load_font(void *v, void *emulcookie, struct wsdisplay_font *font)
363 {
364 	struct sisfb_softc *sc = (struct sisfb_softc *)v;
365 	struct rasops_info *ri = &sc->sc_fb->ri;
366 
367 	return rasops_load_font(ri, emulcookie, font);
368 }
369 
370 int
sisfb_list_font(void * v,struct wsdisplay_font * font)371 sisfb_list_font(void *v, struct wsdisplay_font *font)
372 {
373 	struct sisfb_softc *sc = (struct sisfb_softc *)v;
374 	struct rasops_info *ri = &sc->sc_fb->ri;
375 
376 	return rasops_list_font(ri, font);
377 }
378 
379 /*
380  * Frame buffer initialization.
381  */
382 
383 int
sisfb_setup(struct sisfb * fb)384 sisfb_setup(struct sisfb *fb)
385 {
386 	struct rasops_info *ri;
387 	uint width, height, bpp;
388 	bus_size_t fbaddr;
389 	uint tmp;
390 
391 	/*
392 	 * Unlock access to extended registers.
393 	 */
394 
395 	sisfb_seq_write(fb, 0x05, 0x86);
396 
397 	/*
398 	 * Try and figure out display settings.
399 	 */
400 
401 	height = sisfb_crtc_read(fb, CRTC_VDE);
402 	tmp = sisfb_crtc_read(fb, CRTC_OVERFLL);
403 	if (ISSET(tmp, 1 << 1))
404 		height |= 1 << 8;
405 	if (ISSET(tmp, 1 << 6))
406 		height |= 1 << 9;
407 	tmp = sisfb_seq_read(fb, 0x0a);
408 	if (ISSET(tmp, 1 << 1))
409 		height |= 1 << 10;
410 	height++;
411 
412 	width = sisfb_crtc_read(fb, CRTC_HDISPLE);
413 	tmp = sisfb_seq_read(fb, 0x0b);
414 	if (ISSET(tmp, 1 << 2))
415 		width |= 1 << 8;
416 	if (ISSET(tmp, 1 << 3))
417 		width |= 1 << 9;
418 	width++;
419 	width <<= 3;
420 
421 	fbaddr = sisfb_crtc_read(fb, CRTC_STARTADRL) |
422 	    (sisfb_crtc_read(fb, CRTC_STARTADRH) << 8) |
423 	    (sisfb_seq_read(fb, 0x0d) << 16) |
424 	    ((sisfb_seq_read(fb, 0x37) & 0x03) << 24);
425 	fbaddr <<= 2;
426 #ifdef SIS_DEBUG
427 	printf("FBADDR %08x\n", fbaddr);
428 #endif
429 
430 	tmp = sisfb_seq_read(fb, 0x06);
431 	switch (tmp & 0x1c) {
432 	case 0x00:
433 		bpp = 8;
434 		break;
435 	case 0x04:
436 		bpp = 15;
437 		break;
438 	case 0x08:
439 		bpp = 16;
440 		break;
441 	case 0x10:
442 		bpp = 32;
443 		break;
444 	default:
445 		return EINVAL;
446 	}
447 
448 	ri = &fb->ri;
449 	ri->ri_width = width;
450 	ri->ri_height = height;
451 	ri->ri_depth = bpp;
452 	ri->ri_stride = (ri->ri_width * ri->ri_depth) / 8;
453 	ri->ri_flg = RI_CENTER | RI_CLEAR | RI_FULLCLEAR;
454 	ri->ri_bits = (void *)(bus_space_vaddr(fb->fbt, fb->fbh) + fbaddr);
455 	ri->ri_hw = fb;
456 
457 #ifdef __MIPSEL__
458 	/* swap B and R */
459 	switch (bpp) {
460 	case 15:
461 		ri->ri_rnum = 5;
462 		ri->ri_rpos = 10;
463 		ri->ri_gnum = 5;
464 		ri->ri_gpos = 5;
465 		ri->ri_bnum = 5;
466 		ri->ri_bpos = 0;
467 		break;
468 	case 16:
469 		ri->ri_rnum = 5;
470 		ri->ri_rpos = 11;
471 		ri->ri_gnum = 6;
472 		ri->ri_gpos = 5;
473 		ri->ri_bnum = 5;
474 		ri->ri_bpos = 0;
475 		break;
476 	}
477 #endif
478 
479 	bcopy(rasops_cmap, fb->cmap, sizeof(fb->cmap));
480 	if (bpp == 8)
481 		sisfb_loadcmap(fb, 0, 256);
482 
483 	rasops_init(ri, 160, 160);
484 
485 	strlcpy(fb->wsd.name, "std", sizeof(fb->wsd.name));
486 	fb->wsd.ncols = ri->ri_cols;
487 	fb->wsd.nrows = ri->ri_rows;
488 	fb->wsd.textops = &ri->ri_ops;
489 	fb->wsd.fontwidth = ri->ri_font->fontwidth;
490 	fb->wsd.fontheight = ri->ri_font->fontheight;
491 	fb->wsd.capabilities = ri->ri_caps;
492 
493 	return 0;
494 }
495 
496 /*
497  * Colormap handling routines.
498  */
499 
500 void
sisfb_loadcmap(struct sisfb * fb,int baseidx,int count)501 sisfb_loadcmap(struct sisfb *fb, int baseidx, int count)
502 {
503 	uint8_t *cmap = fb->cmap + baseidx * 3;
504 
505 	bus_space_write_1(fb->iot, fb->ioh, DAC_ADDR, baseidx);
506 	while (count-- != 0) {
507 		bus_space_write_1(fb->iot, fb->ioh, DAC_DATA, *cmap++ >> 2);
508 		bus_space_write_1(fb->iot, fb->ioh, DAC_DATA, *cmap++ >> 2);
509 		bus_space_write_1(fb->iot, fb->ioh, DAC_DATA, *cmap++ >> 2);
510 	}
511 }
512 
513 int
sisfb_getcmap(uint8_t * cmap,struct wsdisplay_cmap * cm)514 sisfb_getcmap(uint8_t *cmap, struct wsdisplay_cmap *cm)
515 {
516 	uint index = cm->index, count = cm->count, i;
517 	uint8_t ramp[256], *dst, *src;
518 	int rc;
519 
520 	if (index >= 256 || count > 256 - index)
521 		return EINVAL;
522 
523 	index *= 3;
524 
525 	src = cmap + index;
526 	dst = ramp;
527 	for (i = 0; i < count; i++)
528 		*dst++ = *src, src += 3;
529 	rc = copyout(ramp, cm->red, count);
530 	if (rc != 0)
531 		return rc;
532 
533 	src = cmap + index + 1;
534 	dst = ramp;
535 	for (i = 0; i < count; i++)
536 		*dst++ = *src, src += 3;
537 	rc = copyout(ramp, cm->green, count);
538 	if (rc != 0)
539 		return rc;
540 
541 	src = cmap + index + 2;
542 	dst = ramp;
543 	for (i = 0; i < count; i++)
544 		*dst++ = *src, src += 3;
545 	rc = copyout(ramp, cm->blue, count);
546 	if (rc != 0)
547 		return rc;
548 
549 	return 0;
550 }
551 
552 int
sisfb_putcmap(uint8_t * cmap,struct wsdisplay_cmap * cm)553 sisfb_putcmap(uint8_t *cmap, struct wsdisplay_cmap *cm)
554 {
555 	uint index = cm->index, count = cm->count, i;
556 	uint8_t ramp[256], *dst, *src;
557 	int rc;
558 
559 	if (index >= 256 || count > 256 - index)
560 		return EINVAL;
561 
562 	index *= 3;
563 
564 	rc = copyin(cm->red, ramp, count);
565 	if (rc != 0)
566 		return rc;
567 	dst = cmap + index;
568 	src = ramp;
569 	for (i = 0; i < count; i++)
570 		*dst = *src++, dst += 3;
571 
572 	rc = copyin(cm->green, ramp, count);
573 	if (rc != 0)
574 		return rc;
575 	dst = cmap + index + 1;
576 	src = ramp;
577 	for (i = 0; i < count; i++)
578 		*dst = *src++, dst += 3;
579 
580 	rc = copyin(cm->blue, ramp, count);
581 	if (rc != 0)
582 		return rc;
583 	dst = cmap + index + 2;
584 	src = ramp;
585 	for (i = 0; i < count; i++)
586 		*dst = *src++, dst += 3;
587 
588 	return 0;
589 }
590 
591 /*
592  * Early console code
593  */
594 
595 int sisfb_cnattach(bus_space_tag_t, bus_space_tag_t, pcitag_t, pcireg_t);
596 
597 int
sisfb_cnattach(bus_space_tag_t memt,bus_space_tag_t iot,pcitag_t tag,pcireg_t id)598 sisfb_cnattach(bus_space_tag_t memt, bus_space_tag_t iot, pcitag_t tag,
599     pcireg_t id)
600 {
601 	uint32_t defattr;
602 	struct rasops_info *ri;
603 	pcireg_t bar;
604 	int rc;
605 
606 	/* filter out unrecognized devices */
607 	switch (id) {
608 	default:
609 		return ENODEV;
610 	case PCI_ID_CODE(PCI_VENDOR_SIS, PCI_PRODUCT_SIS_315PRO_VGA):
611 		break;
612 	}
613 
614 	bar = pci_conf_read_early(tag, PCI_MAPREG_START);
615 	if (PCI_MAPREG_TYPE(bar) != PCI_MAPREG_TYPE_MEM)
616 		return EINVAL;
617 	sisfbcn.fbt = memt;
618 	rc = bus_space_map(memt, PCI_MAPREG_MEM_ADDR(bar), 1 /* XXX */,
619 	    BUS_SPACE_MAP_LINEAR, &sisfbcn.fbh);
620 	if (rc != 0)
621 		return rc;
622 
623 	bar = pci_conf_read_early(tag, PCI_MAPREG_START + 4);
624 	if (PCI_MAPREG_TYPE(bar) != PCI_MAPREG_TYPE_MEM)
625 		return EINVAL;
626 	sisfbcn.mmiot = memt;
627 	rc = bus_space_map(memt, PCI_MAPREG_MEM_ADDR(bar), 1 /* XXX */,
628 	    BUS_SPACE_MAP_LINEAR, &sisfbcn.mmioh);
629 	if (rc != 0)
630 		return rc;
631 
632 	bar = pci_conf_read_early(tag, PCI_MAPREG_START + 8);
633 	if (PCI_MAPREG_TYPE(bar) != PCI_MAPREG_TYPE_IO)
634 		return EINVAL;
635 	sisfbcn.iot = iot;
636 	rc = bus_space_map(iot, PCI_MAPREG_MEM_ADDR(bar), 1 /* XXX */,
637 	    0, &sisfbcn.ioh);
638 	if (rc != 0)
639 		return rc;
640 
641 	rc = sisfb_setup(&sisfbcn);
642 	if (rc != 0)
643 		return rc;
644 
645 	ri = &sisfbcn.ri;
646 	ri->ri_ops.pack_attr(ri, 0, 0, 0, &defattr);
647 	wsdisplay_cnattach(&sisfbcn.wsd, ri, 0, 0, defattr);
648 
649 	return 0;
650 }
651