xref: /openbsd-src/sys/arch/loongson/dev/sisfb.c (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: sisfb.c,v 1.4 2013/10/21 10:36:14 miod 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 accelaration, 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 *, long *);
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 void sisfb_crtc_write(struct sisfb *, uint, uint);
135 static inline uint sisfb_seq_read(struct sisfb *, uint);
136 static inline void sisfb_seq_write(struct sisfb *, uint, uint);
137 
138 static inline uint
139 sisfb_crtc_read(struct sisfb *fb, uint idx)
140 {
141 	uint val;
142 	bus_space_write_1(fb->iot, fb->ioh, CRTC_ADDR, idx);
143 	val = bus_space_read_1(fb->iot, fb->ioh, CRTC_DATA);
144 #ifdef SIS_DEBUG
145 	printf("CRTC %04x -> %02x\n", idx, val);
146 #endif
147 	return val;
148 }
149 
150 static inline void
151 sisfb_crtc_write(struct sisfb *fb, uint idx, uint val)
152 {
153 #ifdef SIS_DEBUG
154 	printf("CRTC %04x <- %02x\n", idx, val);
155 #endif
156 	bus_space_write_1(fb->iot, fb->ioh, CRTC_ADDR, idx);
157 	bus_space_write_1(fb->iot, fb->ioh, CRTC_DATA, val);
158 }
159 
160 static inline uint
161 sisfb_seq_read(struct sisfb *fb, uint idx)
162 {
163 	uint val;
164 	bus_space_write_1(fb->iot, fb->ioh, SEQ_ADDR, idx);
165 	val = bus_space_read_1(fb->iot, fb->ioh, SEQ_DATA);
166 #ifdef SIS_DEBUG
167 	printf("SEQ %04x -> %02x\n", idx, val);
168 #endif
169 	return val;
170 }
171 
172 static inline void
173 sisfb_seq_write(struct sisfb *fb, uint idx, uint val)
174 {
175 #ifdef SIS_DEBUG
176 	printf("SEQ %04x <- %02x\n", idx, val);
177 #endif
178 	bus_space_write_1(fb->iot, fb->ioh, SEQ_ADDR, idx);
179 	bus_space_write_1(fb->iot, fb->ioh, SEQ_DATA, val);
180 }
181 
182 int
183 sisfb_match(struct device *parent, void *vcf, void *aux)
184 {
185 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
186 
187 	return pci_matchbyid(pa, sisfb_devices, nitems(sisfb_devices));
188 }
189 
190 void
191 sisfb_attach(struct device *parent, struct device *self, void *aux)
192 {
193 	struct sisfb_softc *sc = (struct sisfb_softc *)self;
194 	struct pci_attach_args *pa = (struct pci_attach_args *)aux;
195 	struct wsemuldisplaydev_attach_args waa;
196 	bus_space_tag_t fbt, mmiot, iot;
197 	bus_space_handle_t fbh, mmioh, ioh;
198 	bus_size_t fbsize, mmiosize;
199 	struct sisfb *fb;
200 	int console;
201 
202 	if (pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_MEM,
203 	    BUS_SPACE_MAP_LINEAR, &fbt, &fbh, NULL, &fbsize, 0) != 0) {
204 		printf(": can't map frame buffer\n");
205 		return;
206 	}
207 
208 	if (pci_mapreg_map(pa, PCI_MAPREG_START + 4, PCI_MAPREG_TYPE_MEM,
209 	    0, &mmiot, &mmioh, NULL, &mmiosize, 0) != 0) {
210 		printf(": can't map mmio area\n");
211 		goto fail1;
212 	}
213 
214 	if (pci_mapreg_map(pa, PCI_MAPREG_START + 8, PCI_MAPREG_TYPE_IO,
215 	    0, &iot, &ioh, NULL, NULL, 0) != 0) {
216 		printf(": can't map registers\n");
217 		goto fail2;
218 	}
219 
220 	console = sisfbcn.ri.ri_hw != NULL;
221 
222 	if (console)
223 		fb = &sisfbcn;
224 	else
225 		fb = &sc->sc_fb_store;
226 
227 	fb->sc = sc;
228 	fb->fbt = fbt;
229 	fb->fbh = fbh;
230 	fb->mmiot = mmiot;
231 	fb->mmioh = mmioh;
232 	fb->iot = iot;
233 	fb->ioh = ioh;
234 	sc->sc_fb = fb;
235 
236 	if (!console) {
237 		if (sisfb_setup(fb) != 0) {
238 			printf(": can't setup frame buffer\n");
239 			return;
240 		}
241 	}
242 
243 	printf(": %dx%dx%d frame buffer\n",
244 	    fb->ri.ri_width, fb->ri.ri_height, fb->ri.ri_depth);
245 
246 	sc->sc_scrlist[0] = &fb->wsd;
247 	sc->sc_wsl.nscreens = 1;
248 	sc->sc_wsl.screens = (const struct wsscreen_descr **)sc->sc_scrlist;
249 
250 	waa.console = console;
251 	waa.scrdata = &sc->sc_wsl;
252 	waa.accessops = &sisfb_accessops;
253 	waa.accesscookie = sc;
254 	waa.defaultscreens = 0;
255 
256 	config_found((struct device *)sc, &waa, wsemuldisplaydevprint);
257 	return;
258 
259 fail2:
260 	bus_space_unmap(mmiot, mmioh, mmiosize);
261 fail1:
262 	bus_space_unmap(fbt, fbh, fbsize);
263 }
264 
265 /*
266  * wsdisplay accesops
267  */
268 
269 int
270 sisfb_alloc_screen(void *v, const struct wsscreen_descr *type, void **cookiep,
271     int *curxp, int *curyp, long *attrp)
272 {
273 	struct sisfb_softc *sc = (struct sisfb_softc *)v;
274 	struct rasops_info *ri = &sc->sc_fb->ri;
275 
276 	if (sc->sc_nscr > 0)
277 		return ENOMEM;
278 
279 	*cookiep = ri;
280 	*curxp = *curyp = 0;
281 	ri->ri_ops.alloc_attr(ri, 0, 0, 0, attrp);
282 	sc->sc_nscr++;
283 
284 	return 0;
285 }
286 
287 void
288 sisfb_free_screen(void *v, void *cookie)
289 {
290 	struct sisfb_softc *sc = (struct sisfb_softc *)v;
291 
292 	sc->sc_nscr--;
293 }
294 
295 int
296 sisfb_ioctl(void *v, u_long cmd, caddr_t data, int flags, struct proc *p)
297 {
298 	struct sisfb_softc *sc = (struct sisfb_softc *)v;
299 	struct sisfb *fb = sc->sc_fb;
300 	struct rasops_info *ri = &fb->ri;
301 	struct wsdisplay_cmap *cm;
302 	struct wsdisplay_fbinfo *wdf;
303 	int rc;
304 
305 	switch (cmd) {
306 	case WSDISPLAYIO_GTYPE:
307 		*(uint *)data = WSDISPLAY_TYPE_SISFB;
308 		break;
309 	case WSDISPLAYIO_GINFO:
310 		wdf = (struct wsdisplay_fbinfo *)data;
311 		wdf->width = ri->ri_width;
312 		wdf->height = ri->ri_height;
313 		wdf->depth = ri->ri_depth;
314 		wdf->cmsize = 256;
315 		break;
316 	case WSDISPLAYIO_LINEBYTES:
317 		*(uint *)data = ri->ri_stride;
318 		break;
319 	case WSDISPLAYIO_GETCMAP:
320 		cm = (struct wsdisplay_cmap *)data;
321 		rc = sisfb_getcmap(fb->cmap, cm);
322 		if (rc != 0)
323 			return rc;
324 		break;
325 	case WSDISPLAYIO_PUTCMAP:
326 		cm = (struct wsdisplay_cmap *)data;
327 		rc = sisfb_putcmap(fb->cmap, cm);
328 		if (rc != 0)
329 			return rc;
330 		if (ri->ri_depth == 8)
331 			sisfb_loadcmap(fb, cm->index, cm->count);
332 		break;
333 	default:
334 		return -1;
335 	}
336 
337 	return 0;
338 }
339 
340 int
341 sisfb_show_screen(void *v, void *cookie, int waitok,
342     void (*cb)(void *, int, int), void *cbarg)
343 {
344 	return 0;
345 }
346 
347 paddr_t
348 sisfb_mmap(void *v, off_t offset, int prot)
349 {
350 	struct sisfb_softc *sc = (struct sisfb_softc *)v;
351 	struct rasops_info *ri = &sc->sc_fb->ri;
352 
353 	if ((offset & PAGE_MASK) != 0)
354 		return -1;
355 
356 	if (offset < 0 || offset >= ri->ri_stride * ri->ri_height)
357 		return -1;
358 
359 	/*
360 	 * Don't allow mmap if the frame buffer area is not page aligned.
361 	 * XXX we should reprogram it to a page aligned boundary at attach
362 	 * XXX time if this isn't the case.
363 	 */
364 	if (((paddr_t)ri->ri_bits & PAGE_MASK) != 0)
365 		return -1;
366 
367 	return XKPHYS_TO_PHYS((paddr_t)ri->ri_bits) + offset;
368 }
369 
370 int
371 sisfb_load_font(void *v, void *emulcookie, 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_load_font(ri, emulcookie, font);
377 }
378 
379 int
380 sisfb_list_font(void *v, struct wsdisplay_font *font)
381 {
382 	struct sisfb_softc *sc = (struct sisfb_softc *)v;
383 	struct rasops_info *ri = &sc->sc_fb->ri;
384 
385 	return rasops_list_font(ri, font);
386 }
387 
388 /*
389  * Frame buffer initialization.
390  */
391 
392 int
393 sisfb_setup(struct sisfb *fb)
394 {
395 	struct rasops_info *ri;
396 	uint width, height, bpp;
397 	bus_size_t fbaddr;
398 	uint tmp;
399 
400 	/*
401 	 * Unlock access to extended registers.
402 	 */
403 
404 	sisfb_seq_write(fb, 0x05, 0x86);
405 
406 	/*
407 	 * Try and figure out display settings.
408 	 */
409 
410 	height = sisfb_crtc_read(fb, CRTC_VDE);
411 	tmp = sisfb_crtc_read(fb, CRTC_OVERFLL);
412 	if (ISSET(tmp, 1 << 1))
413 		height |= 1 << 8;
414 	if (ISSET(tmp, 1 << 6))
415 		height |= 1 << 9;
416 	tmp = sisfb_seq_read(fb, 0x0a);
417 	if (ISSET(tmp, 1 << 1))
418 		height |= 1 << 10;
419 	height++;
420 
421 	width = sisfb_crtc_read(fb, CRTC_HDISPLE);
422 	tmp = sisfb_seq_read(fb, 0x0b);
423 	if (ISSET(tmp, 1 << 2))
424 		width |= 1 << 8;
425 	if (ISSET(tmp, 1 << 3))
426 		width |= 1 << 9;
427 	width++;
428 	width <<= 3;
429 
430 	fbaddr = sisfb_crtc_read(fb, CRTC_STARTADRL) |
431 	    (sisfb_crtc_read(fb, CRTC_STARTADRH) << 8) |
432 	    (sisfb_seq_read(fb, 0x0d) << 16) |
433 	    ((sisfb_seq_read(fb, 0x37) & 0x03) << 24);
434 	fbaddr <<= 2;
435 #ifdef SIS_DEBUG
436 	printf("FBADDR %08x\n", fbaddr);
437 #endif
438 
439 	tmp = sisfb_seq_read(fb, 0x06);
440 	switch (tmp & 0x1c) {
441 	case 0x00:
442 		bpp = 8;
443 		break;
444 	case 0x04:
445 		bpp = 15;
446 		break;
447 	case 0x08:
448 		bpp = 16;
449 		break;
450 	case 0x10:
451 		bpp = 32;
452 		break;
453 	default:
454 		return EINVAL;
455 	}
456 
457 	ri = &fb->ri;
458 	ri->ri_width = width;
459 	ri->ri_height = height;
460 	ri->ri_depth = bpp;
461 	ri->ri_stride = (ri->ri_width * ri->ri_depth) / 8;
462 	ri->ri_flg = RI_CENTER | RI_CLEAR | RI_FULLCLEAR;
463 	ri->ri_bits = (void *)(bus_space_vaddr(fb->fbt, fb->fbh) + fbaddr);
464 	ri->ri_hw = fb;
465 
466 #ifdef __MIPSEL__
467 	/* swap B and R */
468 	switch (bpp) {
469 	case 15:
470 		ri->ri_rnum = 5;
471 		ri->ri_rpos = 10;
472 		ri->ri_gnum = 5;
473 		ri->ri_gpos = 5;
474 		ri->ri_bnum = 5;
475 		ri->ri_bpos = 0;
476 		break;
477 	case 16:
478 		ri->ri_rnum = 5;
479 		ri->ri_rpos = 11;
480 		ri->ri_gnum = 6;
481 		ri->ri_gpos = 5;
482 		ri->ri_bnum = 5;
483 		ri->ri_bpos = 0;
484 		break;
485 	}
486 #endif
487 
488 	bcopy(rasops_cmap, fb->cmap, sizeof(fb->cmap));
489 	if (bpp == 8)
490 		sisfb_loadcmap(fb, 0, 256);
491 
492 	rasops_init(ri, 160, 160);
493 
494 	strlcpy(fb->wsd.name, "std", sizeof(fb->wsd.name));
495 	fb->wsd.ncols = ri->ri_cols;
496 	fb->wsd.nrows = ri->ri_rows;
497 	fb->wsd.textops = &ri->ri_ops;
498 	fb->wsd.fontwidth = ri->ri_font->fontwidth;
499 	fb->wsd.fontheight = ri->ri_font->fontheight;
500 	fb->wsd.capabilities = ri->ri_caps;
501 
502 	return 0;
503 }
504 
505 /*
506  * Colormap handling routines.
507  */
508 
509 void
510 sisfb_loadcmap(struct sisfb *fb, int baseidx, int count)
511 {
512 	uint8_t *cmap = fb->cmap + baseidx * 3;
513 
514 	bus_space_write_1(fb->iot, fb->ioh, DAC_ADDR, baseidx);
515 	while (count-- != 0) {
516 		bus_space_write_1(fb->iot, fb->ioh, DAC_DATA, *cmap++ >> 2);
517 		bus_space_write_1(fb->iot, fb->ioh, DAC_DATA, *cmap++ >> 2);
518 		bus_space_write_1(fb->iot, fb->ioh, DAC_DATA, *cmap++ >> 2);
519 	}
520 }
521 
522 int
523 sisfb_getcmap(uint8_t *cmap, struct wsdisplay_cmap *cm)
524 {
525 	uint index = cm->index, count = cm->count, i;
526 	uint8_t ramp[256], *dst, *src;
527 	int rc;
528 
529 	if (index >= 256 || count > 256 - index)
530 		return EINVAL;
531 
532 	index *= 3;
533 
534 	src = cmap + index;
535 	dst = ramp;
536 	for (i = 0; i < count; i++)
537 		*dst++ = *src, src += 3;
538 	rc = copyout(ramp, cm->red, count);
539 	if (rc != 0)
540 		return rc;
541 
542 	src = cmap + index + 1;
543 	dst = ramp;
544 	for (i = 0; i < count; i++)
545 		*dst++ = *src, src += 3;
546 	rc = copyout(ramp, cm->green, count);
547 	if (rc != 0)
548 		return rc;
549 
550 	src = cmap + index + 2;
551 	dst = ramp;
552 	for (i = 0; i < count; i++)
553 		*dst++ = *src, src += 3;
554 	rc = copyout(ramp, cm->blue, count);
555 	if (rc != 0)
556 		return rc;
557 
558 	return 0;
559 }
560 
561 int
562 sisfb_putcmap(uint8_t *cmap, struct wsdisplay_cmap *cm)
563 {
564 	uint index = cm->index, count = cm->count, i;
565 	uint8_t ramp[256], *dst, *src;
566 	int rc;
567 
568 	if (index >= 256 || count > 256 - index)
569 		return EINVAL;
570 
571 	index *= 3;
572 
573 	rc = copyin(cm->red, ramp, count);
574 	if (rc != 0)
575 		return rc;
576 	dst = cmap + index;
577 	src = ramp;
578 	for (i = 0; i < count; i++)
579 		*dst = *src++, dst += 3;
580 
581 	rc = copyin(cm->green, ramp, count);
582 	if (rc != 0)
583 		return rc;
584 	dst = cmap + index + 1;
585 	src = ramp;
586 	for (i = 0; i < count; i++)
587 		*dst = *src++, dst += 3;
588 
589 	rc = copyin(cm->blue, ramp, count);
590 	if (rc != 0)
591 		return rc;
592 	dst = cmap + index + 2;
593 	src = ramp;
594 	for (i = 0; i < count; i++)
595 		*dst = *src++, dst += 3;
596 
597 	return 0;
598 }
599 
600 /*
601  * Early console code
602  */
603 
604 int sisfb_cnattach(bus_space_tag_t, bus_space_tag_t, pcitag_t, pcireg_t);
605 
606 int
607 sisfb_cnattach(bus_space_tag_t memt, bus_space_tag_t iot, pcitag_t tag,
608     pcireg_t id)
609 {
610 	long defattr;
611 	struct rasops_info *ri;
612 	pcireg_t bar;
613 	int rc;
614 
615 	/* filter out unrecognized devices */
616 	switch (id) {
617 	default:
618 		return ENODEV;
619 	case PCI_ID_CODE(PCI_VENDOR_SIS, PCI_PRODUCT_SIS_315PRO_VGA):
620 		break;
621 	}
622 
623 	bar = pci_conf_read_early(tag, PCI_MAPREG_START);
624 	if (PCI_MAPREG_TYPE(bar) != PCI_MAPREG_TYPE_MEM)
625 		return EINVAL;
626 	sisfbcn.fbt = memt;
627 	rc = bus_space_map(memt, PCI_MAPREG_MEM_ADDR(bar), 1 /* XXX */,
628 	    BUS_SPACE_MAP_LINEAR, &sisfbcn.fbh);
629 	if (rc != 0)
630 		return rc;
631 
632 	bar = pci_conf_read_early(tag, PCI_MAPREG_START + 4);
633 	if (PCI_MAPREG_TYPE(bar) != PCI_MAPREG_TYPE_MEM)
634 		return EINVAL;
635 	sisfbcn.mmiot = memt;
636 	rc = bus_space_map(memt, PCI_MAPREG_MEM_ADDR(bar), 1 /* XXX */,
637 	    BUS_SPACE_MAP_LINEAR, &sisfbcn.mmioh);
638 	if (rc != 0)
639 		return rc;
640 
641 	bar = pci_conf_read_early(tag, PCI_MAPREG_START + 8);
642 	if (PCI_MAPREG_TYPE(bar) != PCI_MAPREG_TYPE_IO)
643 		return EINVAL;
644 	sisfbcn.iot = iot;
645 	rc = bus_space_map(iot, PCI_MAPREG_MEM_ADDR(bar), 1 /* XXX */,
646 	    0, &sisfbcn.ioh);
647 	if (rc != 0)
648 		return rc;
649 
650 	rc = sisfb_setup(&sisfbcn);
651 	if (rc != 0)
652 		return rc;
653 
654 	ri = &sisfbcn.ri;
655 	ri->ri_ops.alloc_attr(ri, 0, 0, 0, &defattr);
656 	wsdisplay_cnattach(&sisfbcn.wsd, ri, 0, 0, defattr);
657 
658 	return 0;
659 }
660