Bell 32V development
[unix-history] / usr / src / slowsys / sys / uba.c
CommitLineData
0cd33762
TL
1# include "../h/param.h"
2#include "../h/uba.h"
3# include "../h/map.h"
4
5int uballoc(baddr,bcnt,bdpflg)
6char bdpflg ;
7char * baddr ;
8unsigned short bcnt;
9{
10/*
11* Allocate as many contiguous UBA mapping registers
12* as are necessary to do transfer of 'bcnt' bytes
13* to/from location 'baddr'.
14* Wait for enough map registers.
15* 'bdpflg' is non-zero if a "buffered data path" (BDP) is
16* to be used, else 0 -> use direct data path (DDP) .
17* Return
18*
19* |31 - - 28|27 - - 18|17 - - - 9|8 - - 0|
20* | | | | |
21* | BDP | no. | start | byte |
22* | no. | mapping | map | offset|
23* | | reg's | reg. no. | |
24* | | | | |
25*
26*/
27
28register regnum , nmreg , bdp , pfn , j ;
29
30/* calculate no. of mapping reg's required */
31nmreg = btoc(bcnt) + 2;
32pfn = ((int)baddr>>9) & 0xfff ; /* start page frame no. */
33
34spl6() ;
35while ((regnum = malloc(ubamap,nmreg) - 1) < 0) {
36 /* wait for no. of mapping reg's requested */
37 umrwant++ ;
38 sleep(ubamap,PSWP) ;
39 }
40if (bdpflg) /* buffered data path BDP 1-15 */
41 while ( (bdp=malloc(bdpmap,1)) == NULL)
42 {
43 bdpwant++;
44 sleep(bdpmap, PSWP);
45 }
46else { /* BDP 0 = DDP */
47 bdp = 0 ;
48 }
49
50spl0() ;
51
52j = (bdp<<28) | (nmreg<<18) | (regnum<<9) | ((int)baddr & 0x01ff) ;
53pfn |= (MRV | (bdp<<21)) ; /* map reg entry */
54
55if (bdp && ((int)baddr & 01)) pfn |= BO ; /* byte offset */
56while (--nmreg) /* fill the memory mapping reg's */
57 ((struct uba_regs *)UBA0)->uba_map[regnum++] = pfn++ ;
58((struct uba_regs *)UBA0)->uba_map[regnum] = 0 ; /* last entry is invalid */
59
60return(j) ;
61}
62
63/* */
64
65ubafree(mr)
66int mr ;
67{
68/*
69* Free UBA memory mapping reg's and a BDP no..
70* mr :
71* bits 0 - 3 : bdp no.
72* 4 - 15 : start map reg. no.
73* 16 - 31 : no. of mapping reg's
74*
75*/
76
77register bdp , nmreg , regnum ;
78
79spl6();
80bdp = (mr>>28) & 0x0f ; /* BDP no. */
81if (bdp)
82 {
83 ((struct uba_regs *)UBA0)->uba_dpr[bdp] |= BNE ; /* purge */
84 mfree(bdpmap, 1, bdp);
85 if (bdpwant) {
86 bdpwant = 0;
87 wakeup(bdpmap);
88 }
89}
90
91nmreg = (mr>>18) & 0x3ff ; /* no. of mapping reg's */
92regnum = (mr>>9) & 0x1ff ; /* 1st map reg. no. */
93
94/* free mapping reg's */
95mfree(ubamap,nmreg,regnum+1) ;
96if (umrwant) {
97 umrwant = 0;
98 wakeup(ubamap);
99}
100spl0() ;
101}
102
103ubainit()
104{
105 mfree(ubamap, 496, 1);
106 mfree(bdpmap, 15, 1);
107}